snowplow/snowplow-javascript-tracker

View on GitHub
api-docs/docs/browser-tracker/browser-tracker.api.md

Summary

Maintainability
Test Coverage
## API Report File for "@snowplow/browser-tracker"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

// @public
export type ActivityCallback = (data: ActivityCallbackData) => void;

// @public
export type ActivityCallbackData = {
    context: Array<SelfDescribingJson>;
    pageViewId: string;
    minXOffset: number;
    minYOffset: number;
    maxXOffset: number;
    maxYOffset: number;
};

// @public
export interface ActivityTrackingConfiguration {
    heartbeatDelay: number;
    minimumVisitLength: number;
}

// @public
export interface ActivityTrackingConfigurationCallback {
    callback: ActivityCallback;
}

// @public
export function addGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive> | Record<string, ConditionalContextProvider | ContextPrimitive>, trackers?: Array<string>): void;

// @public
export function addPlugin(configuration: BrowserPluginConfiguration, trackers?: Array<string>): void;

// @public (undocumented)
export type AnonymousTrackingOptions = boolean | {
    withSessionTracking?: boolean;
    withServerAnonymisation?: boolean;
};

// @public
export interface BrowserPlugin extends CorePlugin {
    activateBrowserPlugin?: (tracker: BrowserTracker) => void;
}

// @public
export interface BrowserPluginConfiguration extends CorePluginConfiguration {
    /* The plugin to add */
    // (undocumented)
    plugin: BrowserPlugin;
}

// @public
export interface BrowserTracker {
    addPlugin: (configuration: BrowserPluginConfiguration) => void;
    clearUserData: (configuration?: ClearUserDataConfiguration) => void;
    core: TrackerCore;
    crossDomainLinker: (crossDomainLinkerCriterion: (elt: HTMLAnchorElement | HTMLAreaElement) => boolean) => void;
    disableActivityTracking: () => void;
    disableActivityTrackingCallback: () => void;
    disableAnonymousTracking: (configuration?: DisableAnonymousTrackingConfiguration) => void;
    discardBrace: (enableFilter: boolean) => void;
    discardHashTag: (enableFilter: boolean) => void;
    enableActivityTracking: (configuration: ActivityTrackingConfiguration) => void;
    enableActivityTrackingCallback: (configuration: ActivityTrackingConfiguration & ActivityTrackingConfigurationCallback) => void;
    enableAnonymousTracking: (configuration?: EnableAnonymousTrackingConfiguration) => void;
    flushBuffer: (configuration?: FlushBufferConfiguration) => void;
    getCookieName: (basename: string) => string;
    getDomainSessionIndex: () => number;
    getDomainUserId: () => string;
    getDomainUserInfo: () => ParsedIdCookie;
    getPageViewId: () => string;
    getTabId: () => string | null;
    getUserId: () => string | null | undefined;
    id: string;
    namespace: string;
    newSession: () => void;
    preservePageViewId: () => void;
    preservePageViewIdForUrl: (preserve: PreservePageViewIdForUrl) => void;
    setBufferSize: (newBufferSize: number) => void;
    setCollectorUrl: (collectorUrl: string) => void;
    setCookiePath: (path: string) => void;
    setCustomUrl: (url: string) => void;
    setDocumentTitle: (title: string) => void;
    setOptOutCookie: (name?: string | null) => void;
    setReferrerUrl: (url: string) => void;
    setUserId: (userId?: string | null) => void;
    setUserIdFromCookie: (cookieName: string) => void;
    setUserIdFromLocation: (querystringField: string) => void;
    setUserIdFromReferrer: (querystringField: string) => void;
    setVisitorCookieTimeout: (timeout: number) => void;
    sharedState: SharedState;
    trackPageView: (event?: PageViewEvent & CommonEventProperties) => void;
    updatePageActivity: () => void;
}

// Warning: (ae-forgotten-export) The symbol "RequireAtLeastOne" needs to be exported by the entry point index.module.d.ts
//
// @public (undocumented)
export type BuiltInContexts = RequireAtLeastOne<{
    /* Toggles the web_page context */
    webPage: boolean;
    /* Toggles the session context */
    session: boolean;
    /* Toggles the browser context */
    browser: boolean;
}> | Record<string, never>;

// @public
export function clearGlobalContexts(trackers?: Array<string>): void;

// @public
export function clearUserData(configuration?: ClearUserDataConfiguration, trackers?: Array<string>): void;

// @public
export interface ClearUserDataConfiguration {
    /* Store session information in memory for subsequent events */
    // (undocumented)
    preserveSession: boolean;
    /* Store user information in memory for subsequent events */
    // (undocumented)
    preserveUser: boolean;
}

// @public
export interface ClientSession extends Record<string, unknown> {
    eventIndex: number;
    firstEventId: string | null;
    firstEventTimestamp: string | null;
    previousSessionId: string | null;
    sessionId: string;
    sessionIndex: number;
    storageMechanism: string;
    userId: string;
}

// @public
export interface CommonEventProperties<T = Record<string, unknown>> {
    context?: Array<SelfDescribingJson<T>> | null;
    timestamp?: Timestamp | null;
}

// @public
export type ConditionalContextProvider = FilterProvider | RuleSetProvider;

// @public
export interface ContextEvent {
    event: Payload;
    eventSchema: string;
    eventType: string;
}

// @public
export type ContextFilter = (args?: ContextEvent) => boolean;

// @public
export type ContextGenerator = (args?: ContextEvent) => SelfDescribingJson | SelfDescribingJson[] | undefined;

// @public
export type ContextPrimitive = SelfDescribingJson | ContextGenerator;

// @public (undocumented)
export type CookieSameSite = "None" | "Lax" | "Strict";

// @public
export interface CorePlugin {
    activateCorePlugin?: (core: TrackerCore) => void;
    afterTrack?: (payload: Payload) => void;
    beforeTrack?: (payloadBuilder: PayloadBuilder) => void;
    contexts?: () => SelfDescribingJson[];
    filter?: (payload: Payload) => boolean;
    logger?: (logger: Logger) => void;
}

// @public
export interface CorePluginConfiguration {
    /* The plugin to add */
    // (undocumented)
    plugin: CorePlugin;
}

// @public
export function crossDomainLinker(crossDomainLinkerCriterion: (elt: HTMLAnchorElement | HTMLAreaElement) => boolean, trackers?: Array<string>): void;

// @public
export interface DeviceTimestamp {
    // (undocumented)
    readonly type: "dtm";
    // (undocumented)
    readonly value: number;
}

// @public
export function disableActivityTracking(trackers?: Array<string>): void;

// @public
export function disableActivityTrackingCallback(trackers?: Array<string>): void;

// @public
export function disableAnonymousTracking(configuration?: DisableAnonymousTrackingConfiguration, trackers?: Array<string>): void;

// @public
export interface DisableAnonymousTrackingConfiguration {
    /* Available configurations for different storage strategies */
    // (undocumented)
    stateStorageStrategy?: StateStorageStrategy;
}

// @public
export function discardBrace(enable: boolean, trackers?: Array<string>): void;

// @public
export function discardHashTag(enable: boolean, trackers?: Array<string>): void;

// @public (undocumented)
export interface EmitterConfigurationBase {
    bufferSize?: number;
    connectionTimeout?: number;
    credentials?: "omit" | "same-origin" | "include";
    customFetch?: (input: Request, options?: RequestInit) => Promise<Response>;
    customHeaders?: Record<string, string>;
    dontRetryStatusCodes?: number[];
    eventMethod?: EventMethod;
    eventStore?: EventStore;
    idService?: string;
    keepalive?: boolean;
    maxGetBytes?: number;
    maxPostBytes?: number;
    onRequestFailure?: (data: RequestFailure, response?: Response) => void;
    onRequestSuccess?: (data: EventBatch, response: Response) => void;
    postPath?: string;
    retryFailedRequests?: boolean;
    retryStatusCodes?: number[];
    useStm?: boolean;
}

// @public
export function enableActivityTracking(configuration: ActivityTrackingConfiguration, trackers?: Array<string>): void;

// @public
export function enableActivityTrackingCallback(configuration: ActivityTrackingConfiguration & ActivityTrackingConfigurationCallback, trackers?: Array<string>): void;

// @public
export function enableAnonymousTracking(configuration?: EnableAnonymousTrackingConfiguration, trackers?: Array<string>): void;

// @public
export interface EnableAnonymousTrackingConfiguration {
    /* Configuration for Anonymous Tracking */
    // (undocumented)
    options?: AnonymousTrackingOptions;
    /* Available configurations for different storage strategies */
    // (undocumented)
    stateStorageStrategy?: StateStorageStrategy;
}

// @public
export type EventBatch = Payload[];

// Warning: (ae-forgotten-export) The symbol "EventJsonWithKeys" needs to be exported by the entry point index.module.d.ts
//
// @public
export type EventJson = Array<EventJsonWithKeys>;

// @public (undocumented)
export type EventMethod = "post" | "get";

// @public
export interface EventPayloadAndContext {
    context: Array<SelfDescribingJson>;
    event: PayloadBuilder;
}

// @public
export interface EventStore {
    add: (payload: EventStorePayload) => Promise<number>;
    count: () => Promise<number>;
    getAll: () => Promise<readonly EventStorePayload[]>;
    getAllPayloads: () => Promise<readonly Payload[]>;
    iterator: () => EventStoreIterator;
    removeHead: (count: number) => Promise<void>;
}

// @public (undocumented)
export interface EventStoreConfiguration {
    maxSize?: number;
}

// @public (undocumented)
export interface EventStoreIterator {
    next: () => Promise<{
        value: EventStorePayload | undefined;
        done: boolean;
    }>;
}

// @public (undocumented)
export interface EventStorePayload {
    payload: Payload;
    svrAnon?: boolean;
}

// @public (undocumented)
export type ExtendedCrossDomainLinkerAttributes = {
    userId?: boolean;
    sessionId?: boolean;
    sourceId?: boolean;
    sourcePlatform?: boolean;
    reason?: boolean | ((evt: Event) => string);
};

// @public (undocumented)
export type ExtendedCrossDomainLinkerOptions = boolean | ExtendedCrossDomainLinkerAttributes;

// @public
export type FilterProvider = [
ContextFilter,
Array<ContextPrimitive> | ContextPrimitive
];

// @public
export function flushBuffer(configuration?: FlushBufferConfiguration, trackers?: Array<string>): void;

// @public
export interface FlushBufferConfiguration {
    /* The size of the buffer after this flush */
    // (undocumented)
    newBufferSize?: number;
}

// @public
export type JsonProcessor = (payloadBuilder: PayloadBuilder, jsonForProcessing: EventJson, contextEntitiesForProcessing: SelfDescribingJson[]) => void;

// @public (undocumented)
export interface LocalStorageEventStoreConfigurationBase extends EventStoreConfiguration {
    maxLocalStorageQueueSize?: number;
    useLocalStorage?: boolean;
}

// @public (undocumented)
export interface Logger {
    // (undocumented)
    debug: (message: string, ...extraParams: unknown[]) => void;
    // (undocumented)
    error: (message: string, error?: unknown, ...extraParams: unknown[]) => void;
    // (undocumented)
    info: (message: string, ...extraParams: unknown[]) => void;
    // Warning: (ae-forgotten-export) The symbol "LOG_LEVEL" needs to be exported by the entry point index.module.d.ts
    //
    // (undocumented)
    setLogLevel: (level: LOG_LEVEL) => void;
    // (undocumented)
    warn: (message: string, error?: unknown, ...extraParams: unknown[]) => void;
}

// @public
export function newSession(trackers?: Array<string>): void;

// @public
export function newTracker(trackerId: string, endpoint: string, configuration?: TrackerConfiguration): BrowserTracker | null | undefined;

// @public
export interface PageViewEvent {
    contextCallback?: (() => Array<SelfDescribingJson>) | null;
    title?: string | null;
}

// @public
export type ParsedIdCookie = [
cookieDisabled: string,
domainUserId: string,
cookieCreateTs: number,
visitCount: number,
nowTs: number,
lastVisitTs: number | undefined,
sessionId: string,
previousSessionId: string,
firstEventId: string,
firstEventTs: number | undefined,
eventIndex: number
];

// @public
export type Payload = Record<string, unknown>;

// @public
export interface PayloadBuilder {
    add: (key: string, value: unknown) => void;
    addContextEntity: (entity: SelfDescribingJson) => void;
    addDict: (dict: Payload) => void;
    addJson: (keyIfEncoded: string, keyIfNotEncoded: string, json: Record<string, unknown>) => void;
    build: () => Payload;
    getJson: () => EventJson;
    getPayload: () => Payload;
    withJsonProcessor: (jsonProcessor: JsonProcessor) => void;
}

// @public (undocumented)
export type Platform = "web" | "mob" | "pc" | "srv" | "app" | "tv" | "cnsl" | "iot";

// @public
export function preservePageViewId(trackers?: Array<string>): void;

// @public (undocumented)
export type PreservePageViewIdForUrl = boolean | "full" | "pathname" | "pathnameAndSearch";

// @public
export function removeGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive | string>, trackers?: Array<string>): void;

// @public
export type RequestFailure = {
    events: EventBatch;
    status?: number;
    message?: string;
    willRetry: boolean;
};

// @public
export interface RuleSet {
    // (undocumented)
    accept?: Array<string> | string;
    // (undocumented)
    reject?: Array<string> | string;
}

// @public
export type RuleSetProvider = [
RuleSet,
Array<ContextPrimitive> | ContextPrimitive
];

// @public
export interface SelfDescribingEvent<T = Record<string, unknown>> {
    event: SelfDescribingJson<T>;
}

// @public
export type SelfDescribingJson<T = Record<string, unknown>> = {
    schema: string;
    data: T extends any[] ? never : T extends {} ? T : never;
};

// @public
export function setBufferSize(newBufferSize: number, trackers?: Array<string>): void;

// @public
export function setCollectorUrl(collectorUrl: string, trackers?: Array<string>): void;

// @public
export function setCookiePath(path: string, trackers?: Array<string>): void;

// @public
export function setCustomUrl(url: string, trackers?: Array<string>): void;

// @public
export function setDocumentTitle(title: string, trackers?: Array<string>): void;

// @public
export function setOptOutCookie(name?: string | null, trackers?: Array<string>): void;

// @public
export function setReferrerUrl(url: string, trackers?: Array<string>): void;

// @public
export function setUserId(userId?: string | null, trackers?: Array<string>): void;

// @public
export function setUserIdFromCookie(cookieName: string, trackers?: Array<string>): void;

// @public
export function setUserIdFromLocation(querystringField: string, trackers?: Array<string>): void;

// @public
export function setUserIdFromReferrer(querystringField: string, trackers?: Array<string>): void;

// @public
export function setVisitorCookieTimeout(timeout: number, trackers?: Array<string>): void;

// @public
export class SharedState {
    // (undocumented)
    bufferFlushers: Array<(sync: boolean) => void>;
    /* DOM Ready */
    // (undocumented)
    hasLoaded: boolean;
    /* DOM Ready */
    // (undocumented)
    pageViewId?: string;
    /* DOM Ready */
    // (undocumented)
    pageViewUrl?: string;
    /* DOM Ready */
    // (undocumented)
    registeredOnLoadHandlers: Array<() => void>;
}

// @public (undocumented)
export type StateStorageStrategy = "cookieAndLocalStorage" | "cookie" | "localStorage" | "none";

// @public
export interface StructuredEvent {
    // (undocumented)
    action: string;
    // (undocumented)
    category: string;
    // (undocumented)
    label?: string;
    // (undocumented)
    property?: string;
    // (undocumented)
    value?: number;
}

// @public
export type Timestamp = TrueTimestamp | DeviceTimestamp | number;

// @public
export type TrackerConfiguration = {
    encodeBase64?: boolean;
    cookieDomain?: string;
    cookieName?: string;
    cookieSameSite?: CookieSameSite;
    cookieSecure?: boolean;
    cookieLifetime?: number;
    sessionCookieTimeout?: number;
    appId?: string;
    platform?: Platform;
    respectDoNotTrack?: boolean;
    crossDomainLinker?: (elt: HTMLAnchorElement | HTMLAreaElement) => boolean;
    useExtendedCrossDomainLinker?: ExtendedCrossDomainLinkerOptions;
    discoverRootDomain?: boolean;
    stateStorageStrategy?: StateStorageStrategy;
    resetActivityTrackingOnPageView?: boolean;
    anonymousTracking?: AnonymousTrackingOptions;
    contexts?: BuiltInContexts;
    plugins?: Array<BrowserPlugin>;
    onSessionUpdateCallback?: (updatedSession: ClientSession) => void;
    preservePageViewIdForUrl?: PreservePageViewIdForUrl;
    synchronousCookieWrite?: boolean;
} & EmitterConfigurationBase & LocalStorageEventStoreConfigurationBase;

// @public
export interface TrackerCore {
    addGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive> | Record<string, ConditionalContextProvider | ContextPrimitive>): void;
    addPayloadDict(dict: Payload): void;
    addPayloadPair: (key: string, value: unknown) => void;
    addPlugin(configuration: CorePluginConfiguration): void;
    clearGlobalContexts(): void;
    getBase64Encoding(): boolean;
    removeGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive | string>): void;
    resetPayloadPairs(dict: Payload): void;
    setAppId(appId: string): void;
    setBase64Encoding(encode: boolean): void;
    setColorDepth(depth: string): void;
    setIpAddress(ip: string): void;
    setLang(lang: string): void;
    setPlatform(value: string): void;
    setScreenResolution(width: string, height: string): void;
    setTimezone(timezone: string): void;
    setTrackerNamespace(name: string): void;
    setTrackerVersion(version: string): void;
    setUseragent(useragent: string): void;
    setUserId(userId: string): void;
    setViewport(width: string, height: string): void;
    track: (pb: PayloadBuilder, context?: Array<SelfDescribingJson> | null, timestamp?: Timestamp | null) => Payload | undefined;
}

// @public
export function trackPageView(event?: PageViewEvent & CommonEventProperties, trackers?: Array<string>): void;

// @public
export function trackSelfDescribingEvent<T = Record<string, unknown>>(event: SelfDescribingEvent<T> & CommonEventProperties, trackers?: Array<string>): void;

// @public
export function trackStructEvent(event: StructuredEvent & CommonEventProperties, trackers?: Array<string>): void;

// @public
export interface TrueTimestamp {
    // (undocumented)
    readonly type: "ttm";
    // (undocumented)
    readonly value: number;
}

// @public
export function updatePageActivity(trackers?: Array<string>): void;

// @public (undocumented)
export const version: string;

// (No @packageDocumentation comment for this package)

```