Skip to content
Blog

Pageview Tracking

Pageview tracking starts the moment the SDK loads and works equally well for traditional multi-page sites and single-page applications with client-side routing. There’s nothing to wire up yourself.

With autoTrack enabled (the default), the SDK follows a straightforward sequence:

  1. Tracks the initial page load by recording the URL and page title
  2. Hooks into history.pushState to catch SPA navigation from frameworks like React Router, Vue Router, and Next.js
  3. Listens for popstate to handle browser back and forward buttons
  4. Records time on page by watching visibilitychange, logging how long the user spent before navigating away

Events are dispatched using navigator.sendBeacon with a fetch fallback, so they’re reliably delivered even when the page is closing.

Auto-tracking is on by default. Turn it off if you prefer manual control:

import { Tribe } from "@tribecloud/sdk";
const tribe = new Tribe({ siteId: "YOUR_SITE_ID", autoTrack: false });

When you load the SDK via a script tag, auto-tracking is always active and can’t be disabled.

Every pageview event carries a handful of useful details:

  • URL is the page path the visitor is on
  • Page title comes from document.title
  • Referrer indicates where the visitor arrived from
  • Duration captures time spent on the previous page, sent when the visitor navigates
  • Device info includes browser, OS, and device type, all parsed from the user agent string
  • Country is derived from the visitor’s IP address, which itself is never stored

There’s nothing special to configure. The SDK picks up client-side navigation from React Router, Vue Router, Next.js, and SvelteKit automatically. Each route change fires a pageview event as you’d expect.

When no user is logged in, the SDK generates an anonymous ID and stores it in localStorage under the key __tribe_anon_{siteId}. This ID accompanies every event so unique visitors can be counted without relying on cookies or collecting personal data.

Once a user logs in, their events become associated with their actual account instead of the anonymous ID.