Files
multica/apps/web/components/pageview-tracker.tsx
Bohan Jiang 2e50df9a6a perf(analytics): report $pageview at section granularity, drop web query-string churn (#3813)
capturePageview now section-normalizes the path (strip query/hash, collapse
UUID and issue-key resource segments) and dedupes consecutive same-section
views, so navigating between issues/agents/etc. no longer fires a billed
PostHog event per resource. The web tracker keys on pathname only (not
searchParams), removing ~17% pure query-string-churn pageviews and keeping
OAuth code/state out of $current_url.

MUL-3081

Co-authored-by: J <j@multica.ai>
Co-authored-by: multica-agent <github@multica.ai>
2026-06-05 15:33:32 +08:00

31 lines
1.1 KiB
TypeScript

"use client";
import { useEffect } from "react";
import { usePathname } from "next/navigation";
import { capturePageview } from "@multica/core/analytics";
/**
* Fires a PostHog $pageview whenever the Next.js App Router pathname changes.
* Mounted once at the root so every route transition is covered, including
* transitions into workspace-scoped subtrees.
*
* Deliberately keyed on `pathname` only — NOT `useSearchParams`. Filter / sort
* / search state lives in the query string and changes constantly on a
* dashboard; firing a pageview on every query-string change was ~17% pure
* noise (and billed events) with no funnel signal. The query string is also
* dropped from the captured URL by `capturePageview` (it section-normalizes
* the path), so OAuth `code` / `state` never reach PostHog either.
*
* PostHog's own `capture_pageview: true` auto-capture is deliberately disabled
* in `initAnalytics` so this component owns the event shape.
*/
export function PageviewTracker() {
const pathname = usePathname();
useEffect(() => {
if (pathname) capturePageview(pathname);
}, [pathname]);
return null;
}