UNPKG

@thrivestack/analytics-browser

Version:

ThriveStack Analytics Platform - Comprehensive web analytics tracking with privacy-first approach

307 lines 8.68 kB
import { ThriveStackOptions, ThriveStackEvent, UserData, GroupData, ConsentCategories, EmailAbuseResponse } 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 trackClicks; private trackForms; private enableConsent; private source; private geoIpServiceUrl; private ipAddress; private locationInfo; private interactionHistory; private maxHistoryLength; private consentCategories; private userId; private groupId; private deviceId; private deviceIdReady; private fpPromise; private locationReady; private firstPageVisitCaptured; private sessionTimeout; private debounceDelay; private sessionUpdateTimer; private lastClickTime; private debugMode; private enableDeveloperLogs; private visitorGeneratedSent; private lastSessionId; /** * Check if visitor_generated event should be sent */ private shouldSendVisitorGeneratedEvent; /** * Check if visitor_generated should be sent for new session with existing device */ private shouldSendVisitorGeneratedForNewSession; /** * Send dedicated fingerprint event with location data */ private sendFingerprintEvent; /** * Send fingerprint event for cached device ID (new session mapping) */ private sendFingerprintEventFromCache; private _hierarchyCache; private subscriptionStatus; private subscriptionCheckPromise; private isTrackingEnabled; /** * Initialize ThriveStack with configuration options */ constructor(options: ThriveStackOptions | string); /** * Check subscription status with 24-hour caching */ private checkSubscriptionStatus; /** * Fetch subscription status from API */ private fetchSubscriptionStatus; /** * Get subscription status from cache */ private getSubscriptionStatusFromCache; /** * Set subscription status in cache with 24-hour expiration */ private setSubscriptionStatusCache; /** * Generate fingerprint using IP address + User Agent hash (Plausible-style approach) * This method provides fast and privacy-friendly device identification */ generateSimpleFingerprint(): void; /** * Generate fingerprint in background and send visitor_id_generated event when ready */ private generateFingerprintInBackground; /** * Initialize device ID: Check cookie first, generate if needed */ private initializeDeviceId; /** * Start simple fingerprint generation immediately as TOP PRIORITY (background process) */ private startSimpleFingerprintGeneration; /** * Generate simple fingerprint using IP address + User Agent hash (Plausible-style) */ private generateSimpleFingerprintHash; /** * Fetch IP address with fallback APIs for high availability */ private fetchIPAddress; /** * Extract location data from IPWHO API response */ private extractIPWHOLocationData; /** * Extract location data from IPinfo API response */ private extractIPInfoLocationData; /** * Store location data from IP API in cookie */ private storeLocationDataInCookie; /** * Create hash from input string using MurmurHash3 */ private createMurmurHash; /** * MurmurHash3 implementation for consistent, fast hashing * @param str - Input string to hash * @param seed - Hash seed (default: 0x9747b28c) * @returns 32-bit hash value */ private murmurHash3; /** * Set device ID in cookie */ private setDeviceIdCookie; /** * Initialize location data - uses fingerprint data if available, otherwise fetches separately */ private initializeLocationData; /** * Fetch IP address and location information with cookie caching * NOTE: This is now only used as a fallback when fingerprint generation doesn't provide location data */ 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 consent settings */ shouldTrack(): 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; /** * Get visitor generated sent status from cookie */ private getVisitorGeneratedSentFromCookie; /** * Set visitor generated sent status in cookie */ private setVisitorGeneratedSentCookie; /** * Get last session ID from cookie */ private getLastSessionIdFromCookie; /** * Set last session ID in cookie */ private setLastSessionIdCookie; /** * Queue an event for batched sending */ private queueEvent; /** * 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; /** * Check if element has ThriveStack event class */ private hasThriveStackEventClass; /** * Capture page visit event */ capturePageVisit(): Promise<void>; /** * 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; /** * 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>; /** * Public method to report email abuse * @param email - The email address to report for abuse * @returns Promise<EmailAbuseResponse> - Response from the abuse API */ reportEmailAbuse(email: string): Promise<EmailAbuseResponse>; /** * Enable debug mode for troubleshooting */ enableDebugMode(): void; } //# sourceMappingURL=thrivestack.d.ts.map