Skip to content
Tracking and technical

What is single-page application tracking?

3 min read · Updated · By the Reveata team

Short answerSingle-page application (SPA) tracking is recording a page view each time a JavaScript app such as a React, Vue or Angular site changes its route without a full page reload, so that every screen a visitor sees is counted as its own page.

On a traditional website, every click loads a new HTML page and the analytics script runs again. A single-page application loads once and then swaps content in place, updating the address bar with JavaScript. If the analytics script only counts page loads, a visitor who opens ten screens looks like a visitor who saw one page and left.

How route changes happen

Most SPA routers use the browser's History API. Moving to /pricing calls history.pushState, and the back button fires a popstate event. The address changes, the page does not reload.

Some routers use the hash instead: https://example.com/#/pricing. Here the part after # holds the route, and the browser fires hashchange when it changes.

A tracking script for SPAs has to listen for these changes and send a page view for each one, with the new address and the previous page as the referrer.

How Reveata tracks SPAs

The Reveata script handles History API routing on its own: it records a page view on every history.pushState, replaceState and back or forward navigation (Install the script). React, Next.js, Vue, Nuxt, SvelteKit, Angular and other frameworks have their own setup guides under frameworks and site builders.

For hash routers, add data-hash="true". Each hash route then counts as its own page, stored as a path like /app/#/settings/billing. A plain anchor such as #pricing is still ignored, because on ordinary sites it only points to a heading. Query strings inside the route are filtered the same way as normal ones, keeping only campaign parameters such as UTM tags and ad click ids (Hash-based routes).

Router setting Needs data-hash
Vue Router createWebHashHistory() Yes
React Router createHashRouter or <HashRouter> Yes
Angular withHashLocation() or useHash: true Yes
Any router in History mode No

If you want full control, set data-auto="false" and send page views yourself with reveata('pageview'), for example for virtual pages inside a wizard.

Common mistakes

  • Double page views. Adding a manual page view call on route change while automatic tracking is on counts every screen twice.
  • Changing only the query string. In Reveata, a change of the query string alone is not a new page, which keeps filter and sort controls from inflating page views.
  • Goals before the first page view. A goal needs a visit, and only a page view starts one. With data-auto="false", send the page view first.
  • Hash routes in filters and funnels. With hash routing, include the hash in goals and filters: /#/checkout/done, not /checkout/done.

Checking it works

Open your app, click between a few routes and watch the realtime view. Each route should appear as its own page. Adding data-debug="true" to the snippet logs every page view the script sends in the browser console.

Frequently asked questions

Do server-rendered frameworks like Next.js count as SPAs?

After the first load, yes. Next.js, Nuxt and SvelteKit render the first page on the server and then navigate in the browser like an SPA, so route changes must be tracked by the script, which Reveata does automatically.

Why does my SPA show a very high bounce rate?

Usually because route changes are not being tracked, so every visit looks like a single page. Fix the tracking first; the bounce rate will correct itself for new visits.

Does SPA tracking work in mobile apps?

Mobile apps have screens rather than URLs. Reveata's React Native package records screens as pages of the app, next to your website's pages.

See it with your own numbersReveata ties every visit and sale to the source that brought it. Add your website in a minute.
Get started
Was this page useful?
GlossaryWhat is a tracking script?A tracking script is a small JavaScript file you add to every page of a website, which runs in each visitor's browser and sends page views, clicks and other actions to an analytics service.GlossaryWhat is a custom event in analytics?A custom event is an action you define and send to your analytics tool yourself, such as signup, start_trial or download_pdf, so it can be counted, compared by traffic source and used as a goal or funnel step.GlossaryWhat are Core Web Vitals?Core Web Vitals are three measurements Google uses to describe a page's real-world user experience, namely Largest Contentful Paint (loading), Interaction to Next Paint (responsiveness) and Cumulative Layout Shift (visual stability).GlossaryWhat are event properties?Event properties are key–value details attached to an analytics event, such as the plan chosen or the button clicked on a signup event, so you can break one event down by those details instead of creating a separate event for every variation.GlossaryWhat is a canonical URL?A canonical URL is the one preferred address you want search engines to index and show for a page whose content is reachable at several URLs, usually declared with a rel="canonical" link in the page's head.GlossaryWhat is a Content Security Policy (CSP)?A Content Security Policy (CSP) is a set of rules a website sends to the browser, usually in a Content-Security-Policy header, listing which sources of scripts, styles, images and network connections the page is allowed to use, so injected or unexpected code is blocked.