Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: enable App Router page view tracking on navigation (#40225)

Sean Oliver99835713d2a4
diff --git a/packages/common/telemetry.tsx b/packages/common/telemetry.tsx
index 64f77f1d503..c4f8c4fc17c 100644
--- a/packages/common/telemetry.tsx
+++ b/packages/common/telemetry.tsx
@@ -172,6 +172,9 @@ export const PageTelemetry = ({
// Handle initial page telemetry event
const hasSentInitialPageTelemetryRef = useRef(false)
+ // Track previous pathname for App Router to detect actual changes
+ const previousAppPathnameRef = useRef<string | null>(null)
+
// Initialize PostHog client when consent is accepted
useEffect(() => {
if (hasAcceptedConsent && IS_PLATFORM) {
@@ -239,10 +242,13 @@ export const PageTelemetry = ({
// For app router
if (router !== null) return
- // Wait until we've sent the initial page telemetry event
- if (appPathname && !hasSentInitialPageTelemetryRef.current) {
+ // Only track if pathname actually changed (not initial mount)
+ if (appPathname && previousAppPathnameRef.current !== null && previousAppPathnameRef.current !== appPathname) {
sendPageTelemetry()
}
+
+ // Update previous pathname
+ previousAppPathnameRef.current = appPathname
}, [appPathname, router, sendPageTelemetry])
useEffect(() => {