PageView.
Let Bily record the first page
The Bily browser script records the first page view when the document loads. This works the same whether you use the raw script or initialize Bily through@bilyai/js.
Traditional multi-page sites need no manual page-view code. Each full navigation loads a new document and records one initial event.
Record each later SPA route
Single-page applications do not load a new document for each route. After the router commits a later URL, send:sourceUrl to the complete current URL. Send the event after the page title and route state are current.
Skip the first route and repeated URLs
Save the current URL before you listen for later navigation.route-tracking.ts
onRouteCommitted() to your router’s after-navigation callback. Do not call it to initialize the listener.
Use your framework’s router
React Router
Track pathname, search, and hash changes from one component.
Next.js
Track App Router and Pages Router navigation from one shared component.
Confirm every page appears once
- The event name is exactly
PageView. - The initial document relies on the automatic event.
- Later browser routes call
track()after the route commits. sourceUrlcontainswindow.location.href.pageTitlecontains the finaldocument.title.- A rerender at the same URL does not emit another event.
Verify page views
Test direct loads, reloads, route transitions, and browser history.