Files
hyggecraftery-web/components/PostHogProvider.tsx
2026-07-01 21:48:16 +02:00

25 lines
662 B
TypeScript

'use client'
import { useEffect } from 'react'
import { usePathname } from 'next/navigation'
import posthog from 'posthog-js'
export default function PostHogProvider({ children }: { children: React.ReactNode }) {
useEffect(() => {
posthog.init('phc_BHgg9S7CQqVShe7EMCdi86PxA49qcNaTsR9Nn5EGxRCT', {
api_host: 'https://eu.posthog.com',
capture_pageview: false,
persistence: 'memory',
})
}, [])
const pathname = usePathname()
useEffect(() => {
// PostHog queues events automatically before init completes
posthog.capture('$pageview', { $current_url: window.location.href })
}, [pathname])
return <>{children}</>
}