Single-page applications (SPAs) provide a fast user experience by loading content without a full page refresh. However, because the page doesn't "reload," standard tracking tags often miss these internal page changes.
This guide shows you how to use Google Tag Manager (GTM) to capture every SPA page view automatically using the TG site tag.
π‘ Prerequisites
Admin access to your GTM container.
The standard TG site tag is already installed and firing on the initial page load.
Setup guide: Google Tag Manager
1. Create the PageView tag
In GTM, create a New Tag named
TrafficGuard - PageView.Select Custom HTML as the tag type.
Paste the following code into the HTML box:
<script>
// Custom TrafficGuard PageView Event
window.dataTrafficGuard = window.dataTrafficGuard || [];
dataTrafficGuard.push(['event','pageview','{"evs":"spa"}']);
</script>
2. Configure the trigger
In the Triggering section of your new tag, click the + icon to add a trigger.
Name it
TrafficGuard PageView Triggerand select Custom Event as the type.In the Event name field, enter exactly:
gtm.historyChange.Ensure All Custom Events is selected and save the trigger.
3. Save and publish
Save the tag, then click Submit and Publish in GTM to make the changes live.
How to verify the setup
To ensure your SPA tracking is active:
Open your website and your browser's Developer Tools (Right-click > Inspect).
Go to the Network tab and type
trafficguardin the filter box.Click through your site's navigation.
Success: You should see a new
eventrequest appears in the list every time the URL changes.
β
