From fbce96b36c68fe7d9543b54c4fd2b9c086bac66a Mon Sep 17 00:00:00 2001 From: Xinyi Ye Date: Tue, 10 Sep 2024 14:59:29 -0700 Subject: [PATCH] fix(analytics-types): update element interactions options (#862) --- .../src/element-interactions.ts | 23 ++++++++++++++++++- packages/analytics-types/src/index.ts | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/analytics-types/src/element-interactions.ts b/packages/analytics-types/src/element-interactions.ts index 9e809b3ad..76601d679 100644 --- a/packages/analytics-types/src/element-interactions.ts +++ b/packages/analytics-types/src/element-interactions.ts @@ -18,15 +18,23 @@ export const DEFAULT_CSS_SELECTOR_ALLOWLIST = [ 'select', 'textarea', 'label', + 'video', + 'audio', + '[contenteditable="true" i]', '[data-amp-default-track]', '.amp-default-track', ]; /** - * Default prefix to allo the plugin to capture data attributes as an event property. + * Default prefix to allow the plugin to capture data attributes as an event property. */ export const DEFAULT_DATA_ATTRIBUTE_PREFIX = 'data-amp-track-'; +/** + * Default list of elements on the page should be tracked when the page changes. + */ +export const DEFAULT_ACTION_CLICK_ALLOWLIST = ['div', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; + export interface ElementInteractionsOptions { /** * List of CSS selectors to allow auto tracking on. @@ -65,6 +73,17 @@ export interface ElementInteractionsOptions { enabled?: boolean; messenger?: Messenger; }; + + /** + * Debounce time in milliseconds for tracking events. + * This is used to detect rage clicks. + */ + debounceTime?: number; + + /** + * CSS selector allowlist for tracking clicks that result in a DOM change/navigation on elements not already allowed by the cssSelectorAllowlist + */ + actionClickAllowlist?: string[]; } export interface Messenger { @@ -72,6 +91,8 @@ export interface Messenger { setup: () => void; } +// The [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) type is used when the dom library is included in tsconfig.json +// This interface is for packages without the dom library, for example, analytics-node interface Element { id: string; className: string; diff --git a/packages/analytics-types/src/index.ts b/packages/analytics-types/src/index.ts index eba10e743..1ab1e9b06 100644 --- a/packages/analytics-types/src/index.ts +++ b/packages/analytics-types/src/index.ts @@ -71,4 +71,5 @@ export { ActionType, DEFAULT_CSS_SELECTOR_ALLOWLIST, DEFAULT_DATA_ATTRIBUTE_PREFIX, + DEFAULT_ACTION_CLICK_ALLOWLIST, } from './element-interactions';