Files
hyggecraftery-web/components/PostHogPageView.tsx
Tim Leikauf 4274d680e1 Rework PostHog setup — use Next.js ingest proxy + posthog-js/react
Mirrors the proven pattern from gendersloty: rewrites /ingest/* to
the PostHog host so requests go through the same origin (no CORS,
no ad-blocker issues). Uses PostHogProvider and usePostHog from
posthog-js/react official React integration.

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

23 lines
596 B
TypeScript

'use client'
import { usePathname, useSearchParams } from 'next/navigation'
import { usePostHog } from 'posthog-js/react'
import { useEffect } from 'react'
export function PostHogPageView() {
const pathname = usePathname()
const searchParams = useSearchParams()
const posthog = usePostHog()
useEffect(() => {
if (pathname && posthog) {
let url = window.origin + pathname
const search = searchParams.toString()
if (search) url += `?${search}`
posthog.capture('$pageview', { $current_url: url })
}
}, [pathname, searchParams, posthog])
return null
}