chore: enable posthog pageview. (#4888)

This commit is contained in:
Prateek Shourya 2024-06-20 16:52:05 +05:30 committed by GitHub
parent 280a69bd3c
commit f06cce44a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 2 deletions

View file

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