UNPKG

@trlogic/tracker-web

Version:
76 lines (75 loc) 3.04 kB
import { NativeEventListener } from "./api/NativeEventListener"; import { EventCallback } from "./core/contract/EventCallback"; import { InitializationCallback } from "./core/contract/InitializationCallback"; import { TrackerConfig } from "./core/model/TrackerConfig"; import { TrackerConfiguration } from "./core/model/TrackerConfiguration"; import { TrackerEventType } from "./core/model/TrackerEventType"; import { TrackerVariableType } from "./core/model/TrackerVariableType"; /** * Main entry point for the Tracker Web SDK. * Mirrors Android TrackerSDK — Builder pattern, instance-based API. * * @example * ```ts * const tracker = new TrackerSDK.Builder() * .setConfiguration({ * tenant: 'my-tenant', * apiUrl: 'https://api.example.com', * apiKey: 'my-api-key', * }) * .build(); * * tracker.initialize({ * onComplete(success, message) { * if (success) console.log('SDK initialized'); * }, * }); * ``` */ export declare class TrackerSDK { private readonly engine; private isInitialized; private constructor(); /** * Initializes the Tracker SDK. Fetches configuration from backend, * sets up collectors, and starts event listeners. */ initialize(callback: InitializationCallback): Promise<void>; /** Checks if the SDK is initialized. */ getIsInitialized(): boolean; /** * Triggers a custom event asynchronously. The event will be queued * and sent when network is available. */ triggerCustomEvent(eventName: string, args?: Record<string, unknown>): void; /** * Triggers a custom event synchronously with a callback. * The callback will be invoked with the server response. */ triggerCustomEventSync(eventName: string, args: Record<string, unknown>, callback: EventCallback): Promise<void>; /** Sets a user-defined value that will be included in all events. */ setUserDefinedValue(key: string, value: unknown): void; /** Gets all user-defined values. */ getUserDefinedValues(): Record<string, unknown> | null; /** Gets all currently collected variables from all collectors. */ getAllVariables(): Map<TrackerVariableType, unknown> | null; /** Gets the current tracker configuration from backend. */ getConfiguration(): TrackerConfig | null; /** Triggers a native event programmatically (for testing/debugging). */ triggerNativeEvent(eventType: TrackerEventType): void; /** Sets a listener for native tracker events. */ setNativeEventListener(listener: NativeEventListener | null): void; /** * Terminates the SDK and releases all resources. * After calling this, you must re-create and re-initialize to use it again. */ terminate(): void; /** Builder class for creating TrackerSDK instances. */ static Builder: { new (): { configuration: TrackerConfiguration | null; setConfiguration(configuration: TrackerConfiguration): /*elided*/ any; build(): TrackerSDK; }; }; }