From 56bb019946465f6cf52e433303b549db0ba84429 Mon Sep 17 00:00:00 2001 From: Goksu Toprak Date: Thu, 5 Feb 2026 15:49:09 -0800 Subject: [PATCH] feat: register site super property and remove posthog.reset() Register { site: 'docs' } super property in the loaded callback so docs events are distinguishable from web events in PostHog dashboards. Remove posthog.reset() from useEffect cleanup to preserve cross-domain user identity. Relates WEB-106 Co-authored-by: Amp --- src/components/PageViewTracker.tsx | 20 -------------------- src/components/PostHogSetup.tsx | 9 ++------- src/components/PostHogSiteIdentifier.tsx | 22 ---------------------- 3 files changed, 2 insertions(+), 49 deletions(-) delete mode 100644 src/components/PageViewTracker.tsx delete mode 100644 src/components/PostHogSiteIdentifier.tsx diff --git a/src/components/PageViewTracker.tsx b/src/components/PageViewTracker.tsx deleted file mode 100644 index 5fe8d9d6..00000000 --- a/src/components/PageViewTracker.tsx +++ /dev/null @@ -1,20 +0,0 @@ -'use client' -import { useEffect } from 'react' -import { useRouter } from 'waku' -import { usePostHogTracking } from '../lib/posthog' - -/** - * Component to track page views automatically - * Should be placed inside the PostHogProvider - */ -export function PageViewTracker() { - const location = useRouter() - const { trackPageView } = usePostHogTracking() - - useEffect(() => { - // Track page view on mount and when location changes - trackPageView(location.path + location.query, document.title) - }, [location.path, location.query, trackPageView]) - - return null -} diff --git a/src/components/PostHogSetup.tsx b/src/components/PostHogSetup.tsx index d2e6e508..eecf95c1 100644 --- a/src/components/PostHogSetup.tsx +++ b/src/components/PostHogSetup.tsx @@ -12,17 +12,12 @@ function PostHogInitializer() { posthog.init(posthogKey, { api_host: posthogHost, - defaults: '2025-05-24', + defaults: '2025-11-30', capture_exceptions: true, debug: import.meta.env.MODE === 'development', - loaded: (posthog) => { - posthog.capture('$pageview') - }, }) - return () => { - posthog.reset() - } + posthog.register({ site: 'docs' }) }, []) return null diff --git a/src/components/PostHogSiteIdentifier.tsx b/src/components/PostHogSiteIdentifier.tsx deleted file mode 100644 index 7328f610..00000000 --- a/src/components/PostHogSiteIdentifier.tsx +++ /dev/null @@ -1,22 +0,0 @@ -'use client' -import { usePostHog } from 'posthog-js/react' -import { useEffect } from 'react' - -/** - * Component to set site identifier for PostHog - * This distinguishes docs from web in the same PostHog project - */ -export function PostHogSiteIdentifier() { - const posthog = usePostHog() - - useEffect(() => { - if (posthog) { - // Set site property as a super property so it's included in all events - posthog.register({ - site: 'docs', - }) - } - }, [posthog]) - - return null -}