Skip to content

Commit 87109e4

Browse files
committed
Fix ref search param for analytics
1 parent defda9b commit 87109e4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/components/track-page.tsx

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use client'
22

33
import { usePlausible } from 'next-plausible'
4-
import { useEffect } from 'react'
4+
import { useSearchParams } from 'next/navigation'
5+
import { Suspense, useEffect } from 'react'
56

67
type Event =
78
| { event: 'pageview'; props: {} }
@@ -12,12 +13,29 @@ type Event =
1213
| { event: 'expense: delete'; props: { groupId: string; expenseId: string } }
1314
| { event: 'group: export expenses'; props: { groupId: string } }
1415

15-
export function TrackPage({ path }: { path: string }) {
16+
type Props = {
17+
path: string
18+
}
19+
20+
export function TrackPage(props: Props) {
21+
return (
22+
<Suspense>
23+
<TrackPage_ {...props} />
24+
</Suspense>
25+
)
26+
}
27+
28+
function TrackPage_({ path }: Props) {
1629
const sendEvent = useAnalytics()
30+
const searchParams = useSearchParams()
31+
const ref = searchParams.get('ref')
1732

1833
useEffect(() => {
19-
sendEvent({ event: 'pageview', props: {} }, path)
20-
}, [path, sendEvent])
34+
sendEvent(
35+
{ event: 'pageview', props: {} },
36+
`${path}${ref ? `?ref=${ref}` : ''}`,
37+
)
38+
}, [path, ref, sendEvent])
2139

2240
return null
2341
}

0 commit comments

Comments
 (0)