Files
tuono/apps/documentation/src/components/PostHog/PostHogPageView.tsx
T
2025-02-06 20:58:33 +01:00

21 lines
531 B
TypeScript

import { useEffect } from 'react'
import { usePostHog } from 'posthog-js/react'
import { useRouter } from 'tuono'
export default function PostHogPageView(): null {
const { pathname } = useRouter()
const posthog = usePostHog()
// Track pageviews
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (pathname && posthog) {
const url = window.origin + pathname
posthog.capture('$pageview', { $current_url: url })
}
}, [pathname, posthog])
return null
}