@randyd45/web-behavior-tracker
Version:
A framework-agnostic package for tracking user behavior on web forms
64 lines (63 loc) • 2.33 kB
TypeScript
import { BehaviorEvent, ElementState } from './types.js';
/**
* Utility functions for behavior tracking
*/
export declare class TrackingUtils {
/**
* Checks if an element is a form element or has a form-related role
*/
static isFormElement(element: HTMLElement): boolean;
/**
* Gets the current value of an element
*/
static getElementValue(element: HTMLElement): string;
/**
* Gets element attributes that are relevant for tracking
*/
static getElementAttributes(element: HTMLElement): Record<string, string>;
/**
* Gets the current state of an element
*/
static getElementState(element: HTMLElement): ElementState;
/**
* Gets the DOM path of an element for identification
*/
static getElementPath(element: HTMLElement): string;
/**
* Creates a behavior event with common properties
*/
static createBehaviorEvent(type: BehaviorEvent['type'], target: HTMLElement, value?: any, additionalData?: Record<string, any>): BehaviorEvent;
/**
* Throttles function calls to prevent excessive execution
*/
static throttle<T extends (...args: any[]) => any>(func: T, delay: number): (...args: Parameters<T>) => void;
/**
* Debounces function calls to delay execution until after calls have stopped
*/
static debounce<T extends (...args: any[]) => any>(func: T, delay: number): (...args: Parameters<T>) => void;
/**
* Checks if an event should be tracked based on options
*/
static shouldTrackEvent(eventType: string, options: {
trackMouseMovements?: boolean;
trackFocusBlur?: boolean;
trackClicks?: boolean;
trackInputChanges?: boolean;
}): boolean;
/**
* Detects if input is likely from autocomplete
*/
static isAutocompleteEvent(currentValue: string, previousValue: string, currentTime: number, lastInputTime: number, target: HTMLElement): boolean;
/**
* Checks if the added text looks like a complete word/phrase
*/
private static isCompleteWordInput;
/**
* Checks if the element is commonly used for autocomplete
*/
private static isAutocompleteField;
/**
* Checks if the added text matches common autocomplete patterns
*/
private static hasAutocompletePatterns;
}