/** * Attention Quality Manager for Grain Analytics * Enforces policies to ensure tracked data represents genuine user attention * * Policies: * 1. Page Visibility: Stop tracking when tab is hidden/backgrounded * 2. User Activity: Stop tracking when user is idle (no mouse/keyboard/touch) * 3. Section Duration Cap: Max attention per section before requiring transition * 4. Scroll Distance: Minimum scroll distance to count as meaningful engagement * * See: ATTENTION_QUALITY_POLICY.md for detailed policy documentation */ import type { ActivityDetector } from './activity'; export interface AttentionQualityOptions { /** * Maximum continuous attention duration per section (ms) * Default: 9000 (9 seconds) */ maxSectionDuration?: number; /** * Minimum scroll distance to reset attention timer (px) * Default: 100 */ minScrollDistance?: number; /** * Idle threshold - stop tracking after this period of inactivity (ms) * Default: 30000 (30 seconds) */ idleThreshold?: number; /** * Enable debug logging */ debug?: boolean; } interface SectionAttentionState { sectionName: string; currentDuration: number; lastScrollPosition: number; lastResetTime: number; } export declare class AttentionQualityManager { private options; private activityDetector; private isDestroyed; private isPageVisible; private visibilityChangeHandler; private sectionStates; private lastFilterReason; constructor(activityDetector: ActivityDetector, options?: AttentionQualityOptions); /** * Setup page visibility tracking */ private setupPageVisibilityTracking; /** * Check if tracking should be allowed (global check) * Returns true if tracking is allowed, false if it should be paused */ shouldTrack(): boolean; /** * Check if section view tracking should be allowed for a specific section * @param sectionName - Section identifier * @param currentScrollY - Current scroll position * @returns Object with shouldTrack boolean and optional reason */ shouldTrackSection(sectionName: string, currentScrollY: number): { shouldTrack: boolean; reason?: string; resetAttention?: boolean; }; /** * Update section duration (call this when tracking a section view event) * @param sectionName - Section identifier * @param durationMs - Duration to add to current attention block */ updateSectionDuration(sectionName: string, durationMs: number): void; /** * Reset attention for a specific section (call when user navigates to different section) * @param sectionName - Section identifier */ resetSection(sectionName: string): void; /** * Reset all section attention states */ resetAllSections(): void; /** * Get current attention state for a section (for debugging/monitoring) */ getSectionState(sectionName: string): SectionAttentionState | undefined; /** * Get reason why last tracking attempt was filtered */ getLastFilterReason(): string | null; /** * Check if scroll tracking should be allowed * Similar to shouldTrack() but also checks scroll-specific conditions */ shouldTrackScroll(previousScrollY: number, currentScrollY: number): { shouldTrack: boolean; reason?: string; }; /** * Get all active policies as object (for monitoring/debugging) */ getPolicies(): { maxSectionDuration: number; minScrollDistance: number; idleThreshold: number; }; /** * Get current tracking state (for monitoring/debugging) */ getTrackingState(): { isPageVisible: boolean; isUserActive: boolean; timeSinceLastActivity: number; activeSections: number; }; /** * Log debug messages */ private log; /** * Destroy and cleanup */ destroy(): void; } export {}; //# sourceMappingURL=attention-quality.d.ts.map