import { BrowserPlugin, FilterCriterion } from '@snowplow/browser-tracker-core'; import { DynamicContext } from "@snowplow/tracker-core"; /** The form tracking configuration */ interface FormTrackingConfiguration { /** The options which can be configured for the form tracking events */ options?: FormTrackingOptions; /** The dyanmic context which will be evaluated for each form event */ context?: DynamicContext | null; } /** Events to capture in form tracking */ declare enum FormTrackingEvent { /** Form field changed event */ CHANGE_FORM = "change_form", /** Form field focused event */ FOCUS_FORM = "focus_form", /** Form submitted event */ SUBMIT_FORM = "submit_form" } /** Form tracking plugin options to determine which events to fire and the elements to listen for */ interface FormTrackingOptions { /** Whether to handle events in the capture phase or the bubbling phase. Capture is usually more reliable, but may trigger early if you need changes from other submit handlers in your transforms, filters, or context generators. Defaults to true. */ useCapture?: boolean; /** List of `form` elements that are allowed to generate events, or criteria for deciding that when the event listener handles the event */ forms?: FilterCriterion | HTMLCollectionOf | NodeListOf | HTMLFormElement[]; /** Criteria for fields within forms that should generate focus or change events; you may also include a transformation function for fields that may include personal data */ fields?: FilterCriterion & { transform?: transformFn; }; /** Allow list of events to enable tracking for; can be any combination of focus_form, change_form, or submit_form */ events?: `${FormTrackingEvent}`[]; /** A list of targets to add event listeners to. If not provided, defaults to the current `document` */ targets?: EventTarget[]; } type TrackedHTMLElementTagNameMap = Pick; type TrackedHTMLElement = TrackedHTMLElementTagNameMap[keyof TrackedHTMLElementTagNameMap]; interface ElementData extends Record { name: string; value: string | null; nodeName: string; type?: string; } type transformFn = (elementValue: string | null, elementInfo: ElementData | TrackedHTMLElement, elt: TrackedHTMLElement) => string | null; /** * A plugin which enables automatic form focus, change, and submit tracking */ declare function FormTrackingPlugin(): BrowserPlugin; /** * Enables automatic form tracking. * * An event will be fired when a form field is changed or a form submitted. * This can be called multiple times: previous listeners will be removed and replaced with any updated configuration. * * @param configuration - The form tracking configuration * @param trackers - The tracker identifiers which the events will be sent to */ declare function enableFormTracking(configuration?: FormTrackingConfiguration, trackers?: Array): void; /** * Disables automatic form tracking. * * All page-level listeners for the given trackers will be removed. * * @param trackers - The tracker identifiers which the events will be sent to */ declare function disableFormTracking(trackers?: Array): void; export { FormTrackingConfiguration, FormTrackingPlugin, enableFormTracking, disableFormTracking };