PureStats documentation

SPA routing

Track single-page applications with PureStats using automatic or manual pageviews. Avoid duplicate events and preserve campaign data during client navigation.

Single-page applications change the URL without a full document reload. PureStats handles common History API route changes automatically, but custom routers may need manual pageview calls.

Automatic tracking

The tracker observes:

  • Initial page load.
  • history.pushState.
  • history.replaceState.
  • Browser back and forward navigation.
  • Hash routes that start with #/.

This covers most React Router, Vue Router and Next.js client transitions.

Manual tracking

PureStats counts a pageview only when the URL changes. Calling purestats('pageview') on an unchanged URL does nothing, and the call takes no path. If your app changes visible screens without changing the URL, give each screen its own URL, or record the change as a custom event:

window.purestats?.('Screen Viewed', { screen: 'billing_checkout' });

To report a cleaned or normalized path for every pageview, use the beforeSend hook in the JavaScript API.

Avoid duplicate pageviews

You don't need to send pageviews yourself after route changes. Check the Network panel: one route change should produce one accepted pageview event.

Campaign parameters

UTM parameters are captured on landing pages. If a SPA removes UTM parameters immediately after load, make sure the tracker runs before the URL cleanup.

Cross-domain flows

When a visitor moves from www.example.com to checkout.example.com, add the hostname in Site settings → Domains and enable cross-domain stitching in Site settings → Privacy settings if you need the visit to continue across hostnames.