Skip to main content
CrispStats tracks single-page apps without extra code. The script watches the History API and, where the browser has it, the Navigation API, so route changes in Next.js, React Router, TanStack Router, Vue Router, SvelteKit and other routers count as pageviews. Routers that keep the route after # need data-hash. For a router the script cannot see, call crispstats.pageview() yourself.

How page changes are seen

The script counts a pageview when the URL has changed since the last one it counted: When two of these report the same change, such as the pushState wrapper and the Navigation API, the second sees the same URL and sends nothing.

Same URL, one pageview

The same URL twice in a row is one pageview. A router that calls replaceState to update state without changing the address, or calls pushState twice for the same route, does not inflate your numbers. The script compares the URL as it would send it: the fragment is left out unless data-hash is on, and the query string is cut to the kept parameters, so ?tab=billing and ?tab=team are the same page unless you keep tab with data-keep-params.

Referrer on navigation

The first pageview carries the external referrer: the site the visitor came from. On every later navigation in the same page load, the referrer is the previous tracked page on your site. An excluded page is never used as a referrer.

Engagement before each navigation

Time on page and scroll depth are reported per pageview. Before each single-page navigation, and whenever the page is hidden or left, the script sends a ping with the seconds the page has been visible so far and the furthest scroll depth so far as a percentage. A ping is sent only when the visible time has grown by at least one whole second, so a page left within its first second sends none. Time in a background tab or in the back/forward cache is not counted.

Routers that saved pushState early

The script wraps history.pushState when it starts. A router that saved its own copy of pushState before that calls the original, which the wrapper never sees. This happens when the script loads late, for example with next/script and strategy="afterInteractive", and with routers such as vinext that keep a reference at startup. The Navigation API covers this: it reports every URL change, however the router made it. Browsers that have it, such as Chrome and Edge, see these route changes. In a browser without it, such a router’s navigations are missed, and only the first pageview of each full page load is counted. To see whether a browser has it, run "navigation" in window in its console. To check your app, open it in a browser where "navigation" in window is false, with debug mode on, click between routes and watch the console. One crispstats: pageview not sent (debug mode) line per route change means the script sees your router. If route changes log nothing, use manual pageviews.

Manual pageviews

Add data-manual to the tag and the script counts no pageview on its own, not even the first one. Your code calls crispstats.pageview() after each page change instead. Use it only when the script cannot see your router, or when you want to decide yourself what a page is.
Then call pageview() once per page, including the first. In Next.js, a client component in the root layout does it:
app/crispstats-pageviews.tsx
Render <CrispStatsPageviews /> inside a <Suspense> boundary in app/layout.tsx, because useSearchParams needs one. Add the queue stub and the global types so the call is typed and is not lost before the script loads. How pageview() behaves: A URL you pass is resolved against the current page and cut like any other: fragment and unkept query parameters are removed. Calls made before the script loads wait in the queue stub and run once it starts.
Under data-manual, events sent before the first pageview() call are dropped, because they belong to no page. Call pageview() before your first custom event. In debug mode, such events log not sent (no pageview yet).
Without data-manual, pageview() is still there as a safety net: a router hook that calls it after each change costs nothing when the script already saw the change.

Hash routers

If your app routes with the fragment, such as https://example.com/#/settings, add data-hash to the tag:
With data-hash, the script sends the fragment when it is a route, one that starts with #/ or #!/, and a change of route counts as navigation. A query string inside the fragment is cut like any other. Any other fragment, such as #pricing or #access_token=…, is removed in the browser, so /#/settings shows as /#/settings in your reports and an in-page anchor never counts as a page.
Leave data-hash off on a site with real paths, such as Next.js, Nuxt, SvelteKit, Astro or Remix. It does no harm there, since only #/ and #!/ routes are read, but it has nothing to read either.
Without data-hash, the fragment is cut from every URL before it is sent.

Check it works

1

Turn on debug mode locally

Use the tag with data-debug from localhost and testing. It logs each event in the console and sends nothing.
2

Navigate between routes

Each route change logs one crispstats: pageview not sent (debug mode) line, with the payload. Its u is the new URL. If you stayed on the previous route for a second or more, a ping line for that page comes just before it.
3

Watch the live feed after you deploy

With the normal tag on your live site, open Realtime in the dashboard. Each navigation appears in the Live feed within a few seconds.

Next steps

Script attributes

Every option the script reads.

Next.js

The script, a proxy and 404s in a Next.js app.

Localhost and testing

Debug mode, local builds and tests in CI.
Last modified on November 18, 2026