@tinytapanalytics/sdk
Version:
Behavioral psychology platform that detects visitor frustration, predicts abandonment, and helps you save at-risk conversions in real-time
153 lines • 4.02 kB
TypeScript
/**
* Micro-Interaction Psychology Tracking
* Tracks HOW users interact (not just what), with adaptive performance optimization
*
* Features:
* - Rage click detection
* - Hesitation tracking
* - Form fill analysis
* - Adaptive performance (auto-adjusts based on device capabilities)
* - Client-side significance scoring
* - Smart batching and rate limiting
*/
import { TinyTapAnalyticsConfig } from '../types/index';
export interface MicroInteractionEvent {
id?: string;
type: string;
elementSelector: string;
elementType?: string;
pageUrl?: string;
timestamp: number;
hesitationDuration?: number;
isRageClick: boolean;
clickCount?: number;
cursorDistance?: number;
formFillSpeed?: number;
backspaceCount?: number;
scrollSpeed?: number;
isErrorState: boolean;
significanceScore: number;
}
export interface TrackingProfile {
name: string;
significanceThreshold: number;
maxEventsPerMinute: number;
batchSize: number;
batchInterval: number;
}
export declare class MicroInteractionTracking {
private config;
private sdk;
private isActive;
private readonly profiles;
private currentProfile;
private eventQueue;
private batchTimer?;
private interactionState;
private eventTimestamps;
private stats;
private performanceMonitor?;
private adaptiveOptimizer?;
private listeners;
private listenerIdCounter;
constructor(config: TinyTapAnalyticsConfig, sdk: any);
/**
* Start micro-interaction tracking
*/
start(): void;
/**
* Stop micro-interaction tracking
*/
stop(): void;
/**
* Apply adaptive performance settings
*/
private applyAdaptiveSettings;
/**
* Attach click tracking with rage click detection
*/
private attachClickTracking;
/**
* Attach dead click detection (clicks on non-interactive elements that look clickable)
*/
private attachDeadClickTracking;
/**
* Attach input field tracking
*/
private attachInputTracking;
/**
* Attach mouse movement tracking (RAF-throttled for better performance)
*/
private attachMouseTracking;
/**
* Attach scroll tracking (throttled)
*/
private attachScrollTracking;
/**
* Track a micro-interaction event
*/
private trackEvent;
/**
* Generate unique ID for micro-interaction event
* Format: {sessionId}_{timestamp}_{type}_{hash}
*/
private generateEventId;
/**
* Simple hash function for event ID generation
*/
private simpleHash;
/**
* Calculate significance score for an event
*/
private calculateSignificance;
/**
* Rate limiting check
*/
private allowEvent;
/**
* Start batch timer with Page Visibility API support
*/
private startBatchTimer;
/**
* Send batch of events to server
*/
private sendBatch;
/**
* Flush remaining events (called on page unload)
*/
flush(): void;
/**
* Add event listener with proper cleanup tracking
*/
private addEventListener;
private getElementSelector;
private isFormElement;
private isInteractiveElement;
private isElementInErrorState;
/**
* Update the tracking profile dynamically
*/
setProfile(profileName: 'minimal' | 'balanced' | 'detailed' | 'performance'): void;
/**
* Get current profile name
*/
getProfile(): string;
/**
* Get current tracking statistics
*/
getStats(): {
isActive: boolean;
profile: string;
currentProfile: string;
queueSize: number;
eventsThisMinute: number;
significanceThreshold: number;
maxEventsPerMinute: number;
batchSize: number;
eventCount: number;
filteredEventCount: number;
rateLimitedCount: number;
batchCount: number;
};
}
//# sourceMappingURL=MicroInteractionTracking.d.ts.map