Skip to content

Fix GA4 page_view firing on every map interaction - #1022

Open
chriswhong wants to merge 1 commit into
mainfrom
fix/ga4-page-view-on-map-interaction
Open

Fix GA4 page_view firing on every map interaction#1022
chriswhong wants to merge 1 commit into
mainfrom
fix/ga4-page-view-on-map-interaction

Conversation

@chriswhong

Copy link
Copy Markdown
Contributor

Summary

  • send_page_view: false in the gtag config only suppresses the initial page_view on load — it does not affect GA4's enhanced measurement feature
  • GA4 enhanced measurement patches history.replaceState at the instance level and independently fires a page_view event on every call
  • The ?map= camera param is updated via replaceState on every map move (onMoveEnd), causing a flood of page_view events
  • Fix: call History.prototype.replaceState directly, which bypasses GA4's instance-level patch

Test plan

  • Move the map and confirm no page_view events fire in GA4 DebugView or the Network tab (no hits to google-analytics.com/g/collect with en=page_view)
  • Confirm the ?map= query param still updates correctly in the URL on map move
  • Confirm a single page_view still fires on initial page load

🤖 Generated with Claude Code

GA4's enhanced measurement patches history.replaceState at the instance
level and fires a page_view on every call, regardless of send_page_view:false.
Calling History.prototype.replaceState directly bypasses this patch so the
?map= camera param updates silently without triggering analytics events.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chriswhong
chriswhong requested a review from a team as a code owner July 15, 2026 14:23
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.

1 participant