SaTracking
PlatformsNEWAdvanced

Track single-page application route changes in GTM

Choose a History Change trigger or an application event for SPA navigation and prevent duplicate pageviews.

Download for AI (.txt)

Measurement topic illustration · SaTracking

Audience and prerequisites

Use the History Change trigger for route updates and confirm the Google tag does not also send an automatic pageview for the same navigation. You need a test route flow, access to the web container, and a definition of whether the Google tag already sends pageviews automatically. Skill level: advanced. Reading time: eight minutes.

1. Observe how the router changes the URL

GTM's History Change trigger can fire when the URL fragment changes or when the site uses the HTML5 pushState API. First inspect a representative route transition in the browser and in GTM Preview. Some routers update application state without a history change GTM can observe; in that case, define an explicit application event and configure GTM to listen for it instead of assuming the trigger will detect every route.

2. Choose one pageview owner

Check Google tag settings and existing tags before adding a route-based pageview. Google tag settings can detect page views on browser history changes. If that feature is enabled while a separate GTM History Change trigger also sends pageviews, one route may be counted twice. Decide whether the Google tag's automatic detection or a deliberate GTM tag owns virtual pageviews, then disable or remove the duplicate path.

3. Configure and test the route trigger

For the GTM route, create a History Change trigger and inspect the generated event in Preview. Use the new URL or another stable router signal to decide which transitions count. Configure the GA4 Event tag to send a page_view with the intended page location/title only when that trigger represents a real route change. Do not trigger on unrelated fragment updates such as tab selection unless they are intentionally part of page measurement.

If the application emits an explicit data-layer event instead, that message is generic application-to-GTM signaling. Create the matching Custom Event trigger and map the route values into a configured tag. A data-layer push alone does not send a GA4 event.

4. Validate entry, back, and repeated transitions

Test direct page load, in-app navigation, browser back/forward, hash-only changes, and repeated navigation to the same route. In Tag Assistant, verify one intended pageview per counted transition and check the resolved URL. Confirm events in GA4 DebugView for the right property. A Preview timeline shows test-session tag behavior; it does not prove report processing.

If views duplicate, inspect automatic pageview settings, multiple triggers, and the site's existing GA4 integration. If they are missing, confirm whether the router uses pushState, hash changes, or a custom application event.

Privacy and limits

Avoid placing personal or sensitive values in route URLs because page location may be collected. Follow consent behavior for Google tags and keep query parameters out of measurement where needed. Document whether route changes count as pageviews so the definition remains stable across router changes.

Use GTM Preview and Tag Assistant to inspect route event order and tag results. For custom application signals, see connect a data-layer event to a trigger.

Official references

EDITORIAL HISTORY

What changed

  1. v1.0.0
    Initial bilingual guide drafted and checked against linked current Google documentation.
MEASUREMENT SUPPORT

Need a hand with your tracking?

Nicolas Salazar works with teams on analytics, tracking plans, data quality, consent, and implementation.