Analytics Q&As Logo
Analytics Q&As Part of the Q&A Network
Q&A Logo

How do I track SPA (single-page app) navigation in GA4?

Asked on Sep 28, 2025

Answer

Tracking navigation in a Single-Page Application (SPA) with Google Analytics 4 requires setting up custom events to capture URL changes since SPAs do not trigger traditional pageviews. This can be done using Google Tag Manager (GTM) to listen for history changes or hash changes.
<!-- BEGIN COPY / PASTE -->
    // Example GTM Custom Event Trigger for SPA
    Trigger Type: History Change
    Trigger Configuration: 
  • This trigger fires on: All History Changes
GA4 Event Tag Configuration:
  • Event Name: page_view
  • Event Parameters:
  • page_location: {{Page URL}}
  • page_title: {{Page Title}}
<!-- END COPY / PASTE -->
Additional Comment:
  • Use Google Tag Manager to set up a "History Change" trigger, which listens for URL changes in SPAs.
  • Configure a GA4 event tag to fire on this trigger, capturing parameters like "page_location" and "page_title".
  • Ensure that your GA4 property is correctly linked in GTM to send the data.
  • Test the setup using GTM's Preview mode to verify that events are sent correctly when navigating within the SPA.
✅ Answered with Analytics best practices.

← Back to All Questions
The Q&A Network