UNPKG

@tinytapanalytics/sdk

Version:

Behavioral psychology platform that detects visitor frustration, predicts abandonment, and helps you save at-risk conversions in real-time

163 lines 3.71 kB
/** * A/B Testing features for experimentation and optimization * Dynamically imported to reduce core bundle size */ import { TinyTapAnalyticsConfig } from '../types/index'; interface ABTest { id: string; name: string; variants: ABVariant[]; allocation: Record<string, number>; status: 'draft' | 'running' | 'paused' | 'completed'; targetingRules?: TargetingRule[]; conversionGoals: string[]; } interface ABVariant { id: string; name: string; control: boolean; traffic: number; changes: ABChange[]; } interface ABChange { type: 'css' | 'html' | 'javascript' | 'redirect'; selector?: string; property?: string; value: string; } interface TargetingRule { type: 'url' | 'device' | 'traffic' | 'attribute'; operator: 'equals' | 'contains' | 'matches' | 'greater' | 'less'; value: string | number; } interface TestResult { testId: string; variantId: string; userId: string; sessionId: string; assignedAt: number; conversions: Array<{ goal: string; timestamp: number; value?: number; }>; } export declare class ABTesting { private config; private sdk; private activeTests; private userAssignments; private testResults; private storageKey; constructor(config: TinyTapAnalyticsConfig, sdk: any); /** * Initialize A/B testing */ init(): Promise<void>; /** * Create a new A/B test */ createTest(test: Omit<ABTest, 'id' | 'status'>): string; /** * Start an A/B test */ startTest(testId: string): boolean; /** * Stop an A/B test */ stopTest(testId: string): boolean; /** * Get user's variant for a test */ getVariant(testId: string): string | null; /** * Track conversion for A/B test */ trackConversion(testId: string, goal: string, value?: number): void; /** * Apply variant changes to the page */ applyVariant(testId: string, variantId: string): void; /** * Get test results */ getTestResults(testId: string): TestResult | null; /** * Get all active tests */ getActiveTests(): ABTest[]; /** * Load active tests from API */ private loadActiveTests; /** * Process all active tests */ private processActiveTests; /** * Process a single test */ private processTest; /** * Check if user matches targeting rules */ private matchesTargeting; /** * Check URL targeting rule */ private matchesUrlRule; /** * Check device targeting rule */ private matchesDeviceRule; /** * Check traffic targeting rule */ private matchesTrafficRule; /** * Assign user to variant based on traffic allocation */ private assignUserToVariant; /** * Apply a single change to the page */ private applyChange; /** * Apply CSS change */ private applyCSSChange; /** * Apply HTML change */ private applyHTMLChange; /** * Apply JavaScript change */ private applyJavaScriptChange; /** * Apply redirect */ private applyRedirect; /** * Generate test ID */ private generateTestId; /** * Generate anonymous ID */ private generateAnonymousId; /** * Hash string for consistent assignment */ private hashString; /** * Store user assignments in localStorage */ private storeAssignments; /** * Load stored assignments from localStorage */ private loadStoredAssignments; } export {}; //# sourceMappingURL=ABTesting.d.ts.map