mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
36 lines
975 B
TypeScript
36 lines
975 B
TypeScript
'use client'
|
|
|
|
import { usePathname, useSearchParams } from 'next/navigation'
|
|
import { useEffect, Suspense } from 'react'
|
|
import { usePostHog } from 'posthog-js/react'
|
|
|
|
function PostHogPageViewInner() {
|
|
const pathname = usePathname()
|
|
const searchParams = useSearchParams()
|
|
const posthog = usePostHog()
|
|
|
|
useEffect(() => {
|
|
// Invite codes are bearer-like tokens. The join route emits its own
|
|
// aggregate-only event, so it must never produce a URL-bearing page view.
|
|
if (pathname?.startsWith('/join/')) return
|
|
|
|
if (pathname && posthog) {
|
|
let url = window.origin + pathname
|
|
if (searchParams.toString()) {
|
|
url = url + '?' + searchParams.toString()
|
|
}
|
|
posthog.capture('$pageview', { $current_url: url })
|
|
}
|
|
}, [pathname, searchParams, posthog])
|
|
|
|
return null
|
|
}
|
|
|
|
export function PostHogPageView() {
|
|
return (
|
|
<Suspense fallback={null}>
|
|
<PostHogPageViewInner />
|
|
</Suspense>
|
|
)
|
|
}
|