Files
hyggecraftery-web/components/PostHogProvider.tsx
Tim Leikauf f487189a19 Fix PostHog init race condition — remove __loaded guard
posthog.capture() queues events automatically before init completes,
so checking __loaded blocked the first pageview from being sent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 21:04:57 +02:00

25 lines
681 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://analytics.hyggecraftery.com',
capture_pageview: false,
persistence: 'localStorage',
})
}, [])
const pathname = usePathname()
useEffect(() => {
// PostHog queues events automatically before init completes
posthog.capture('$pageview', { $current_url: window.location.href })
}, [pathname])
return <>{children}</>
}