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.
How it works
Section titled “How it works”With autoTrack enabled (the default), the SDK follows a straightforward sequence:
- Tracks the initial page load by recording the URL and page title
- Hooks into
history.pushStateto catch SPA navigation from frameworks like React Router, Vue Router, and Next.js - Listens for
popstateto handle browser back and forward buttons - 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.
Enable / disable
Section titled “Enable / disable”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.
What gets tracked
Section titled “What gets tracked”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
SPA support
Section titled “SPA support”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.
Anonymous visitors
Section titled “Anonymous visitors”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.