/** * VTilt SDK - Main Entry Point * * Privacy-first analytics SDK with modular architecture. * This file is a thin orchestrator that delegates to specialized managers: * * - ConfigManager: Configuration management * - SessionManager: Session and window ID management * - UserManager: User identity and properties * - CaptureManager: Event capture and payload enrichment * - IdentityManager: High-level identity operations * - RemoteConfigManager: Remote configuration from /decide * - FeatureManager: Feature lifecycle management (descriptors, initAll, notifyAll) * * @see docs/patterns/tracker-feature-lifecycle.md */ import { VTiltConfig, EventPayload, TrackingEvent, RemoteConfig } from "./types"; import { SessionManager } from "./session"; import { UserManager } from "./user-manager"; import { Autocapture } from "./autocapture"; import { GoogleTagGateway } from "./extensions/google-tag-gateway"; import { VtdOverlay } from "./extensions/vtd-overlay"; import { type QueuedRequest } from "./request-queue"; import { RateLimiter } from "./rate-limiter"; import { SimpleEventEmitter, type EventListener, type Unsubscribe } from "./utils/event-emitter"; import { ConsentManager, FeatureManager } from "./core"; import type { ConsentState } from "./core"; import { type SendChatMessageContent, type SendChatMessageOptions } from "./utils/globals"; export declare class VTilt { readonly version: string; __loaded: boolean; private configManager; sessionManager: SessionManager; userManager: UserManager; private _captureManager; private _identityManager; private _remoteConfigManager; consentManager: ConsentManager; _featureManager: FeatureManager; vtdOverlay?: VtdOverlay; private _eventBuffer; private requestQueue; private retryQueue; rateLimiter: RateLimiter; _emitter: SimpleEventEmitter; private _has_warned_about_config; private static readonly BOOT_GATED_METHODS; private _booted; private _pendingCalls; private _postBootInitDone; constructor(config?: Partial); /** * Register all features with their descriptors. * Descriptors tell FeatureManager and RemoteConfigManager how each feature works. */ private _registerFeatures; private _installBootGate; _boot(): void; init(token: string, config?: Partial, name?: string): VTilt; private _init; /** * Substantive init work that requires both init() config AND a booted * browser environment. Runs exactly once. * * Init order: hydrate storage -> initAll features -> load remote config * Features must exist before remote config loads so cached/fresh config * can trigger onConfigUpdate on already-initialized features. */ private _runPostBootInit; /** * Grant all consent categories by default when `require_consent` is not * enabled and the visitor has no explicit consent cookie. Deferred until * privacy is resolved so remote `require_consent: true` can still gate. */ private _applyDefaultConsentIfAllowed; startAutocapture(): void; stopAutocapture(): void; isAutocaptureActive(): boolean; /** * Returns a structured snapshot of the autocapture state — useful for * debugging "no `$autocapture` events" complaints. Returns `null` if the * Autocapture feature has not been registered (e.g. before init). */ getAutocaptureDiagnostics(): ReturnType | null; startSessionRecording(): void; stopSessionRecording(): void; isRecordingActive(): boolean; getSessionRecordingId(): string | null; /** * Keep recording aligned with analytics `$pageview`. On pathname change the * recorder takes a FullSnapshot (Meta+FS page boundary) in addition to * updating flush-time `$current_url`. */ notifyRecordingPageUrl(href: string): void; openChat(): void; closeChat(): void; toggleChat(): void; showChat(): void; hideChat(): void; /** * Send a chat message. By default uses the active conversation; pass options to * start a new conversation, target a channel, or open the widget panel. */ sendChatMessage(content: SendChatMessageContent, options?: SendChatMessageOptions): Promise; /** * Raw `gtag(...)` passthrough. Queues calls made before the feature is * enabled or before `gtag.js` has loaded, flushed FIFO once ready. Safe * to call at any time, including before `vt.init()`. * * @example * vt.gtag('event', 'sign_up', { method: 'email' }) */ gtag(...args: unknown[]): void; /** * Set Enhanced Conversions user identifiers. Values are normalized and * SHA-256 hashed in the browser before being forwarded to gtag. */ setGoogleUserData(data: Parameters[0]): Promise; get featureManager(): FeatureManager; on(event: string, listener: EventListener): Unsubscribe; once(event: string, listener: EventListener): Unsubscribe; /** Removes all listeners for `event` (same semantics as internal emitter). */ off(event: string): void; /** * Whether this browser session looks like a bot/crawler (PostHog parity). * When true and bot filtering is enabled, `capture()` is a no-op. */ _is_bot(): boolean; capture(name: string, payload: EventPayload, options?: { skip_client_rate_limiting?: boolean; skip_engagement?: boolean; }): void; /** Emit $pageleave for the current page when enabled (SPA transitions, lifecycle hooks). */ tryCapturePageleave(reason: string): void; identify(newDistinctId?: string, userPropertiesToSet?: Record, userPropertiesToSetOnce?: Record): void; setUserProperties(userPropertiesToSet?: Record, userPropertiesToSetOnce?: Record): void; resetUser(reset_device_id?: boolean): void; alias(alias: string, original?: string): void; setConsent(consent: ConsentState): void; getConsent(): ConsentState; getUserIdentity(): Record; getDeviceId(): string; getUserState(): "anonymous" | "identified"; getConfig(): VTiltConfig; getRemoteConfig(): RemoteConfig | null; getSessionId(): string | null; getDistinctId(): string; getAnonymousId(): string; toString(): string; /** * Merge a partial config patch into the live SDK config and notify all features. * Use for any post-`init()` change (autocapture, `chat`, persistence, etc.). * Top-level keys shallow-merge; nested `chat` deep-merges. */ updateConfig(config: Partial): void; buildUrl(): string; buildEndpointUrl(path: string): string; sendRequest(url: string, event: TrackingEvent): void; /** * Route a captured event through the EventBuffer. * $snapshot and $snapshot_items bypass the buffer (they have identity from * UserManager and don't need config filtering). */ bufferEvent(name: string, url: string, event: TrackingEvent): void; private _is_configured; private _send_batched_request; private _send_http_request; private _send_beacon_request; _send_retriable_request(item: QueuedRequest): void; private _setup_unload_handler; private _start_queue_if_opted_in; private _read_vt_param_from_url; private _initVtdOverlay; _execute_array(array: any[]): void; _dom_loaded(): void; } export declare function init_as_module(): VTilt; export declare function init_from_snippet(): void;