GA4 not tracking page views on a single-page app: history change triggers in GTM.
- “GA4 not tracking page views on single page application”
- “GA4 SPA page views not tracking”
- “GA4 only records landing page React app”
- “GA4 page views not tracking Next.js”
- “GTM history change trigger GA4 page_view”
- “virtual page views GA4 GTM”
- “GA4 page views doubled single page app”
- “Page changes based on browser history events”
Baris Asa, tracking consultant, London · Last checked: 18 November 2026
GA4 misses page views on a single-page app because the screen changes without a new page load, so nothing sends apage_view unless something listens for the browser history change. If your tags are in GTM, Google’s fix is a GA4 page_view tag on a History Change trigger, with GA4’s own “Page changes based on browser history events” setting cleared. Running both counts every screen twice.
A standard Shopify theme isn’t a single-page app. Headless front ends usually are: Hydrogen, Next.js, or a React or Vue shop. Not sure? Ask your developer, or run the Network test further down.
What it costs: product pages look unvisited, or twice as busy as they are. Page-level conversion rates and “top products” reports are wrong in either direction.
Check in reports (no access needed): Reports, Engagement, Pages and screens. If Views per active user sits close to 1 on a site where people clearly browse, and nearly every view is a landing page, screens aren’t counted. If the same figure roughly doubled on a known date, such as a container change or a front-end release, they’re counted twice.
Check in DebugView (for whoever runs GTM):
- Open the site with Tag Assistant connected, so your visit shows in GA4 (Admin, Data display, DebugView).
- Land on one page. Then click to three more screens without reloading. Each click is a route change: a new screen, a new address, no page load.
- Count the
page_viewevents per click. One per click is right. None means route changes aren’t counted. Two means they’re counted twice. (Two on the landing page as well usually means a secondpage_viewtag on All Pages.) - Click each
page_viewand readpage_locationandpage_title. Each should name the screen you were on at that moment.
One per click, right address, right title: this isn’t your problem.
This note answers one question: why does my single-page app lose or double its page views in GA4, and how do I fix it. The general choice of trigger for each GA4 tag is in Which GTM trigger for GA4 tags.
Is my site a single-page app?
A single-page app loads one HTML page, then redraws the content with JavaScript as you click. The address bar still changes, but the browser never loads a new page.
The test: open the browser’s developer tools on the Network tab, filter to “Doc”, and click from one product to another. A normal site requests a new document on every click. A single-page app requests none after the first, only data.
The Google tag sends a page view when the page loads. On a single-page app that happens once per visit. Every screen after that needs something else to send it.
Which of the five cases do you have?
| What DebugView shows per click | Cause | Fix |
|---|---|---|
No page_view | Nothing sends a page view when the screen changes | Set up one method (below) |
Two page_views | Both methods are on | Turn one off |
| One, with the previous screen’s title | The tag reads the page before the app updates it | Fire on a named event the app pushes |
| Extra ones on filters, sorting or tabs | The app rewrites the address for small changes | Narrow the trigger |
One, but the same address every time, with #/ in it | Hash routing: GA4 drops the part after # | Send the full address |
If one of these matches and nobody on your side owns GTM, this is a short job: I find the case, build the fix, and send a DebugView screenshot per screen as proof.
1. Only the landing page is counted
Nothing listens for the route change. Google’s enhanced measurement page says GA4 can send a page_view “each time the page loads or the browser history state is changed by the active site”, with an advanced setting that controls the history part. It listens for pushState, popState and replaceState, the browser calls an app uses to change the address.
If that setting is off and GTM has no tag on History Change, only the landing page is counted. Someone may have cleared the setting on purpose, expecting a GTM tag that was never built.
If the setting is on, or the GTM trigger is built, and you still see nothing per click, the app may not use the browser’s history at all. Google’s single-page app guide names apps that render screens with DocumentFragment: they need a custom event instead. That’s developer work.
2. Every screen is counted twice
Both methods are running. Google’s guide puts it plainly: “If you configure your tags using Google Tag Manager, don’t enable automatic history tracking in Google Analytics, as this can lead to double-counting page views.” So on a GTM site, clear the GA4 setting and keep the History Change tag.
Also check the page source for a Google tag pasted outside GTM. It can send page views of its own on top of the container’s.
If the purchase tag also sits on History Change, an order can be counted twice too. That’s F-101 , covered in GA4 purchase event fires twice.
3. The page view carries the previous screen’s title
It’s happened. More than once. The app changes the address first and the title a moment later, and a tag on History Change reads the old title. In Pages and screens, product A’s views appear under product B’s title.
Settings won’t fix a race. The developer pushes a named event, such as virtual_page_view, once the new screen has its title and data, and the page_view tag fires on a Custom Event trigger with that name. It’s the same kind of race as GTM tag fires before the dataLayer is ready (F-103 ), with the same fix. Any GA4 event tag on History Change that reads the new screen’s data has the same risk.
4. Extra page views with no new screen
replaceState is on the list GA4’s setting listens for, and Google’s GTM tutorial says the History Change trigger fires on pushState or replaceState. Apps built with routers such as Next.js or React Router often rewrite the address when someone applies a filter, sorts a list or opens a tab. A front-end release that adds filters synced to the address can push views per user up without anyone touching GTM.
In GTM, set the trigger to Some History Changes and filter on the built-in History Source variable. Google doesn’t list its values, so read them in Preview: click a real route change, then a filter, then the browser’s Back button, and compare. Keep Back and Forward if they should count. If a filter and a real route change look the same, a named event pushed by the app is cleaner.
5. Hash routing: every screen looks like the same address
Some apps route with the part after #, as in /#/product/blue-jacket. Google’s page view guide says the default page_location “excludes the fragment portion of the URL”. So every screen can arrive as the home page.
GTM’s History Change trigger does fire when the fragment changes. In GTM, create a JavaScript Variable that returns document.location.href, and use it for page_location in step 4 below instead of {{Page URL}}. Then check in DebugView that the #/ part arrives. Google doesn’t document what GA4 does with a fragment you send yourself, so DebugView is the proof.
How do I set up a History Change trigger for GA4 page views in GTM?
For whoever maintains your GTM container. Google’s GTM tutorial for single-page apps, condensed:
- GA4 first. Admin, Data collection and modification, Data streams, your web stream. Under Enhanced measurement, open the settings, then Page views, Show advanced settings. Clear “Page changes based on browser history events”. Save.
- Built-in variables. In GTM, Variables, Built-In Variables, Configure. Turn on the History variables. Google notes they’re only needed to filter the trigger.
- Trigger. Triggers, New, History Change. All History Changes, or Some History Changes if you’re filtering (case 4).
- Update tag. Tags, New, Google tag, with your same tag ID. Configuration settings:
page_locationset to{{Page URL}}(hash router: yourdocument.location.hrefvariable),page_titleset to a page title variable, andupdateset totrue. Google saysupdatemerges the values and suppresses an immediate duplicatepage_view. No trigger on this tag. - Page view tag. Tags, New, Google Analytics: GA4 Event, event name
page_view. In Advanced Settings, Tag Sequencing, fire the update tag first. Trigger: your History Change trigger. - Check. Preview, click through the app, and confirm in DebugView one new
page_viewper screen with the rightpage_location.
Two details the tutorial leaves to you. {{Page Title}} isn’t one of GTM’s built-in variables (the page ones are Page URL, Page Path, Page Hostname and Referrer), so create a JavaScript Variable that reads document.title and name it Page Title. And Google leaves page_referrer out on purpose, so GA4 fills in the previous screen as the referrer.
If the Google tag is pasted into the site’s code rather than deployed through GTM, Google’s route is the other one: turn on both “Page loads” and “Page changes based on browser history events” in the same enhanced measurement settings, and send no page_view of your own.
| Measure | Both on | One method, named event |
|---|---|---|
page_view per route change (DebugView) | 2 | 1 |
| Views per active user (Pages and screens) | 4.6 | 2.3 |
| Route changes with the previous screen’s title (20 clicks) | 14 of 20 | 0 of 20 |
Say a headless shop runs GA4’s history setting and a GTM tag on History Change. Every route change counts twice, so views per user look healthy. The GTM tag also fires before the title changes, so product views sit under category titles and products look unvisited. Clear GA4’s setting, move the page_view tag to a named event the app pushes once each screen is drawn, and both problems go.
How do I know it’s done?
- DebugView shows one
page_viewper screen as you click through five screens, with no reload. - Each
page_viewhas its own screen’spage_locationandpage_title. Google suggests comparing each one’spage_locationandpage_referrerwith the previous one. - Back and Forward give one
page_vieweach, if you decided they should count. - Filters, sorting and tabs don’t add page views, unless you decided they should.
- A week later, Views per active user and Pages and screens look like people browsing.
- The method you chose and the date are written in the tracking documentation, so the next developer doesn’t turn the other one on.
Filed under F-103 when the title lags, and F-101 when the doubling reaches purchases.
When the fix needs the app to push a named event, I write the spec for the developer (event name, when it fires, what it carries), build the GTM side, and hand back the DebugView screenshots.
Common questions
Why does GA4 only show the landing page on my single-page app?
Nothing sends a page_view when the screen changes. GA4’s browser history setting is off and GTM has no History Change tag, or the app doesn’t change the address through the browser’s history at all. Case 1.
Should I use GA4’s history setting or a GTM History Change trigger?
If your tags are in GTM, Google says to use the History Change trigger and leave GA4’s automatic history tracking off, because running both double-counts. GA4’s setting is the route for a Google tag pasted into the site’s code.
Why are page views doubled on my single-page app?
Usually both methods are on: GA4’s browser history setting and a GTM tag on History Change. Keep one. Case 2.
Why does the page_view carry the previous page’s title?
The tag read the title before the app changed it. The fix is a named event the app pushes once the new screen is ready. Case 3.
Does a hash URL like /#/product count as a new page in GA4?
Not by default. Google says page_location leaves out the part after the #. Send the full address from a variable that reads document.location.href, then check it in DebugView. Case 5.
Do I need a developer to fix this?
For cases 1 and 2, no: they are settings in GA4 and GTM. For a stale title, a hash router or an app that doesn’t use the browser’s history, yes: the app has to push a named event when each screen is ready.
If DebugView itself shows nothing, start with GA4 DebugView is empty. If GTM Preview won’t open, see GTM Preview won’t connect.
Sources
Read on 18 November 2026:
- Google for Developers, Measure single-page applications (browser history changes recommended when the app uses
pushState()andreplaceState(); custom events for apps that render withDocumentFragment; “If you configure your tags using Google Tag Manager, don’t enable automatic history tracking in Google Analytics, as this can lead to double-counting page views”; enable both Page loads and Page changes based on browser history events; compare eachpage_view’s referrer and location with the previous one) - Google for Developers, Measure single-page applications with Google Tag Manager (last updated 12 June 2026: clear “Page changes based on browser history events” first; History variables optional; History Change trigger “fires whenever a history change event (like
pushStateorreplaceState) occurs”; Google tag withpage_location,page_titleandupdate: true, no trigger; GA4 Event tagpage_viewwith tag sequencing;page_referrerleft out so GA4 fills in the previous virtual page) - Google Analytics Help, Enhanced measurement events (
page_view“each time the page loads or the browser history state is changed by the active site”; an advanced setting controls history-based page views; listens for pushState, popState and replaceState) - Google for Developers, Measure pageviews (a page view is sent when a page loads or the browser history changes; the default
page_location“excludes the fragment portion of the URL”; “If you send manual pageviews without disabling pageview measurement, you may end up with duplicate pageviews”) - Google Tag Manager Help, History change trigger (fires “when the URL fragment changes or when a site uses the HTML5 pushstate API”; for virtual pageviews in single-page web applications)
- Google Tag Manager Help, Built-in variables for web (History Source reads
gtm.historyChangeSource, set by History Change triggers; page variables: Page Hostname, Page Path, Page URL, Referrer)