Skip to content
FunnelGuard

Fix guide by FunnelsGuard

GA4 events sent with stale page_location in a SPA: how to fix

TRK-073Medium impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

A single-page app, built with React, Vue, Angular or a similar framework, loads once and then swaps content and changes the address bar with the browser History API. The browser never does a full page load, so tags that only run on load do not run again.

GA4 sends the page address in the page_location event parameter. On the wire it shows up as dl in the request to google-analytics.com/g/collect. If your setup reads the URL once, at load, every later event carries that first URL. That is a stale page_location.

Why it costs you leads or sales

Stale URLs make your reports describe a different journey from the one visitors took. The damage is usually quiet, which is why it lasts.

What goes wrong in your data
  • Every event is credited to the landing page, so a pricing or checkout step looks like it never happens.
  • Funnel explorations and path reports that filter on page_location miss steps or show the wrong ones.
  • Conversions are credited to the wrong page, so you improve the wrong page.
  • Audiences and conversion rules built on a URL contain (for example /thank-you) never match.
  • Page-based triggers in ad platforms that read the URL can fire on the wrong page or not at all.
Where purchase events are creditedExample numbers
Where purchase events are credited (example)Landing page (stale): 92 % of purchase events; Checkout page (stale): 8 % of purchase events; Landing page (fixed): 3 % of purchase events; Checkout page (fixed): 97 % of purchase events03774928397Landing page (stale)Checkout page (stale)Landing page (fixed)Checkout page (fixed)% of purchase events

Example: with a stale page_location, almost all purchase events are credited to the landing page; after the fix they appear on the checkout step where they happened.

How the stale URL spreads
  1. Landing /page_view sent with the right URL
  2. Route change to /pricingNo page_view sent, or sent before the URL updates
  3. Click eventdl still shows /
  4. generate_leadCredited to / in reports

The route changes without a page load, so the later events keep the first URL.

How to check if your site has it

Check page_location on later events
  1. Open the site and DevTools

    Open the Network tab in your browser DevTools and filter by collect. Tick Preserve log.

  2. Load the first page

    Note the dl value in the first request. It should match the address bar.

  3. Navigate inside the app

    Click internal links without reloading the page, then trigger an event such as a button click or form submit.

  4. Compare dl with the address bar

    If dl still shows the first URL, or the URL from one step earlier, your page_location is stale. Also check that a new page_view fires on each route change.

  5. Confirm in GA4

    In Admin > DebugView, click an event and read its page_location parameter. In Reports, a page report with very few pages despite a multi-page app is a warning sign.

How to fix it

The goal is the same everywhere: on each route change, wait until the URL has updated, send a page_view with the new location, and make sure other events read the current URL at the moment they fire.

Fix by platform
  1. Turn off automatic page_view in the config tag

    In your Google tag, set the parameter send_page_view to false only if you add your own page_view trigger. Otherwise you will get duplicates.

  2. Use a History Change trigger

    Create a trigger of type History Change. Fire a GA4 Event tag named page_view on it, in addition to the All Pages or Initialization trigger for the first load.

  3. Pass the current URL

    In the event tag add the parameter page_location with the built-in variable {{Page URL}}. Enable Page URL, Page Path and History variables in Variables > Configure. Check in Preview that the value changes after each route change.

  4. Avoid double counting

    If GA4 enhanced measurement already tracks page changes based on browser history events, turn off Page changes based on browser history events in the web stream settings, or do not add your own page_view.

Send page_view after a route change (gtag.js)javascript
// Call this from your router's after-navigation hook
function trackRouteChange() {
  gtag('event', 'page_view', {
    page_location: window.location.href,
    page_title: document.title,
    page_referrer: window.__lastUrl || document.referrer
  });
  window.__lastUrl = window.location.href;
}

// Example with React Router
// const location = useLocation();
// useEffect(() => { trackRouteChange(); }, [location.pathname, location.search]);
Event data before and after

Stale page_location

  • One page_view at load, none on route changes
  • dl stays on the landing URL for the whole visit
  • Conversions credited to the landing page

Current page_location

  • A page_view after each route change
  • dl matches the address bar on every event
  • Conversions credited to the page where they happened

How to confirm it's fixed

Verify the fix
  1. Repeat the Network check

    Navigate through three or four routes and trigger a click and a form event. Every collect request should have a dl that matches the address bar at that moment.

  2. Use GTM Preview or DebugView

    Confirm one page_view per navigation, with the new page_location and page_title.

  3. Check reports the next day

    In Reports > Engagement > Pages and screens, you should see the real pages of your app, not just the landing page.

How to prevent it happening again

Prevention checklist
  • Keep one owner for page_view logic: either GA4 enhanced measurement, GTM, or your own code.
  • Add a route-change analytics check to your release checklist whenever the router, framework or transitions library is upgraded.
  • Never cache window.location in a variable at load for use in later events.
  • After each release, click through a few routes with DebugView open.
  • Document the setup so a new developer does not add a second page_view.

How FunnelGuard handles this

FunnelGuard does not check for stale page_location yet. It reads the dl parameter in the tracking hits it captures, but it has no rule that compares it with the page the robot was on. A check like this is a possible future addition.

What FunnelGuard does today is run your real journeys on a schedule, from the EU or the US, and confirm that the tracking hits for GA4, Google Ads, Meta and other platforms are sent at each step. It also checks that test leads reach your inbox and CRM. If a tag stops firing after a release, you get one alert with a screenshot and a likely cause after a re-check from a second region.

Questions people ask

Why is my GA4 page_location always the homepage in a single-page app?

Your page_view probably fires only on the first load. A single-page app changes the URL without reloading, so later events reuse the first URL. Send a page_view on every route change, after the address bar has updated.

What is the dl parameter in GA4?

dl is the short name for page_location in the request sent to google-analytics.com/g/collect. It holds the full URL of the page when the event fired. You can read it in the Network tab of your browser DevTools.

How do I track page views in a SPA with Google Tag Manager?

Create a History Change trigger and attach a GA4 Event tag named page_view to it. Add page_location with the {{Page URL}} variable. Make sure GA4 enhanced measurement history tracking is off, or you will count each page twice.

Does GA4 enhanced measurement track SPA page changes automatically?

It can. The Page changes based on browser history events option sends page_view when the History API changes the URL. It does not always work with every router or transition setup, so verify with DebugView.

Why do I see duplicate page_view events after fixing my SPA tracking?

Two things are sending page_view: usually enhanced measurement and your own tag or code. Keep one. Turn off the history-based option in the web stream, or remove your custom page_view.

How do I check that GA4 is sending the right page_location?

Open DevTools, go to Network, filter by collect and click through your routes. The dl value should match the address bar for each request. You can also read page_location on events in GA4 DebugView.

Does FunnelGuard detect stale page_location in GA4?

No, not yet. It checks that tracking hits are sent during your journeys, but it has no rule for comparing page_location with the current page. Check manually with DebugView or the Network tab after each release.

Does FunnelGuard catch this?

Could add

Not checked yet: could be added to FunnelGuard.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.