@thrivestack/analytics-browser
Version:
ThriveStack Analytics Platform - Comprehensive web analytics tracking with privacy-first approach
241 lines • 6.26 kB
TypeScript
import { ThriveStackOptions, ThriveStackEvent, UserData, GroupData, ConsentCategories } from './types';
/**
* ThriveStack Analytics Platform
* Comprehensive web analytics tracking with privacy-first approach
* @version 2.0.1
*/
export declare class ThriveStack {
private apiKey;
private apiEndpoint;
private respectDoNotTrack;
private trackClicks;
private trackForms;
private enableConsent;
private source;
private geoIpServiceUrl;
private ipAddress;
private locationInfo;
private eventQueue;
private queueTimer;
private batchSize;
private batchInterval;
private interactionHistory;
private maxHistoryLength;
private consentCategories;
private userId;
private groupId;
private deviceId;
private deviceIdReady;
private fpPromise;
private sessionTimeout;
private debounceDelay;
private sessionUpdateTimer;
private lastClickTime;
private debugMode;
private _hierarchyCache;
/**
* Initialize ThriveStack with configuration options
*/
constructor(options: ThriveStackOptions | string);
/**
* Initialize device ID with proper fallback logic
*/
private initializeDeviceId;
/**
* Initialize FingerprintJS
*/
private initFingerprintJS;
/**
* Generate a random device ID as fallback
*/
private generateRandomDeviceId;
/**
* Set device ID in cookie
*/
private setDeviceIdCookie;
/**
* Fetch IP address and location information with cookie caching
*/
private fetchIpAndLocationInfo;
/**
* Set location info in cookie with Base64 encoding
*/
private setLocationInfoCookie;
/**
* Get location info from cookie with Base64 decoding
*/
private getLocationInfoFromCookie;
/**
* Remove location info cookie (used when cookie is corrupted)
*/
private removeLocationInfoCookie;
/**
* Initialize ThriveStack and start tracking
*/
init(userId?: string, source?: string): Promise<void>;
/**
* Check if tracking is allowed based on DNT and consent settings
*/
shouldTrack(): boolean;
/**
* Check if specific tracking category is allowed
*/
isTrackingAllowed(category: keyof ConsentCategories): boolean;
/**
* Update consent settings for a tracking category
*/
setConsent(category: keyof ConsentCategories, hasConsent: boolean): void;
/**
* Set user ID for tracking
*/
setUserId(userId: string): void;
/**
* Set groupId in instance and cookie
*/
setGroupId(groupId: string): void;
/**
* Set source for tracking
*/
setSource(source: string): void;
/**
* Set userId in cookie
*/
private setUserIdCookie;
/**
* Get userId from cookie
*/
private getUserIdFromCookie;
/**
* Set groupId in cookie
*/
private setGroupIdCookie;
/**
* Get groupId from cookie
*/
private getGroupIdFromCookie;
/**
* Queue an event for batched sending
*/
private queueEvent;
/**
* Process queue only if device ID is ready
*/
private processQueueIfReady;
/**
* Process and send queued events
*/
private processQueue;
/**
* Track events by sending to ThriveStack API
*/
track(events: ThriveStackEvent[]): Promise<any>;
/**
* Send user identification data
*/
identify(data: UserData | UserData[]): Promise<any>;
/**
* Send group data
*/
group(data: GroupData | GroupData[]): Promise<any>;
/**
* Get UTM parameters from URL
*/
private getUtmParameters;
/**
* Get device ID - now returns the actual device ID or null if not ready
*/
getDeviceId(): string | null;
/**
* Get device ID from cookie
*/
private getDeviceIdFromCookie;
/**
* Get session ID from cookie
*/
private getSessionId;
/**
* Create a new session
*/
private createNewSession;
/**
* Migrate old session format
*/
private migrateOldSession;
/**
* Set session cookie with new format
*/
private setSessionCookie;
/**
* Update session activity with debouncing
*/
private updateSessionActivity;
/**
* Immediate session activity update
*/
private updateSessionActivityImmediate;
/**
* Setup session tracking event listeners
*/
private setupSessionTracking;
/**
* Check if element has ThriveStack event class
*/
private hasThriveStackEventClass;
/**
* Capture page visit event
*/
private capturePageVisit;
/**
* Add event to interaction history
*/
private addToInteractionHistory;
/**
* Capture element click event
*/
private captureClickEvent;
/**
* Capture form events (submission, abandonment)
*/
private captureFormEvent;
/**
* Set up automatic page visit tracking
*/
private autoCapturePageVisit;
/**
* Set up automatic click event tracking
*/
private autoCaptureClickEvents;
/**
* Set up automatic form event tracking
*/
private autoCaptureFormEvents;
/**
* Get element hierarchy for DOM traversal
* @param {Element} element - DOM element
* @returns {string} Element hierarchy path
*/
private getElementHierarchy;
/**
* Get CSS selector for element
* @param {Element} element - DOM element
* @returns {string} CSS selector
*/
private getElementSelector;
/**
* Automatically detect and clean PII from event data
*/
private cleanPIIFromEventData;
/**
* Set user information and optionally make identify API call
*/
setUser(userId: string, emailId: string, properties?: Record<string, any>): Promise<any | null>;
/**
* Set group information and optionally make group API call
*/
setGroup(groupId: string, groupDomain: string, groupName: string, properties?: Record<string, any>): Promise<any | null>;
/**
* Enable debug mode for troubleshooting
*/
enableDebugMode(): void;
}
//# sourceMappingURL=thrivestack.d.ts.map