Skip to content
SegmentStream/ Docs

Loading documentation…

↑ ↓ to navigate  ↵ to open  Esc to close
Website Console
Section menu

@segmentstream/web-tracker/browser

5 public exports from @segmentstream/web-tracker/browser.

Public exports

AnonymousIdCookie

The first-party cookie that keeps the visitor's anonymous ID between page loads.

type AnonymousIdCookie = {
    name?: string;
    writer?: "site" | "tracker";
    maxAgeSeconds?: number;
    domain?: string;
};
BrowserTrackerOptions
type BrowserTrackerOptions = BaseOptions & ConsentOptions;
DEFAULT_SDK
const DEFAULT_SDK: Sdk
Page

The page a view describes. `url` also becomes the next view's referrer.

type Page = {
    url: string;
    path: string;
    title: string;
    query_raw: string;
    query_params: Record<string, string>;
    referrer: string | null;
};
createBrowserTracker

One bounded, memory-only queue. Failed and unacknowledged events are dropped, never retried. Call `pageView()` after each navigation and `flush()` periodically and with `hidden = true` when the page is hidden, which queues a beacon. Options' callbacks that throw skip the view.

function createBrowserTracker(options: BrowserTrackerOptions): {
    pageView: () => void;
    flush: (hidden?: boolean) => Promise<number>;
    consentChanged: () => void;
    anonymousId: () => string | null;
};