Skip to content
FunnelGuard

Fix guide by FunnelsGuard

GA4 page_referrer wrong after SPA navigation: how to fix it

TRK-075Low impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

page_referrer is a parameter GA4 attaches to page_view events. On a normal site, it is the URL the visitor came from. GA4 reads it from document.referrer, which the browser sets on a full page load.

A single-page app (built with React, Vue, Angular, Next.js and similar) changes the URL with the History API instead of loading a new page. document.referrer does not change. So the next page_view can show the original external referrer, or the wrong internal page, instead of the page the visitor just left.

GA4's Enhanced measurement can send a page_view on browser history changes. It sets the referrer for these, but custom setups, tag managers and router libraries can override or lose it. Results vary by setup, so test yours.

Why it costs you leads or sales

The business impact is low, but it muddies your data. Page paths in reports can look like they came from the wrong place. Path analysis and funnel steps that rely on the previous page become less trustworthy. Internal navigation can also show up as a referral from your own domain if your settings are off.

It rarely stops a lead or sale. It makes it harder to see which pages lead to your form or checkout, so you may make decisions on a wrong picture.

How a stale referrer appears in a SPA
  1. Landing pageFull load. Referrer is google.com. Correct.
  2. Route change to /pricingNo reload. Referrer still google.com.
  3. Route change to /contactReferrer still google.com, not /pricing.
  4. Path analysisPrevious-page data is wrong.

The page never reloads, so the browser referrer stays at the first value.

How to check if your site has it

Check page_referrer in GA4 DebugView
  1. Turn on debug mode

    Use the Google Analytics Debugger Chrome extension, or Preview mode in Google Tag Manager.

  2. Open DebugView

    In GA4, go to Admin, then DebugView, and pick your device.

  3. Click through three or four pages

    Navigate using the site's own links, without reloading.

  4. Inspect each page_view

    Open the event and compare page_location and page_referrer. The referrer should be the previous page's URL.

  5. Compare with a full reload

    Reload a deep page. If the referrer is right only after a reload, your route changes are the problem.

How to fix it

The principle is the same everywhere: on each route change, send a page_view with page_location set to the new URL and page_referrer set to the URL of the route the visitor just left. Turn off duplicate automatic page views so you do not count each navigation twice.

Fix by platform
  1. Disable the automatic page_view

    In your gtag config, set send_page_view to false so the router controls page views.

  2. Track the previous URL

    Store the last URL in a variable and update it after each route change.

  3. Send page_view on each route change

    Call gtag('event', 'page_view', {...}) with page_location and page_referrer from your router's navigation hook. See the code below.

Send a virtual page_view with the right referrer (gtag.js)javascript
// In your GA4 config, disable the automatic page view:
// gtag('config', 'G-XXXXXXX', { send_page_view: false });

let previousUrl = document.referrer;

function trackVirtualPageView() {
  const currentUrl = window.location.href;
  gtag('event', 'page_view', {
    page_location: currentUrl,
    page_referrer: previousUrl,
    page_title: document.title
  });
  previousUrl = currentUrl;
}

// Call once on first load, then from your router's after-navigation hook.
trackVirtualPageView();
page_view parameters on a route change

Before

  • page_location: /contact
  • page_referrer: https://www.google.com/
  • Previous page is lost

After

  • page_location: /contact
  • page_referrer: /pricing (full URL)
  • Previous page is correct

How to confirm it's fixed

Confirmation checklist
  • In DebugView, each route change sends exactly one page_view.
  • page_location matches the visible URL.
  • page_referrer equals the full URL of the previous route.
  • The first page of a visit still shows the real external referrer.
  • Reloading a deep page still shows a sensible referrer.
  • Page counts in Reports do not jump after the change, which would point to double counting.

How to prevent it happening again

Prevention
  • Add a DebugView check to your release checklist for any router, framework or tag manager change.
  • Document who owns page view tracking: the router code, GTM, or Enhanced measurement, but only one.
  • Re-test after migrating to a new framework, theme or page transition library.
  • Keep a note of the previous-URL logic so it is not removed during refactors.

How FunnelGuard handles this

FunnelGuard does not check this yet. Verifying the page_referrer value on each virtual page view is a possible future check, not a current feature.

What FunnelGuard does today is run your real customer journeys on a schedule, check each step, confirm the tracking hits for GA4 and other ad and analytics platforms are sent, and check that test leads reach your inbox and CRM. That can show a missing or broken page-level tag, but it does not judge whether the referrer value is correct.

To watch for this issue yourself, run the DebugView check after each release, or compare a few sessions in GA4 Explore with the Page referrer dimension. A Free plan is available if you want to monitor the rest of your funnel meanwhile, with 1 site and 2 journeys.

Questions people ask

Why is my GA4 page_referrer wrong in a single-page app?

A single-page app changes the URL without reloading the page, so the browser's document.referrer stays at its first value. GA4 can then send that stale value on later page views. Send each virtual page_view with page_referrer set to the previous route's URL.

How do I set page_referrer manually in GA4?

Send a page_view event with a page_referrer parameter. With gtag.js, call gtag('event', 'page_view', { page_location: currentUrl, page_referrer: previousUrl }). In Google Tag Manager, add page_referrer as a parameter on your GA4 Event tag.

Does GA4 Enhanced measurement fix SPA page views?

Enhanced measurement can send page views on browser history changes, which covers many SPAs. Results vary with your router and tag setup, so check DebugView. If you send your own page views, turn that option off to avoid duplicates.

How can I check page_referrer in GA4?

Open Admin, then DebugView, with debug mode on, and click through your site. Open each page_view and compare page_referrer with the page you just left. You can also see the dr parameter on collect requests in the browser's Network tab.

Why does my own site show as a referrer in GA4?

If page_referrer holds your own domain, internal navigation is being treated as a referral in some reports. Add your domain under Admin, Data streams, Configure tag settings, List unwanted referrals. Also check that your virtual page views send the correct referrer.

Will a wrong page_referrer lose me leads?

No, it does not stop forms or checkouts from working. It makes page-path and navigation reports less reliable, so the impact is low. Fix it so your analysis of what leads to conversions is accurate.

Does FunnelGuard check page_referrer?

No. FunnelGuard does not check this yet, and it is a possible future check. It does run your funnel journeys on a schedule and checks tracking hits are sent, so use DebugView to verify the referrer value.

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.