Start free

How to use hash routes, back/forward and prerendering (spa.js)

An optional add-on for apps that use hash routes (#/settings), and for any site where people use Back and Forward a lot. The core script stays exactly as it is.

Getting startedFeature page: Single-page app add-on: #/ routes, back/forward restores and prerenderingFeature page: Under 1 KB script and single-page apps
Hash routes, back/forward and prerendering (spa.js): example screenshotHash routes, back/forward and prerendering (spa.js): example screenshot
Example screenshot with made-up data, not a real customer’s numbers.

What it does

spa.js sits next to script.js or events.js, or goes into a one-file bundle. With data-hash on the tag, each #/ route counts as its own page (stored as /app#/settings, without the route’s query part); plain #section anchors are ignored, and the first route on load is attached to the core script’s pageview rather than counted twice. Pages restored from the browser’s back/forward cache are counted, which the core script cannot see. The add-on’s own pageviews wait until a prerendered page is actually shown.

Why it matters

Hash-routed apps otherwise look like one page, and back/forward-cache restores are silently missed. Fixing both in an add-on keeps the standard script small and unchanged for everyone else.

How to use it

  1. Keep your normal quietstats tag as it is.
  2. Add the spa.js tag after it. Add data-hash if your app uses #/ routes.
  3. Or tick Single-page apps (and Count #/ routes as pages) in Manage site → One-file bundle and replace your tag with the one it gives you.
  4. Open the dashboard: routes show as /path#/route in Top pages.

How it works

What the single-page app add-on counts1. Page loads: the core script counts /app as usual. 2. With data-hash and a #/ route in the address, the add-on attaches the route to that pageview: /app#/settings. (otherwise: No extra pageview.) 3. The route changes (#/billing): one new pageview. (otherwise: #section anchors: ignored.) 4. Back or Forward restores the page from the browser cache: one pageview. 5. Prerendered page? The add-on waits until it is shown before sending.1Page loads: the core scriptcounts /app as usual.2With data-hash and a #/ routein the address, the add-onattaches the route to thatpageview: /app#/settings.No extrapageview.3The route changes (#/billing):one new pageview.#sectionanchors:ignored.4Back or Forward restores thepage from the browser cache:one pageview.5Prerendered page? The add-onwaits until it is shown beforesending.
From src/tracker.spa.src.js (served as /js/spa.js). script.js is unchanged.

Privacy

Limits

Plans

Every plan, including Free. quietstats is free during launch: the Free plan covers 1 site and 5,000 pageviews a month, and no card is needed. See pricing.

Questions

Do I need this for React, Next.js or Vue?

Only if your router uses #/ URLs or you want back/forward-cache restores counted. pushState routers are already counted by the core script.

Will routes be counted twice?

No. The first route on load updates the core script’s pageview, and later route changes are counted once each.

Does it work with custom events?

Yes. Put it next to events.js, or tick both in the one-file bundle.

Set it up

Show the install snippet
HTML
<script data-host="https://quietstats.co.uk" data-site="YOUR_SITE_ID" data-dnt="true" data-hash src="https://quietstats.co.uk/js/spa.js" async defer></script>

Replace YOUR_SITE_ID with the ID shown on your site’s Manage page.

Related

Feature page: Single-page app add-on: #/ routes, back/forward restores and prerendering → What it is, why it matters, privacy and how other tools do it.

Guides on this topic

All website analytics guides →

Related features

Browse all 448 features →

Explore quietstats

See your traffic (119)

Live visitors and live eventsTrend charts, headline cards and any date rangeCompare any two date rangesWorld map, countries and regionsDevices, browsers, operating systems and screens

Sources and campaigns (63)

Sources and channelsAI search referralsUTM campaignsSearch keywords from Google Search ConsoleShort links

Behaviour and content (80)

Top pagesPage transitionsScroll depth and engaged timeClick mapVisitor journeys

Goals, events and conversions (83)

Goals and funnelsCustom events and conversion ratesRevenue cards and revenue by sourceEngagement goalsA/B tests with your own tags and a plain-English confidence note

Reports, sharing and alerts (44)

Alerts inbox and rulesReport snapshotsPassword-protected snapshotsOptional public stats pageAnonymous benchmarks against similar sites

Data in and out (42)

CSV and Excel downloadsStats APIImport from Plausible or GA4API playgroundTSV and XML export for every report

Privacy and performance (17)

Zero cookies, privacy built inUnder 1 KB script and single-page appsPages never countedPrivacy proof page and badge for your siteSigned-in sessions

Why quietstats

Why quietstatsPricingLive demoStart free

Compare

quietstats comparedFeature comparisonvs Google Analyticsvs Plausiblevs Fathom Analyticsvs Simple Analyticsvs Umamivs Matomovs Cloudflare Web Analyticsvs GoatCountervs Piwik PROvs PostHogvs Microsoft Clarityvs Pirsch Analyticsvs MixpanelGoogle Analytics alternatives

Learn

Website analytics guidesMetrics handbookAnalytics glossaryPlaybooksGDPR and cookie-free analyticsInstall on SquarespaceInstall on WixInstall on GhostInstall on Google Tag ManagerBlog

Playbooks and tools

Script size calculatorCookie banner checkerPlaybook: Local businessPlaybook: Online shopPlaybook: Blog or publisherPlaybook: SaaS or appPlaybook: Charity or community groupPlaybook: Agency with clientsUTM link checkerConversion rate calculatorCookie banner traffic-loss calculator