@mira-network/mira-data-stream
Version:
JavaScript SDK for Mira Data Stream analytics and event tracking
75 lines (74 loc) • 2.35 kB
TypeScript
import { MiraOptions, EventProperties, TrackOptions } from './types';
/**
* MiraAnalytics class for tracking events
*/
export declare class MiraAnalytics {
private apiUrl;
private userId;
private anonymousId;
private writeKey;
private queue;
private flushInterval;
private flushIntervalId;
/**
* Creates a new instance of MiraAnalytics
* @param options Configuration options
*/
constructor(options?: MiraOptions);
/**
* Start the automatic flush interval
*/
private startFlushInterval;
/**
* Stop the automatic flush interval
*/
private stopFlushInterval;
/**
* Generate a random anonymous ID
* @returns A UUID v4 compatible ID
*/
private generateAnonymousId;
/**
* Identify a user
* @param userId The unique identifier for the user
* @param traits Additional user properties
* @returns The MiraAnalytics instance for chaining
*/
identify(userId: string, traits?: EventProperties): MiraAnalytics;
/**
* Set the write key for authentication
* @param writeKey The write key to use for authentication
* @returns The MiraAnalytics instance for chaining
*/
setWriteKey(writeKey: string): MiraAnalytics;
/**
* Track an event
* @param eventName The name of the event to track
* @param properties Additional event properties
* @param options Options for this specific event
* @returns The MiraAnalytics instance for chaining
*/
track(eventName: string, properties?: EventProperties, options?: TrackOptions): MiraAnalytics;
/**
* Track a page view
* @param name Page name
* @param properties Additional page properties
* @param options Options for this specific event
* @returns The MiraAnalytics instance for chaining
*/
page(name?: string | null, properties?: EventProperties, options?: TrackOptions): MiraAnalytics;
/**
* Send all queued events to the server
* @returns A promise that resolves when all events have been sent
*/
flush(): Promise<void>;
/**
* Reset user identity
* @returns The MiraAnalytics instance for chaining
*/
reset(): MiraAnalytics;
/**
* Clean up resources when this instance is no longer needed
*/
dispose(): void;
}