import { VariantId, UserId, EvaluationReason, JsonValue } from '../advanced/types'; /** * Exposure event data. */ export interface ExposureEvent { /** Flag key */ readonly flagKey: string; /** Assigned variant */ readonly variantId: VariantId; /** User ID */ readonly userId: UserId; /** Session ID */ readonly sessionId?: string; /** Experiment ID if part of experiment */ readonly experimentId?: string; /** Cohort assignment */ readonly cohort?: string; /** Evaluation reason */ readonly reason?: EvaluationReason; /** Whether this is first exposure */ readonly isFirstExposure: boolean; /** Timestamp */ readonly timestamp: Date; /** Page/screen where exposure occurred */ readonly page?: string; /** Additional properties */ readonly properties?: Record; } /** * Stored exposure record. */ export interface ExposureRecord { /** Flag key */ readonly flagKey: string; /** Variant ID */ readonly variantId: VariantId; /** First exposure timestamp */ readonly firstExposedAt: Date; /** Last exposure timestamp */ readonly lastExposedAt: Date; /** Total exposure count */ readonly exposureCount: number; /** Experiment ID */ readonly experimentId?: string; /** Cohort */ readonly cohort?: string; } /** * User exposure summary. */ export interface UserExposureSummary { /** User ID */ readonly userId: UserId; /** Total flags exposed to */ readonly flagCount: number; /** Total exposure events */ readonly totalExposures: number; /** Experiments participating in */ readonly experiments: string[]; /** Flag exposures */ readonly exposures: ExposureRecord[]; /** First activity */ readonly firstSeenAt: Date; /** Last activity */ readonly lastSeenAt: Date; } /** * Exposure tracker configuration. */ export interface ExposureTrackerConfig { /** Enable tracking */ readonly enabled?: boolean; /** Deduplication window in ms (default: 24h) */ readonly deduplicationWindow?: number; /** Storage key prefix */ readonly storagePrefix?: string; /** Use persistent storage */ readonly persistent?: boolean; /** Callback on exposure */ readonly onExposure?: (exposure: ExposureEvent) => void; /** Batch exposures before callback */ readonly batchSize?: number; /** Batch flush interval */ readonly flushInterval?: number; /** Enable debug logging */ readonly debug?: boolean; /** Maximum stored exposures per user */ readonly maxExposuresPerUser?: number; } /** * Input for tracking exposure. */ export interface TrackExposureInput { /** Flag key */ readonly flagKey: string; /** Variant ID */ readonly variantId: VariantId; /** User ID */ readonly userId: UserId; /** Session ID */ readonly sessionId?: string; /** Experiment ID */ readonly experimentId?: string; /** Cohort */ readonly cohort?: string; /** Evaluation reason */ readonly reason?: EvaluationReason; /** Current page/screen */ readonly page?: string; /** Additional properties */ readonly properties?: Record; } /** * Tracks feature flag exposures for analytics and experiments. */ export declare class ExposureTracker { private config; private userExposures; private pendingExposures; private flushTimer; private listeners; constructor(config?: ExposureTrackerConfig); /** * Track a flag exposure. */ trackExposure(input: TrackExposureInput): ExposureEvent | null; /** * Track multiple exposures at once. */ trackExposures(inputs: TrackExposureInput[]): ExposureEvent[]; /** * Get exposure record for a user and flag. */ getExposure(userId: UserId, flagKey: string, experimentId?: string): ExposureRecord | null; /** * Get all exposures for a user. */ getExposures(userId: UserId): ExposureRecord[]; /** * Get user exposure summary. */ getUserSummary(userId: UserId): UserExposureSummary | null; /** * Check if user was exposed to a flag. */ wasExposed(userId: UserId, flagKey: string, experimentId?: string): boolean; /** * Get the variant a user was exposed to. */ getExposedVariant(userId: UserId, flagKey: string, experimentId?: string): VariantId | null; /** * Get all users exposed to a flag. */ getExposedUsers(flagKey: string, experimentId?: string): UserId[]; /** * Get exposure counts by variant. */ getVariantExposures(flagKey: string, experimentId?: string): Record; /** * Get all users in an experiment. */ getExperimentUsers(experimentId: string): UserId[]; /** * Get experiment cohort assignments. */ getExperimentCohorts(experimentId: string): Record; /** * Get variant distribution for an experiment. */ getExperimentDistribution(experimentId: string): Record; /** * Subscribe to exposure events. */ subscribe(listener: (exposure: ExposureEvent) => void): () => void; /** * Flush pending exposures. */ flush(): Promise; /** * Clear all exposure data. */ clear(): void; /** * Clear exposures for a specific user. */ clearUser(userId: UserId): void; /** * Shutdown the tracker. */ shutdown(): Promise; /** * Enable or disable tracking. */ setEnabled(enabled: boolean): void; private isDuplicateExposure; private getExposureKey; private enforceMaxExposures; private notifyListeners; private startFlushTimer; private stopFlushTimer; private loadFromStorage; private saveToStorage; private log; } /** * Get the singleton exposure tracker instance. */ export declare function getExposureTracker(): ExposureTracker; /** * Initialize the singleton with configuration. */ export declare function initExposureTracker(config: ExposureTrackerConfig): ExposureTracker; /** * Reset the singleton instance. */ export declare function resetExposureTracker(): void; /** * Create exposure tracking context for React. */ export declare function createExposureContext(config?: ExposureTrackerConfig): { tracker: ExposureTracker; trackExposure: (input: TrackExposureInput) => ExposureEvent | null; getExposure: (userId: UserId, flagKey: string, experimentId?: string) => ExposureRecord | null; wasExposed: (userId: UserId, flagKey: string, experimentId?: string) => boolean; subscribe: (callback: (exposure: ExposureEvent) => void) => () => void; };