Skip to content

fix(analytics): one explicit GA4 page_view per route (send_page_view:false) - #893

Merged
unjica merged 2 commits into
developfrom
fix/ga-spa-page-view
Oct 30, 2026
Merged

unjica merged 2 commits into
developfrom
fix/ga-spa-page-view

Conversation

@unjica

@unjica unjica commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Base branch: develop

Summary

Fixes P0 from the Phase 1 analytics audit (telemetry-tracker.com): client-side navigations sent no page_view, and the next one carried the previous URL (dl=/docs, dp=/).

  • GoogleAnalytics.tsx now calls gtag('config', id, { send_page_view: false }) once, and after each route commit sends exactly one gtag('event', 'page_view', { page_location, page_path, page_title }) with the current values (deferred one task so URL and <title> are committed). Deduped by path; reset when tracking stops (reject / dashboard routes) so a later accept or return counts once.
  • New helper buildGaPageViewParams in lib/google-analytics.ts.
  • Consent gating, measurement ID, and dashboard exclusion are unchanged.

How to test

  • pnpm lint ✅, pnpm --filter dashboard test ✅ (73 files / 445 tests incl. new GoogleAnalytics.test.tsx), next build ✅.
  • Local consent audit (Phase 1 script, base http://localhost:3401, GA /collect intercepted locally, nothing sent to Google): landing 1 page_view (/, correct title); Link nav → 1 page_view dl=/docs dp=/docs dt="Documentation · Telemetry Tracker".
  • Known, not fixable in code: on browser Back an extra page_view with stale dl=/docs and no dp appears next to ours. This is GA4 Enhanced measurement "Page changes based on browser history events" (stream setting, same as Tacko P0). Turn it off in GA4 Admin → Data streams → telemetry-tracker.com → Enhanced measurement → Page views → Advanced.

Code review (Bugbot)

  • Not notification/alert/billing/ingest/auth.

Checklist

  • Tests pass (dashboard)
  • Lint passes
  • Build succeeds (dashboard)
  • CHANGELOG updated under [Unreleased]
  • No breaking changes

Security / privacy

No change to consent gating: GA still loads only after Accept and only on marketing/docs routes.

@unjica
unjica merged commit c646dc2 into develop Oct 30, 2026
7 checks passed
unjica pushed a commit that referenced this pull request Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants