@segmentstream/web-tracker/server
8 public exports from @segmentstream/web-tracker/server.
Public exports
RequestEventOptions
type RequestEventOptions = {
eventType: string;
anonymousId: string | null;
sdk: Sdk;
consent?: Consent;
page?: boolean;
fields?: Record<string, unknown> & {
request?: Record<string, unknown>;
};
};SendOptions
type SendOptions = {
endpoint: string;
writeKey: string;
userAgent?: string;
timeoutMs?: number;
};isDocumentRequest
Whether a request loads a document: a GET that is not a Next.js RSC fetch, router prefetch or speculative prefetch, and asks for HTML or anything. Only these become `http_request` events.
function isDocumentRequest(request: Request): boolean;
requestAnonymousId
The visitor's anonymous ID from the request's cookie, when it is a UUID.
function requestAnonymousId(request: Request, cookie?: string): string | null;
requestEvent
A server event about the visitor's request, carrying its `payload.visitor` snapshot.
function requestEvent(request: Request, options: RequestEventOptions): WebEvent;
requestUrl
The requested URL. Next can normalize the internal URL to localhost; use Host, never forwarded-host.
function requestUrl(request: Request): URL;
sendEvents
Best effort, never throws and never retries. Callers keep this work off the response path.
function sendEvents(events: WebEvent[], options: SendOptions): Promise<void>;
visitorSnapshot
Explicit observations of the visitor's request as Vercel delivers it, for `payload.visitor`. Never forwards arbitrary headers or credentials. The collector keeps it only from write-key senders.
function visitorSnapshot(headers: Headers): {
source: string;
request_id: string | null;
ip: string | null;
continent: string | null;
country: string | null;
country_region: string | null;
city: string | null;
latitude: string | null;
longitude: string | null;
timezone: string | null;
postal_code: string | null;
ja4: string | null;
ja3: string | null;
user_agent: string | null;
accept: string | null;
accept_language: string | null;
referer: string | null;
sec_ch_ua: string | null;
sec_ch_ua_mobile: string | null;
sec_ch_ua_platform: string | null;
sec_ch_ua_full_version_list: string | null;
signature_agent: string | null;
signature_input: string | null;
signature: string | null;
from: string | null;
purpose: string | null;
sec_purpose: string | null;
sec_fetch_dest: string | null;
sec_fetch_mode: string | null;
sec_fetch_site: string | null;
sec_fetch_user: string | null;
};