Tracking
SPAs and hash routing
How the tracker follows client-side navigation, hash routers, the back/forward cache and prerendered pages.
The tracker follows client-side navigation on its own. You don’t need a router listener in Next.js, React Router, TanStack Router, Vue Router, SvelteKit or Angular.
History routing
history.pushState,replaceStateandpopstateare watched. A navigation counts as a pageview after 100 ms, and a second change to the same URL is ignored.- Each pageview gets its own id. A heartbeat closes the previous view with its engaged time and scroll depth.
- The referrer is only sent with the first pageview of a page load, so internal navigation never looks like new traffic.
Hash routing
If your app routes with the URL fragment (/#/settings), add data-hash. Hash changes become pageviews and the route is kept in the path: /#/users/42 is reported as /users/42. Without data-hash the fragment is dropped, because it can carry tokens (OAuth, magic links), and plain anchors like #pricing never change the page.
<script defer data-site="SITE_ID" data-hash src="…/script.js"></script>Manual pageviews
To send pageviews yourself (virtual pages, multi-step modals), turn automatic ones off with data-auto="false":
globatics('pageview'); // current URL
globatics('pageview', '/checkout/step-2'); // a virtual pageBack/forward cache and prerendering
- A page restored from the back/forward cache counts as a new pageview, and Web Vitals are measured again.
- A prerendered page (Speculation Rules) is only counted when the visitor actually sees it.
- A hidden tab sends
leave, so the visitor drops off the globe. They come back the moment the tab is visible again.
Testing locally? Keep the tracked page visible next to the live view: switching tabs is a real “leave”.