2025-07-08 20:41:11 +05:30
|
|
|
"use client";
|
2024-06-20 16:52:05 +05:30
|
|
|
|
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { usePathname, useSearchParams } from "next/navigation";
|
|
|
|
|
// posthog
|
2025-07-08 20:41:11 +05:30
|
|
|
import { usePostHog } from "posthog-js/react";
|
2024-06-20 16:52:05 +05:30
|
|
|
|
|
|
|
|
export default function PostHogPageView(): null {
|
|
|
|
|
const pathname = usePathname();
|
|
|
|
|
const searchParams = useSearchParams();
|
|
|
|
|
const posthog = usePostHog();
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// Track pageviews
|
|
|
|
|
if (pathname && posthog) {
|
2025-07-08 20:41:11 +05:30
|
|
|
let url = window.origin + pathname;
|
2024-06-20 16:52:05 +05:30
|
|
|
if (searchParams.toString()) {
|
2025-07-08 20:41:11 +05:30
|
|
|
url = url + `?${searchParams.toString()}`;
|
2024-06-20 16:52:05 +05:30
|
|
|
}
|
2025-07-08 20:41:11 +05:30
|
|
|
posthog.capture("$pageview", {
|
|
|
|
|
$current_url: url,
|
|
|
|
|
});
|
2024-06-20 16:52:05 +05:30
|
|
|
}
|
2025-07-08 20:41:11 +05:30
|
|
|
}, [pathname, searchParams, posthog]);
|
2024-06-20 16:52:05 +05:30
|
|
|
|
2025-07-08 20:41:11 +05:30
|
|
|
return null;
|
2024-06-20 16:52:05 +05:30
|
|
|
}
|