/** * Public and internal types for `@contextune/sdk`. */ /** Frozen-at-init marketing context. */ interface MarketingParamsBlock { utm_source: string | null; utm_medium: string | null; utm_campaign: string | null; utm_term: string | null; utm_content: string | null; referrer: string | null; landing_page: string | null; } /** Static device information, read at snapshot time from `navigator` + `window`. */ interface DeviceInfoBlock { user_agent: string; viewport_w: number; viewport_h: number; language: string; platform: string; device_type: 'desktop' | 'tablet' | 'mobile'; } /** * A single entry in the event log. * * `name` is the normalised event name (e.g. `'page_view'`, `'track'`). * `elapsed_s` is whole seconds since session start. */ interface EventLogEntry { name: string; elapsed_s: number; properties?: Record; } interface ContextuneSnapshot { event_log: EventLogEntry[]; marketing_params?: MarketingParamsBlock; device_info?: DeviceInfoBlock; } type SnapshotFormat = 'js' | 'json' | 'toon'; interface TrackingExtrasOptions { /** Fire a 'scroll' event each time the user crosses a 25/50/75/100% depth milestone. */ scroll?: boolean; /** Fire a 'rage_click' event when ≥3 clicks on the same target occur within a 1-second window. */ rageClicks?: boolean; } type Persistence = 'navigation' | 'ct-session'; declare const SOURCE_MAP: { readonly ga4: "googleanalytics"; readonly segment: "segment"; readonly mixpanel: "mixpanel"; }; type ContextuneSource = keyof typeof SOURCE_MAP; interface ContextuneOptions { /** Omit to use direct-call mode: only track()/page() calls are captured, * no network interception. Useful when you want Contextune itself as the * "analytics" layer. */ source?: ContextuneSource; eventLogSize?: number; /** Controls event log lifetime. 'navigation' (default): cleared on page reload. * 'ct-session': survives reloads; scoped to 30 min of inactivity via cookie. */ persistence?: Persistence; context?: { extras?: { /** Capture UTM params, referrer, and landing page. Default: true. */ marketing?: boolean; /** Capture viewport, language, platform, and device type. Default: true. */ device?: boolean; }; }; tracking?: TrackingExtrasOptions; } /** * Controls which events trigger a subscription handler. * - `'event'` — every entry added to the log * - predicate function — only entries for which the function returns `true` */ type SubscriptionFilter = 'event' | ((entry: EventLogEntry) => boolean); /** * Handler called when a matching event enters the log. * `entry` is the new event; `state` is the full snapshot captured immediately * before the entry was added (the log does not yet contain `entry`). */ type SubscriptionHandler = (entry: EventLogEntry, state: ContextuneSnapshot) => void; interface ContextuneInstance { getSnapshot(): ContextuneSnapshot; getSnapshot(options: { format: 'js'; }): ContextuneSnapshot; getSnapshot(options: { format: 'json' | 'toon'; }): string; track(name: string, properties?: Record): void; page(url?: string): void; subscribe(filter: SubscriptionFilter, handler: SubscriptionHandler): () => void; clear(): void; destroy(): void; } declare const Contextune: { init(options?: ContextuneOptions): ContextuneInstance; getSnapshot(options?: { format?: SnapshotFormat; }): ContextuneSnapshot | string | null; track(name: string, properties?: Record): void; page(url?: string): void; subscribe(filter: SubscriptionFilter, handler: SubscriptionHandler): () => void; clear(): void; destroy(): void; }; export { Contextune, type ContextuneInstance, type ContextuneOptions, type ContextuneSnapshot, type ContextuneSource, type DeviceInfoBlock, type EventLogEntry, type MarketingParamsBlock, type Persistence, type SnapshotFormat, type SubscriptionFilter, type SubscriptionHandler };