Skip to content
Glossary

Single-page application

A single-page application (SPA) loads one HTML document and then draws every later 'page' in the browser with JavaScript, updating the address bar without a full page load. Apps built with React, Vue, Angular or Svelte often work this way.

Updated

Also called: SPA, single page app, client-side routing

Definition

On a classic website every click requests a new HTML page from the server, and every load runs the analytics script again. In an SPA, the first load brings the app; after that, a client-side router changes the URL with the browser's History API and renders the new view itself. Many frameworks mix the two, rendering the first page on the server and navigating in the browser afterwards.

Why SPAs trip up analytics

Calling history.pushState() or history.replaceState() changes the URL without loading a page, and it doesn't fire the popstate event, which fires for history navigation such as the back and forward buttons. A script that counts page loads therefore records the first page and nothing after it. A tracker has to wrap the History API, listen for popstate, and decide what counts as a new page.

Signs your SPA tracking is broken

  • Page views barely move while signups and orders grow.
  • Almost every session looks like a bounce, because each records a single page view.
  • Entry pages look right, but exit pages and user flows are nearly all the first page.
  • Session lengths look implausibly short or long for how people use the app.

How Linqry handles SPAs

The script wraps history.pushState and history.replaceState and listens for popstate. After each one it compares the new path and query string with the last recorded page. If they changed, it sends a pageleave event carrying the time on page for the route being left, then a pageview for the new one. A replaceState call that leaves the URL unchanged records nothing.

Hash-only changes, such as /#/settings, are ignored by default because they usually mean a jump within the page. Add data-hash-routing to the script tag if your router puts routes in the hash:

<script defer data-website-id="YOUR_SITE_ID" data-hash-routing src="https://linqry.com/t.js"></script>

Calls to window.linqry() made before the script has loaded are kept by the snippet's first line and sent once it arrives, so events fired early in your app's startup aren't lost. The Next.js, React and Vue guides show where the snippet goes.

Pitfalls

  • Double counting. Don't call window.linqry('pageview') from your router. Linqry already records route changes, and a custom event with that name would count as a second page view.
  • URL churn. Search boxes and filters that rewrite the query string on every keystroke create a page view for each change. Debounce those updates or keep that state out of the URL.
  • Dialogs with their own URLs. If opening a modal pushes a new URL, it counts as a page view. Decide whether that's what you want.
  • Excluded routes. Paths matched by data-exclude send nothing, including route changes into them.

Related terms

Frequently asked questions

Do I need a plugin to track a single-page app with Linqry?

No. The same script tag works on classic sites and single-page apps; it detects History API navigation by itself.

Does a route change start a new session?

No. A session continues while page views keep arriving less than 30 minutes apart, whether they come from full page loads or route changes.

Sources

  1. MDN Web Docs: Window, popstate event (checked Nov 14, 2026)
  2. MDN Web Docs: History, pushState() method (checked Nov 14, 2026)

Measure your own site without cookies

No card required · 30-day trial · No cookies