Skip to content

Single-page apps

The tracker counts navigation in single-page apps without any setup. It watches history.pushState, history.replaceState and the browser’s back and forward buttons (popstate).

A new page view is sent when the path changes:

Change New page view?
/pricing → /signup yes
/blog?page=1 → /blog?page=2 no: only the query changed
/docs → /docs#install no: only the fragment changed
replaceState to the same path no

When the path changes, the tracker first sends the previous page’s leave event (time visible and scroll depth), then the new page view. The previous page’s address is used as the new page’s referrer.

A navigation inside your app never starts a new visit, so it adds a page view but not a visitor. Only a full page load from outside your site does. See The numbers.

Custom events are tied to the page view they happen on. After a navigation, they belong to the new page view, and the limit of 100 events per page view starts again.

Add the snippet once, to the HTML page that loads your app, or to your root layout. In Next.js:

import Script from "next/script";
<Script defer src="https://c.upbeatanalytics.eu/s.js" />

Don’t add it to individual pages or components: the tracker would only start where it was added, and a second copy does nothing.