Installation & setup

Single-page applications

SPAs load one HTML page and swap views in JavaScript, so “pageviews” need a little care. BobRay handles the common cases automatically and gives you one function for everything else.

7 min read Updated June 2026 Installation & setup
<script defer src="cdn.bobray.com/b.js">

Automatic mode (default)

The snippet listens to the History API, pushState, replaceState, and popstate, and records a pageview on every URL change. For React Router, Vue Router, SvelteKit, and Next.js App Router this simply works with no extra code.

Manual mode

Set data-spa="off" on the snippet and call the tracker yourself wherever your router confirms a navigation:

window.bobray('pageview')

Manual mode is the right choice when you have redirects or guards that briefly touch URLs you do not want counted.

Hash routing

Apps routed as example.com/#/settings should add data-hash="on"; hash changes then count as pageviews with the hash path recorded.

Gotchas worth knowing

Common pitfalls

The mistakes we see most often on this topic, so you can skip them entirely.

Quick reference

Auto modepushState/replaceState/popstate
Manual callwindow.bobray('pageview')
Hash appsdata-hash="on"
Query-only changeNot counted by default
Did this solve it? If not, write to support with your site ID, a real person replies within one business day.