Cookie preferences

Choose which optional cookies EndFrame may use on this site. Analytics and advertising tools load only if you allow them, and you can change your mind any time from “Cookie settings” in the footer. Whatever you choose, this tab keeps the campaign labels from the link that brought you, and they are saved with your account if you sign up. Read the Cookie Policy.

Needed for the site to work, such as remembering this choice. Always on.

Lets us load analytics tools through Google Tag Manager, including Google Analytics and Microsoft Clarity session recordings, to understand how the site is used.

Allows advertising tags to measure our ad campaigns. None run on this site today. It also keeps ad click IDs from the page address for this tab, and saves them with your account if you sign up.

Skip to main content

Single Page Application Tracking in GA4 and Meta Pixel: Fix Missing or Duplicate Page Views

A plain-English guide for marketers whose React, Next.js or Vue site shows too few or too many page views. It names the GA4, Tag Manager and Meta Pixel setting behind each symptom, explains why URL-based conversions break, and lists what to ask the developer.

The EndFrame Team7 min read

A single page application (SPA) is a site that loads once and then swaps content in place as the visitor clicks around. The address bar changes, but the browser never loads a new page. Most tags were built around page loads, so on an SPA they either fire once per visit and miss every later screen, or fire twice when two different pieces of code both try to fill the gap. In GA4 the fix is almost always one setting: Page changes based on browser history events. The Meta Pixel handles route changes by itself. The rest of this guide shows how to tell which problem you have and which tag is responsible.

How to tell a site is a single page app

Sites built with React, Next.js, Vue, Angular or Svelte usually behave this way, but the framework name matters less than the behaviour. You can check it yourself in two minutes in Chrome:

  1. 1Open the site, right click, choose Inspect and open the Network tab.
  2. 2Tick Preserve log, so the list is not cleared when a new page loads.
  3. 3Click the Doc filter, so only page documents (the HTML of each page) are listed.
  4. 4Click an internal link, such as Pricing in the menu.
  5. 5On a normal site a new row appears under Doc for the new page. If the address bar changed but no new row appeared, the page was swapped in place. That route change is invisible to any tag that waits for a page load.

Behind the scenes, the app changes the address with the browser's History API, a set of functions called pushState and replaceState, plus a popstate event that fires when the visitor presses Back. Those three names matter, because they are exactly what GA4 and the Meta Pixel listen for.

How GA4 counts page views on a single page app

The Google tag sends a page_view when it loads, because the config command has a setting called send_page_view that defaults to true. Enhanced measurement can also send a page_view each time the app changes the browser history. Google's help centre says this option listens for pushState, popState and replaceState. To change it, you need the Editor role or above on the property:

  1. 1In GA4, go to Admin, then under Data collection and modification click Data streams.
  2. 2Choose your Web stream. Under Enhanced measurement, make sure the switch is on, then click the settings gear.
  3. 3Open Page views and click Show advanced settings.
  4. 4Tick both Page loads and Page changes based on browser history events, then click Save.

Two details catch developers out. First, setting send_page_view to false only stops the page view on load. Google's own documentation says GA4 still sends page views on history changes while the advanced setting is on. Second, because replaceState is included, an app that rewrites the address every time a filter or tab changes can log a page view for each of those changes too. Our guide to GA4 enhanced measurement events covers the other automatic events in the same panel.

One page view per visit, or two per click: the usual causes

The symptom points to the cause. Compare views per session in a GA4 Explore report with what you see when you click through the site yourself.

What you seeLikely causeFix
One page view per visit, however many screens were viewedBrowser history setting is off, and nothing else sends page views on route changesTurn on Page changes based on browser history events
Two page views for every route changeBrowser history setting is on, and a Tag Manager History Change trigger or manual code also sends page_viewKeep one method only, usually by turning the GA4 setting off when Tag Manager or code handles it
Two page views on the first page onlyDeveloper sends a manual page_view on load while send_page_view is still trueSet send_page_view to false or remove the manual call for the first load
Extra page views when filters or tabs changeThe app uses replaceState for small changes and the history setting counts themAsk the developer to stop rewriting the address for minor state, or send page views manually

If the site uses Google Tag Manager

Google's single page application guide is direct: if you configure tags with Tag Manager, do not enable automatic history tracking in GA4, because it can double count page views. Google's companion tutorial for Tag Manager starts by unticking Page changes based on browser history events, then fires the page view from a History Change trigger, which responds when the site changes the address with pushState or replaceState. If the GA4 tags in a container fire only on Initialization or Page View triggers, they fire when a page loads, which on an SPA means once per visit. Pick one listener, Tag Manager or GA4, never both.

If the site is built with Next.js

Next.js offers a GoogleAnalytics component in the @next/third-parties package. Its documentation says client side navigations are tracked through GA4's history detection, so the browser history setting must be ticked for them to count. It also warns that a developer who sends page views manually must disable the default page view measurement to avoid duplicate data.

The Meta Pixel on single page apps

The Meta Pixel sends a PageView when its base code loads. Meta's single page application guide says you can set disablePushState to true to stop sending PageView events on history state changes, which means the Pixel sends them unless someone turns that off, and Meta says turning it off is not recommended. So on a React or Next.js site you normally need no extra code for PageView. Duplicates appear when a developer or a Tag Manager tag adds fbq('track', 'PageView') on each route change on top of the automatic one. Other events, such as ViewContent or Lead, still need to be fired from the app's routing or form code, as Meta's guide explains. The Meta Pixel not firing checklist covers the cases where nothing arrives at all.

Conversions that depend on a URL

URL rules are the weakest kind of conversion on an SPA. A Meta custom conversion with a rule such as URL contains /thank-you, or a GA4 key event created from page_view where page_location contains /thank-you, only works if two things are true: the address really changes after the form succeeds, and a page view is sent for that route change. Many modern forms show an inline success message without changing the address at all, so there is nothing to match. Others change the address but the tag misses it, because the history setting is off.

The reliable fix is an event fired when the submission succeeds, such as generate_lead in GA4 and Lead in Meta, sent from the app's own success code. Our comparison of thank-you page and event conversion tracking explains how to switch without losing history. If you use EndFrame, the same applies to its goals: use an event goal fired by endframe.track for an inline success message rather than a URL match goal. When counts are already inflated, the guide to duplicate conversions helps trace which source is doubling them.

Campaign parameters and click IDs on the first screen

GA4 reads campaign parameters such as utm_source, utm_medium and utm_campaign from the page address, and click IDs such as Google's gclid arrive the same way. The page_location parameter defaults to the full address of the page at the moment the tag reads it, without the fragment. Some apps tidy the address on load, for example by redirecting to a clean route or removing the query string with replaceState. If that happens before the Google tag reads the address, the session loses its campaign and is credited to the referring site or to direct traffic instead. Meta's fbclid click ID also arrives in the address, so the same risk applies to the Meta Pixel. Our list of reasons UTM parameters do not show in GA4 covers the redirect version of this problem.

How to test the fix in DebugView

Use a test link with UTM parameters and walk through the site with debug mode on, using Tag Assistant or Tag Manager preview. Then in GA4 go to Admin, and under Data display click DebugView. The GA4 DebugView guide explains the screen in detail.

  • Each click to a new screen produces exactly one page_view in the seconds stream.
  • The first page_view shows a page_location that still contains your utm_ parameters.
  • On each later page_view, page_location shows the new address and page_referrer shows the previous one, which is the check Google recommends.
  • Changing a filter or tab does not add a page view, unless you want it to.
  • Submitting a form produces your lead event once, whether or not the address changes.

What to ask your developer

You do not need to read the code to get this fixed. Send these questions:

  1. 1Which router does the site use, and does it change the address with pushState, replaceState or a hash?
  2. 2Is GA4 loaded directly, through the Next.js GoogleAnalytics component, or through Tag Manager?
  3. 3Is any code or tag sending page_view or fbq PageView on route changes? If yes, which one should we keep?
  4. 4Has anyone set send_page_view to false or disablePushState to true, and why?
  5. 5Does any code rewrite or strip the query string before the tags load?
  6. 6Which events fire when a form or checkout succeeds without a page change?

Frequently asked questions

Will fixing duplicate page views correct my old GA4 data?

No. A change to the tag or to enhanced measurement applies from the moment it is live. Page views already collected stay as they were, so engagement rate, views per session and any key event built on page_view will shift on the day of the fix. Note the date and compare periods on either side of it rather than across it.

Does single page tracking affect engagement time and scroll events?

Yes. Google says that when virtual page views are set up correctly, a user_engagement event is sent on each navigation with the engagement time for the previous screen. It also asks developers to reset the scroll position after each route change, otherwise the scroll event, which fires once per page at 90 percent depth, measures the wrong screen.

My site uses addresses like example.com/#/pricing. Is that different?

Yes. The part after the hash is a fragment, and the default page_location in the Google tag leaves the fragment out. Different screens can then be reported as the same page, or not counted as new page views at all. The developer needs to send page_view manually with a page_location that includes the screen name, or move the app to normal paths.

Try EndFrame

Add a server-side path for your conversions.

EndFrame collects events first-party and forwards conversions server-side to Meta, GA4, TikTok, and webhooks with event-ID deduplication — then credits each conversion to its campaign, with the visit-to-conversion path you can audit.

No credit card required

Keep reading