-
Notifications
You must be signed in to change notification settings - Fork 93
feat: migrate analytics from ClickHouse to PostHog #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||||
| "use client"; | ||||||||||||
|
|
||||||||||||
| import posthog from "posthog-js"; | ||||||||||||
| import { PostHogProvider as PHProvider, usePostHog } from "posthog-js/react"; | ||||||||||||
| import { useEffect, Suspense } from "react"; | ||||||||||||
| import { usePathname, useSearchParams } from "next/navigation"; | ||||||||||||
|
|
||||||||||||
| function PostHogPageView() { | ||||||||||||
| const pathname = usePathname(); | ||||||||||||
| const searchParams = useSearchParams(); | ||||||||||||
| const ph = usePostHog(); | ||||||||||||
|
|
||||||||||||
| useEffect(() => { | ||||||||||||
| if (pathname && ph) { | ||||||||||||
| let url = window.origin + pathname; | ||||||||||||
| const search = searchParams?.toString(); | ||||||||||||
| if (search) url += `?${search}`; | ||||||||||||
| ph.capture("$pageview", { $current_url: url }); | ||||||||||||
| } | ||||||||||||
| }, [pathname, searchParams, ph]); | ||||||||||||
|
|
||||||||||||
| return null; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| export function PostHogProvider({ children }: { children: React.ReactNode }) { | ||||||||||||
| useEffect(() => { | ||||||||||||
| const key = process.env.NEXT_PUBLIC_POSTHOG_KEY; | ||||||||||||
| const host = process.env.NEXT_PUBLIC_POSTHOG_HOST; | ||||||||||||
| if (!key || !host) return; | ||||||||||||
|
|
||||||||||||
| posthog.init(key, { | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Missing PostHog defaults config causes SSR hydration errorsMissing PostHog defaults config causes SSR hydration errors. React hydration mismatches may occur. Add defaults: '2025-11-30' to posthog.init(). View DetailsLocation: AnalysisMissing PostHog defaults config causes SSR hydration errors. React hydration mismatches may occur
How to reproduce1. Load page server-rendered
2. Watch for 'Prop dangerouslySetInnerHTML did not match' warnings
3. Especially with features like surveys enabledPatch Details- posthog.init(key, {
- api_host: host,
- capture_pageview: false, // we handle it manually above
- capture_pageleave: true,
- });
+ posthog.init(key, {
+ api_host: host,
+ capture_pageview: false,
+ capture_pageleave: true,
+ defaults: '2025-11-30',
+ });AI Fix PromptTip: Reply with |
||||||||||||
| api_host: host, | ||||||||||||
| capture_pageview: false, // we handle it manually above | ||||||||||||
| capture_pageleave: true, | ||||||||||||
| }); | ||||||||||||
| }, []); | ||||||||||||
|
|
||||||||||||
| return ( | ||||||||||||
| <PHProvider client={posthog}> | ||||||||||||
| <Suspense fallback={null}> | ||||||||||||
| <PostHogPageView /> | ||||||||||||
| </Suspense> | ||||||||||||
| {children} | ||||||||||||
| </PHProvider> | ||||||||||||
| ); | ||||||||||||
|
Comment on lines
+25
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: In the common Next.js App Router setup, people put Fix (recommended): initialize in
|
||||||||||||
| } | ||||||||||||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: PostHog SDK race condition on initialization
PostHog SDK race condition on initialization. Events may be silently dropped on first render. Check posthog.__loaded before passing to PHProvider.
View Details
Location:
components/providers/posthog-provider.tsx(lines 19)Analysis
PostHog SDK race condition on initialization. Events may be silently dropped on first render
useEffect. This creates a race condition where PostHogPageView and children may attempt to capture events before initialization completes.How to reproduce
1. Load page with cold cache 2. Check browser console for PostHog errors 3. Observe pageview events may be silently dropped on initial renderAI Fix Prompt
Tip: Reply with
@paragon-runto automatically fix this issue