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>
23 lines
596 B
TypeScript
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
|
|
}
|