diff options
| author | Yuval Adam <_@yuv.al> | 2024-09-23 16:20:18 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2024-09-23 16:20:18 +0200 |
| commit | 25799e446197c238989cc748e0bd7f350a1d6d67 (patch) | |
| tree | 7d1fe6f0fc08b2f44411fdf65d4718752e7dd972 /app/components/Fathom.tsx | |
| parent | d5cf0f5f273fc5518582fd0cd6b42bafdd6764eb (diff) | |
Add fathom analytics client
Diffstat (limited to 'app/components/Fathom.tsx')
| -rw-r--r-- | app/components/Fathom.tsx | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/components/Fathom.tsx b/app/components/Fathom.tsx new file mode 100644 index 0000000..4dbd21b --- /dev/null +++ b/app/components/Fathom.tsx @@ -0,0 +1,35 @@ +'use client'; + +import { load, trackPageview } from 'fathom-client'; +import { useEffect, Suspense } from 'react'; +import { usePathname, useSearchParams } from 'next/navigation'; + +function TrackPageView() { + const pathname = usePathname(); + const searchParams = useSearchParams(); + + useEffect(() => { + load('MBXPLVRM', { + auto: false + }); + }, []); + + useEffect(() => { + if (!pathname) return; + + trackPageview({ + url: pathname + searchParams?.toString(), + referrer: document.referrer + }); + }, [pathname, searchParams]); + + return null; +} + +export default function Fathom() { + return ( + <Suspense fallback={null}> + <TrackPageView /> + </Suspense> + ); +}
\ No newline at end of file |
