* posthog version upgrade and calai banner tracking * disable posthog for EU * bunch more posthog tracking * Revert yarn.lock changes * add posthog package yarn changes * fix: add missing posthog import and fix lint warning in MemberInvitationModal Co-Authored-By: [email protected] <[email protected]> * fix: type check * cubic fixes * refactor * remove ui playground --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
40 lines
949 B
TypeScript
40 lines
949 B
TypeScript
"use client";
|
|
|
|
import { usePathname, useSearchParams } from "next/navigation";
|
|
import { usePostHog } from "posthog-js/react";
|
|
import { useEffect } from "react";
|
|
|
|
const TRACKED_ROUTES = [
|
|
"/signup",
|
|
"/auth/verify-email",
|
|
"/getting-started",
|
|
"/onboarding/getting-started",
|
|
"/settings/teams/new",
|
|
"/settings/teams",
|
|
];
|
|
|
|
export default function PostHogPageView() {
|
|
const pathname = usePathname();
|
|
const searchParams = useSearchParams();
|
|
const posthog = usePostHog();
|
|
|
|
useEffect(() => {
|
|
const shouldTrack = TRACKED_ROUTES.some(route => pathname?.startsWith(route));
|
|
|
|
if (!shouldTrack) return;
|
|
|
|
// 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;
|
|
}
|