WebmasterID logoWebmasterID
Referrers

Referrers in single-page apps

In a single-page app, the History API changes the URL and view without a full page load, so the browser does not send a new Referer header for each route. The header reflects the original entry point, not the internal navigation, which means SPA analytics must capture referrer and entry data at first load and track route changes separately.

Verified against primary sources

Why SPAs break naive referrer reads

A single-page app uses the History API (pushState/replaceState) to change the URL and render a new view without a full document load. Because there is no new HTTP navigation, the browser does not generate a new Referer header for each route — document.referrer keeps pointing at the page that originally loaded the app.

This means an analytics call fired on an internal route that reads document.referrer will see the original external entry point (or empty), not the previous in-app view. Treating that value as the referrer of the current screen double-counts or misattributes the source.

How to capture referrer correctly in an SPA

Capture the entry referrer once, at the first load, and persist it for the session so later in-app events can be attributed to the original source. For internal navigation, track the previous route in app state rather than relying on the Referer header, which will not change.

Keep campaign attribution on the entry URL: read UTM parameters at first load and store them, because client-side route changes can drop the query string from the visible URL. Server-side capture at the initial request is the most reliable point to record both the referrer host and the campaign parameters before the SPA takes over navigation.

How it appears in analytics and logs

In an SPA, the document Referer is set on the first real navigation and does not update when the app pushes a new route. Internal view changes carry no fresh Referer, so per-view referrer reads are stale unless the app records the entry referrer itself.

Diagnostic use case

Explain why an SPA's internal navigations do not generate new referrers, and capture the true entry referrer once at load instead of per route change.

What WebmasterID can help detect

WebmasterID captures the entry referrer server-side at first load and associates later in-app events with that original source, so SPA route changes do not blank out or duplicate the channel.

Common mistakes

Privacy and accuracy notes

SPA tracking should record the entry referrer host and route path only — not a per-user fingerprint. WebmasterID treats the entry referrer as a channel signal, never as visitor identity.

Related pages

Sources and verification notes

Last reviewed 2026-06-24. Facts are checked against primary/official sources where available; uncertain specifics are marked “Data not yet verified” rather than guessed.