diff options
| author | Saksham Kushwaha <[email protected]> | 2025-10-28 04:40:15 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-10-27 16:10:15 -0700 |
| commit | cccb35160de6c803def1cfbb5447d272a3c50c37 (patch) | |
| tree | 79358543fe626b818fc19065bec00d990edf0041 /packages/lib/posthog.tsx | |
| parent | Fix/invalid dom property (#526) (diff) | |
| download | supermemory-cccb35160de6c803def1cfbb5447d272a3c50c37.tar.xz supermemory-cccb35160de6c803def1cfbb5447d272a3c50c37.zip | |
feat: optional posthog intialization (#525)
Diffstat (limited to 'packages/lib/posthog.tsx')
| -rw-r--r-- | packages/lib/posthog.tsx | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/packages/lib/posthog.tsx b/packages/lib/posthog.tsx index ac563aae..62a60e09 100644 --- a/packages/lib/posthog.tsx +++ b/packages/lib/posthog.tsx @@ -11,7 +11,7 @@ function PostHogPageTracking() { // Page tracking useEffect(() => { - if (pathname) { + if (pathname && posthog.__loaded) { let url = window.origin + pathname if (searchParams.toString()) { url = `${url}?${searchParams.toString()}` @@ -38,19 +38,24 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) { useEffect(() => { if (typeof window !== "undefined") { - posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY ?? "", { + const posthogKey = process.env.NEXT_PUBLIC_POSTHOG_KEY + if (posthogKey){ + posthog.init(posthogKey, { api_host: process.env.NEXT_PUBLIC_BACKEND_URL + "/orange", ui_host: "https://us.i.posthog.com", person_profiles: "identified_only", capture_pageview: false, capture_pageleave: true, - }) + })} + else{ + console.warn("PostHog API key is not set. PostHog will not be initialized.") + } } }, []) // User identification useEffect(() => { - if (session?.user) { + if (session?.user && posthog.__loaded) { posthog.identify(session.user.id, { email: session.user.email, name: session.user.name, |