UNPKG

@varia-bly/variably-sdk

Version:

Official JavaScript/TypeScript SDK for Variably feature flags, experimentation, LLM experiments with React hooks, and real-time dynamic configurations

139 lines 3.5 kB
/** * Automatic event tracking for Variably SDK * Based on the comprehensive metrics collection plan in docs/concepts/metrics-collection.md */ import { AutoTrackConfig, Event } from './types'; export declare class AutoTracker { private config; private trackEventCallback; private trackExperimentMetricCallback; private getUserContext; private sessionStartTime; private sessionId; private currentExperimentContext; private maxScrollDepth; private isTracking; private static DEFAULT_CONFIG; constructor(config: AutoTrackConfig | undefined, trackEventCallback: (event: Event) => Promise<void>, trackExperimentMetricCallback: (experimentId: string, metric: any) => Promise<void>, getUserContext: () => any | null); /** * Start automatic tracking */ start(): void; /** * Stop automatic tracking */ stop(): void; /** * Check if tracking is currently active */ get isActive(): boolean; /** * Update experiment context when feature gates are evaluated */ updateExperimentContext(gateKey: string, experimentId?: string): void; /** * Setup all event listeners for automatic tracking */ private setupEventListeners; /** * Clean up event listeners */ private cleanup; /** * Handle click events */ private handleClick; /** * Handle scroll events */ private handleScroll; /** * Handle form submissions */ private handleFormSubmit; /** * Handle page visibility changes */ private handleVisibilityChange; /** * Handle page unload */ private handlePageUnload; /** * Handle page navigation changes (SPA) */ private handlePageChange; /** * Track page view event */ private trackPageView; /** * Check and track conversion events based on configuration */ private checkAndTrackConversions; /** * Track a specific conversion event */ private trackConversionEvent; /** * Track session end */ private trackSessionEnd; /** * Track session pause */ private trackSessionPause; /** * Track session resume */ private trackSessionResume; /** * Check if click should be tracked */ private shouldTrackClick; /** * Check if element should be excluded from tracking */ private shouldExcludeElement; /** * Extract click data from element */ private extractClickData; /** * Extract property value based on configuration */ private extractPropertyValue; /** * Get element position in its container */ private getElementPosition; /** * Get current layout type based on configuration */ private getLayoutType; /** * Get current experiment context */ private getExperimentContext; /** * Generate unique session ID */ private generateSessionId; /** * Get XPath for element (for precise tracking) */ private getElementXPath; /** * Track event using the provided callback, with experiment attribution when applicable */ private trackEvent; /** * Extract numeric value from event for experiment metrics */ private getEventValue; /** * Intercept History API for SPA navigation detection */ private interceptHistoryAPI; } //# sourceMappingURL=auto-tracker.d.ts.map