/** * Available tracking consent states. * * Use these constants to manage user consent for tracking and analytics. * * @property GRANTED User has granted consent for tracking * @property DENIED User has denied consent for tracking * @property PENDING User hasn't made a decision yet * @property DISMISSED User dismissed the consent prompt * * @example * ```javascript * import { altertable, TrackingConsent } from '@altertable/altertable-js'; * * // Set tracking consent to granted * altertable.configure({ * trackingConsent: TrackingConsent.GRANTED, * }); * * // Check current consent state * const consent = altertable.getTrackingConsent(); * if (consent === TrackingConsent.GRANTED) { * // Tracking is allowed * } * ``` */ declare const TrackingConsent: { readonly DENIED: "denied"; readonly DISMISSED: "dismissed"; readonly GRANTED: "granted"; readonly PENDING: "pending"; }; type TrackingConsentType = (typeof TrackingConsent)[keyof typeof TrackingConsent]; type StorageType = 'localStorage' | 'sessionStorage' | 'cookie' | 'memory' | 'localStorage+cookie'; type StringWithAutocomplete = T | (string & {}); type EventProperties = Record; type UserId = string; type DistinctId = StringWithAutocomplete; type AnonymousId = `anonymous-${string}`; type Environment = StringWithAutocomplete<'production' | 'development' | 'staging'>; interface UserTraits extends Record { email?: string; } interface AltertableConfig { /** * The base URL of the Altertable API. * @default https://api.altertable.ai */ baseUrl?: string; /** * The environment of the application. * @default "production" */ environment?: Environment; /** * Whether to automatically capture page views and events. * @default true */ autoCapture?: boolean; /** * The release ID of the application. * This is helpful to identify the version of the application an event is coming from. */ release?: string; /** * Whether to log events to the console. * @default false */ debug?: boolean; /** * The persistence strategy for storing IDs. * @default "localStorage+cookie" */ persistence?: StorageType; /** * The tracking consent state. * @default "granted" */ trackingConsent?: TrackingConsentType; /** * Optional error handler for intercepting SDK errors. */ onError?: (error: Error) => void; } declare class Altertable { private _cleanupAutoCapture; private _config; private _queue; private _isInitialized; private _lastUrl; private _logger; private _referrer; private _requester; private _sessionManager; private _storage; private _storageKey; constructor(); /** * Initializes the Altertable SDK with your API key and optional configuration. * * @param apiKey Your Altertable API key * @param config Configuration options * @returns A cleanup function to remove event listeners * * @example * ```javascript * altertable.init('YOUR_API_KEY', { * environment: 'development', * }); * ``` */ init(apiKey: string, config?: AltertableConfig): () => void; /** * Updates the configuration after initialization. * * @param updates Configuration updates to apply * * @example * ```javascript * altertable.configure({ * trackingConsent: 'granted', * }); * ``` */ configure(updates: Partial): void; private _handleAutoCaptureChange; /** * Identifies a user with their ID and optional traits. * * Notes: * - You can call this method multiple times with the same ID. * - To change traits, use {@link updateTraits} instead. * - To switch to a new user ID, call {@link reset} first. * * @param userId The user's unique identifier * @param traits User properties * * @example * ```javascript * altertable.identify('u_01jza857w4f23s1hf2s61befmw', { * email: 'john.doe@example.com', * name: 'John Doe', * company: 'Acme Corp', * role: 'Software Engineer', * }); * ``` */ identify(userId: DistinctId, traits?: UserTraits): void; private _identify; /** * Link a new ID to the current identity. * * @param newUserId The new user ID * * @example * ```javascript * altertable.alias('u_01jza857w4f23s1hf2s61befmw'); * ``` */ alias(newUserId: DistinctId): void; private _alias; /** * Updates user traits for the current user. * * @param traits User properties to update * * @example * ```javascript * altertable.updateTraits({ * onboarding_completed: true, * }); * ``` */ updateTraits(traits: UserTraits): void; private _updateTraits; /** * Resets device and session IDs. * * @example * ```javascript * // Reset session, user and visitor (default) * altertable.reset(); * * // Reset session, user, visitor and device * altertable.reset({ * resetDeviceId: true, * }); * ``` */ reset({ resetDeviceId, }?: { /** Whether to reset device ID (default: false) */ resetDeviceId?: boolean; }): void; /** * Tracks a page view event. * * When `autoCapture` is enabled (default), this method is automatically called when the page URL changes. * * @param url The page URL * * @example * ```javascript * altertable.page('https://example.com/products'); * ``` * * @remarks * **Page Tracking**: By default, Altertable automatically captures page views. Only use `page()` when you've disabled auto-capture. * * **Why use auto-capture (default)?** * - No manual tracking required * - Handles browser navigation events (popstate, hashchange) * - Consistent tracking across all page changes * * **When to use `page()`:** * - Custom routing that doesn't trigger browser events * - Virtual page views that don't trigger URL changes (modals, step changes) * - Server-side tracking where auto-capture isn't available */ page(url: string): void; private _page; /** * Tracks a custom event with optional properties. * * @param eventThe event name * @param properties Custom event properties * * @example * ```javascript * altertable.track('Purchase Completed', { * product_id: 'p_01jza8fr5efvgbxxdd1bwkd0m5', * amount: 29.99, * currency: 'USD', * }); * ``` */ track(event: string, properties?: EventProperties): void; private _track; /** * Returns the current tracking consent state. * * @returns The current tracking consent state * @see {@link TrackingConsent} * * @example * ```javascript * const consent = altertable.getTrackingConsent(); * if (consent === 'granted') { * // Tracking is allowed * } * ``` */ getTrackingConsent(): TrackingConsentType; private _flushQueue; private _executeQueueItem; private _executeCommand; private _checkForChanges; private _getContext; private _processEvent; private _sendEvent; } declare global { interface Window { Altertable: Altertable | Array> | undefined; } } declare const altertable: Altertable; export { Altertable, type AltertableConfig, TrackingConsent, altertable };