Skip to main content
Bily uses the exact event name PageView.

Initial page view

The Bily browser script records the initial page view when a document loads. This applies whether you installed the raw script or initialized it through @bilyai/js.
Do not call track("PageView") during the initial page or component mount. That would duplicate the automatic event.
Traditional multi-page sites need no manual page-view code. Each full navigation loads a new document and records its own initial event.

SPA route transitions

Single-page applications do not load a new document for every route. After the router commits a later URL, send:
import { track } from "@bilyai/js";

track("PageView", {
  sourceUrl: window.location.href,
  pageTitle: document.title,
});
Use the full current URL in sourceUrl. Run the call after the page title and route state are current.

Skip the initial route and duplicates

Store the current URL before listening for later navigation.
route-tracking.ts
import { track } from "@bilyai/js";

let previousUrl = window.location.href;

export function onRouteCommitted() {
  const currentUrl = window.location.href;
  if (currentUrl === previousUrl) return;

  previousUrl = currentUrl;
  track("PageView", {
    sourceUrl: currentUrl,
    pageTitle: document.title,
  });
}
Connect onRouteCommitted() to the router’s after-navigation callback. Do not call it once just to initialize the listener.

Framework patterns

React Router

Track pathname, search, and hash changes from one mounted component.

Next.js App Router

Track pathname and search changes from one client component.

Page-view checklist

  • The event name is exactly PageView.
  • The initial document relies on the automatic event.
  • Later browser routes call track() after the route commits.
  • sourceUrl contains window.location.href.
  • pageTitle contains the final document.title.
  • A rerender at the same URL does not emit another event.

Verify page views

Test direct loads, reloads, route transitions, and browser history.