Skip to Content
Tracking & EventsSingle-page apps

Single-page apps

In a single-page app (SPA), moving between “pages” doesn’t reload the browser; the framework swaps the content and updates the URL. Snow handles this for you.

It just works

When the URL changes through the browser’s History API (which is how React Router, Vue Router, Next.js, SvelteKit, Astro, and essentially every modern router navigate), Snow automatically records a new page view. You don’t need to add any router hooks or call anything yourself. Install the snippet once in your root layout and client-side navigations are tracked.

Snow watches for pushState, replaceState, and the browser back/forward buttons (popstate), and only counts a page view when the URL actually changes, so replacing the URL with the same path won’t double-count.

Recording a page view manually

Use sa.page() when you want to record a view yourself, for a “virtual” page like a modal or wizard step, or a router that doesn’t use the History API:

// Record the current URL as a page view sa.page(); // Record a specific path (e.g. a virtual step) sa.page("/checkout/step-2");

Hash-based routing

Snow detects History-API navigations and back/forward. If your router changes only the URL hash (for example /#/dashboard), call sa.page() yourself whenever the route changes:

window.addEventListener("hashchange", () => sa.page());

Most frameworks use the History API by default, so you won’t need this. Reach for manual sa.page() only for hash routers or virtual page views.