Commit 1a78445 1 parent 8907703 commit 1a78445 Copy full SHA for 1a78445
File tree 10 files changed +227
-8
lines changed
10 files changed +227
-8
lines changed Original file line number Diff line number Diff line change 1
1
import { BalancesList } from '@/app/groups/[groupId]/balances-list'
2
2
import { ReimbursementList } from '@/app/groups/[groupId]/reimbursement-list'
3
+ import { TrackPage } from '@/components/track-page'
3
4
import {
4
5
Card ,
5
6
CardContent ,
@@ -30,6 +31,7 @@ export default async function GroupPage({
30
31
31
32
return (
32
33
< >
34
+ < TrackPage path = { `/groups/${ group . id } /balances` } />
33
35
< Card className = "mb-4" >
34
36
< CardHeader >
35
37
< CardTitle > Balances</ CardTitle >
Original file line number Diff line number Diff line change
1
+ 'use client'
2
+
3
+ import { useAnalytics } from '@/components/track-page'
4
+ import Link from 'next/link'
5
+ import { PropsWithChildren } from 'react'
6
+
7
+ export const ExportLink = function ExportLink ( {
8
+ groupId,
9
+ children,
10
+ className,
11
+ } : PropsWithChildren < { groupId : string ; className ?: string } > ) {
12
+ const sendEvent = useAnalytics ( )
13
+
14
+ return (
15
+ < Link
16
+ className = { className }
17
+ href = { `/groups/${ groupId } /expenses/export/json` }
18
+ target = "_blank"
19
+ onClick = { ( ) => {
20
+ sendEvent ( 'group: export expenses' , { props : { groupId } } )
21
+ } }
22
+ >
23
+ { children }
24
+ </ Link >
25
+ )
26
+ }
Original file line number Diff line number Diff line change 1
1
import { ActiveUserModal } from '@/app/groups/[groupId]/expenses/active-user-modal'
2
2
import { ExpenseList } from '@/app/groups/[groupId]/expenses/expense-list'
3
+ import { ExportLink } from '@/app/groups/[groupId]/expenses/export-link'
4
+ import { TrackPage } from '@/components/track-page'
3
5
import { Button } from '@/components/ui/button'
4
6
import {
5
7
Card ,
@@ -30,6 +32,7 @@ export default async function GroupExpensesPage({
30
32
31
33
return (
32
34
< >
35
+ < TrackPage path = { `/groups/${ group . id } /expenses` } />
33
36
< Card className = "mb-4 rounded-none -mx-4 border-x-0 sm:border-x sm:rounded-lg sm:mx-0" >
34
37
< div className = "flex flex-1" >
35
38
< CardHeader className = "flex-1 p-4 sm:p-6" >
@@ -40,12 +43,9 @@ export default async function GroupExpensesPage({
40
43
</ CardHeader >
41
44
< CardHeader className = "p-4 sm:p-6 flex flex-row space-y-0 gap-2" >
42
45
< Button variant = "secondary" size = "icon" asChild >
43
- < Link
44
- href = { `/groups/${ groupId } /expenses/export/json` }
45
- target = "_blank"
46
- >
46
+ < ExportLink groupId = { groupId } >
47
47
< Download className = "w-4 h-4" />
48
- </ Link >
48
+ </ ExportLink >
49
49
</ Button >
50
50
< Button asChild size = "icon" >
51
51
< Link href = { `/groups/${ groupId } /expenses/create` } >
Original file line number Diff line number Diff line change 1
1
import { RecentGroupList } from '@/app/groups/recent-group-list'
2
+ import { TrackPage } from '@/components/track-page'
2
3
import { Button } from '@/components/ui/button'
3
4
import { Plus } from 'lucide-react'
4
5
import { Metadata } from 'next'
@@ -11,6 +12,7 @@ export const metadata: Metadata = {
11
12
export default async function GroupsPage ( ) {
12
13
return (
13
14
< >
15
+ < TrackPage path = "/groups" />
14
16
< div className = "flex justify-between items-center gap-4" >
15
17
< h1 className = "font-bold text-2xl" >
16
18
< Link href = "/groups" > My groups</ Link >
Original file line number Diff line number Diff line change @@ -68,7 +68,11 @@ export default function RootLayout({
68
68
return (
69
69
< html lang = "en" suppressHydrationWarning >
70
70
{ env . PLAUSIBLE_DOMAIN && (
71
- < PlausibleProvider domain = { env . PLAUSIBLE_DOMAIN } trackOutboundLinks />
71
+ < PlausibleProvider
72
+ domain = { env . PLAUSIBLE_DOMAIN }
73
+ trackOutboundLinks
74
+ manualPageviews
75
+ />
72
76
) }
73
77
< body className = "pt-16 min-h-[100dvh] flex flex-col items-stretch bg-slate-50 bg-opacity-30 dark:bg-background" >
74
78
< ThemeProvider
Original file line number Diff line number Diff line change 1
1
import { StatsDisplay } from '@/app/stats-display'
2
+ import { TrackPage } from '@/components/track-page'
2
3
import { Button } from '@/components/ui/button'
3
4
import {
4
5
BarChartHorizontalBig ,
@@ -22,6 +23,7 @@ export const dynamic = 'force-dynamic'
22
23
export default function HomePage ( ) {
23
24
return (
24
25
< main >
26
+ < TrackPage path = "/" />
25
27
< section className = "py-16 md:py-24 lg:py-32" >
26
28
< div className = "container flex max-w-screen-md flex-col items-center gap-4 text-center" >
27
29
< h1 className = "!leading-none font-bold text-3xl sm:text-5xl md:text-6xl lg:text-7xl landing-header py-2" >
Original file line number Diff line number Diff line change 2
2
import { AsyncButton } from '@/components/async-button'
3
3
import { CategorySelector } from '@/components/category-selector'
4
4
import { SubmitButton } from '@/components/submit-button'
5
+ import { useAnalytics } from '@/components/track-page'
5
6
import { Button } from '@/components/ui/button'
6
7
import {
7
8
Card ,
@@ -112,10 +113,22 @@ export function ExpenseForm({
112
113
splitMode : 'EVENLY' ,
113
114
} ,
114
115
} )
116
+ const sendEvent = useAnalytics ( )
115
117
116
118
return (
117
119
< Form { ...form } >
118
- < form onSubmit = { form . handleSubmit ( ( values ) => onSubmit ( values ) ) } >
120
+ < form
121
+ onSubmit = { form . handleSubmit ( async ( values ) => {
122
+ if ( expense ) {
123
+ sendEvent ( 'expense: update' , {
124
+ props : { groupId : group . id , expenseId : expense . id } ,
125
+ } )
126
+ } else {
127
+ sendEvent ( 'expense: create' , { props : { groupId : group . id } } )
128
+ }
129
+ await onSubmit ( values )
130
+ } ) }
131
+ >
119
132
< Card >
120
133
< CardHeader >
121
134
< CardTitle >
@@ -514,7 +527,12 @@ export function ExpenseForm({
514
527
type = "button"
515
528
variant = "destructive"
516
529
loadingContent = "Deleting…"
517
- action = { onDelete }
530
+ action = { async ( ) => {
531
+ sendEvent ( 'expense: delete' , {
532
+ props : { groupId : group . id , expenseId : expense . id } ,
533
+ } )
534
+ await onDelete ( )
535
+ } }
518
536
>
519
537
< Trash2 className = "w-4 h-4 mr-2" />
520
538
Delete
Original file line number Diff line number Diff line change 1
1
'use client'
2
2
import { SubmitButton } from '@/components/submit-button'
3
+ import { useAnalytics } from '@/components/track-page'
3
4
import { Button } from '@/components/ui/button'
4
5
import {
5
6
Card ,
@@ -67,6 +68,7 @@ export function GroupForm({
67
68
name : 'participants' ,
68
69
keyName : 'key' ,
69
70
} )
71
+ const sendEvent = useAnalytics ( )
70
72
71
73
let activeUser = 'None'
72
74
@@ -87,6 +89,11 @@ export function GroupForm({
87
89
< Form { ...form } >
88
90
< form
89
91
onSubmit = { form . handleSubmit ( async ( values ) => {
92
+ if ( group ) {
93
+ sendEvent ( 'group: update' , { props : { groupId : group . id } } )
94
+ } else {
95
+ sendEvent ( 'group: create' , { props : { } } )
96
+ }
90
97
await onSubmit ( values )
91
98
} ) }
92
99
>
Original file line number Diff line number Diff line change
1
+ 'use client'
2
+
3
+ import { usePlausible } from 'next-plausible'
4
+ import { useEffect } from 'react'
5
+
6
+ type Event = {
7
+ pageview : { }
8
+ 'group: create' : { }
9
+ 'group: update' : { groupId : string }
10
+ 'expense: create' : { groupId : string }
11
+ 'expense: update' : { groupId : string ; expenseId : string }
12
+ 'expense: delete' : { groupId : string ; expenseId : string }
13
+ 'group: export expenses' : { groupId : string }
14
+ }
15
+
16
+ export function TrackPage ( { path } : { path : string } ) {
17
+ const sendEvent = useAnalytics ( )
18
+
19
+ useEffect ( ( ) => {
20
+ const url = `${ window . location . origin } ${ path } `
21
+
22
+ sendEvent ( 'pageview' , { u : url , props : { } } )
23
+ } , [ path , sendEvent ] )
24
+
25
+ return null
26
+ }
27
+
28
+ export function useAnalytics ( ) {
29
+ const plausible = usePlausible < Event > ( )
30
+
31
+ const sendEvent : typeof plausible = ( eventName , ...rest ) => {
32
+ if ( process . env . NODE_ENV !== 'production' )
33
+ console . log ( 'Analytics event:' , eventName , ...rest )
34
+ plausible ( eventName , ...rest )
35
+ }
36
+
37
+ return sendEvent
38
+ }
You can’t perform that action at this time.
0 commit comments