@amplitude/plugin-autocapture-browser 1.28.0-featelement-selector-v1.0 → 1.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/autocapture-plugin.d.ts.map +1 -1
- package/lib/cjs/autocapture-plugin.js +7 -66
- package/lib/cjs/autocapture-plugin.js.map +1 -1
- package/lib/cjs/data-extractor.d.ts +19 -17
- package/lib/cjs/data-extractor.d.ts.map +1 -1
- package/lib/cjs/data-extractor.js +29 -25
- package/lib/cjs/data-extractor.js.map +1 -1
- package/lib/cjs/element-selector-config.d.ts +21 -0
- package/lib/cjs/element-selector-config.d.ts.map +1 -0
- package/lib/cjs/element-selector-config.js +34 -0
- package/lib/cjs/element-selector-config.js.map +1 -0
- package/lib/cjs/frustration-plugin.d.ts.map +1 -1
- package/lib/cjs/frustration-plugin.js +6 -1
- package/lib/cjs/frustration-plugin.js.map +1 -1
- package/lib/cjs/libs/element-path.d.ts +1 -23
- package/lib/cjs/libs/element-path.d.ts.map +1 -1
- package/lib/cjs/libs/element-path.js +173 -28
- package/lib/cjs/libs/element-path.js.map +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.d.ts.map +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/autocapture-plugin.d.ts.map +1 -1
- package/lib/esm/autocapture-plugin.js +7 -66
- package/lib/esm/autocapture-plugin.js.map +1 -1
- package/lib/esm/data-extractor.d.ts +19 -17
- package/lib/esm/data-extractor.d.ts.map +1 -1
- package/lib/esm/data-extractor.js +30 -26
- package/lib/esm/data-extractor.js.map +1 -1
- package/lib/esm/element-selector-config.d.ts +21 -0
- package/lib/esm/element-selector-config.d.ts.map +1 -0
- package/lib/esm/element-selector-config.js +30 -0
- package/lib/esm/element-selector-config.js.map +1 -0
- package/lib/esm/frustration-plugin.d.ts.map +1 -1
- package/lib/esm/frustration-plugin.js +6 -1
- package/lib/esm/frustration-plugin.js.map +1 -1
- package/lib/esm/libs/element-path.d.ts +1 -23
- package/lib/esm/libs/element-path.d.ts.map +1 -1
- package/lib/esm/libs/element-path.js +172 -27
- package/lib/esm/libs/element-path.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.d.ts.map +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/amplitude-min.js +1 -1
- package/lib/scripts/amplitude-min.js.gz +0 -0
- package/lib/scripts/amplitude-min.js.map +1 -1
- package/lib/scripts/amplitude-min.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/autocapture-plugin.d.ts.map +1 -1
- package/lib/scripts/data-extractor.d.ts +19 -17
- package/lib/scripts/data-extractor.d.ts.map +1 -1
- package/lib/scripts/element-selector-config.d.ts +21 -0
- package/lib/scripts/element-selector-config.d.ts.map +1 -0
- package/lib/scripts/frustration-plugin.d.ts.map +1 -1
- package/lib/scripts/libs/element-path.d.ts +1 -23
- package/lib/scripts/libs/element-path.d.ts.map +1 -1
- package/lib/scripts/version.d.ts +1 -1
- package/lib/scripts/version.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frustration-plugin.d.ts","sourceRoot":"","sources":["../../src/frustration-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,8BAA8B,EAG9B,UAAU,EAKX,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAA0B,4BAA4B,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGlH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,iBAAiB,EAKlB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"frustration-plugin.d.ts","sourceRoot":"","sources":["../../src/frustration-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,8BAA8B,EAG9B,UAAU,EAKX,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAA0B,4BAA4B,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGlH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,iBAAiB,EAKlB,MAAM,eAAe,CAAC;AAMvB,MAAM,WAAW,oBAAoB;IACnC,CAAC,eAAe,CAAC,eAAe,CAAC,EAAE,UAAU,CAAC,4BAA4B,CAAC,UAAU,CAAC,CAAC,CAAC;IACxF,CAAC,eAAe,CAAC,kBAAkB,CAAC,EAAE,UAAU,CAAC,gBAAgB,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;IACrF,CAAC,eAAe,CAAC,sBAAsB,CAAC,EAAE,UAAU,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC1F,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,EAAE,UAAU,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,CAAC;IACnF,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACzD,CAAC,eAAe,CAAC,mBAAmB,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAC/D;AAED,KAAK,uBAAuB,GAAG,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AA+B9E,eAAO,MAAM,iBAAiB,aAAa,8BAA8B,KAAQ,uBAkQhF,CAAC"}
|
|
@@ -11,6 +11,7 @@ var track_rage_click_1 = require("./autocapture/track-rage-click");
|
|
|
11
11
|
var autocapture_plugin_1 = require("./autocapture-plugin");
|
|
12
12
|
var observables_1 = require("./observables");
|
|
13
13
|
var data_extractor_1 = require("./data-extractor");
|
|
14
|
+
var element_selector_config_1 = require("./element-selector-config");
|
|
14
15
|
var track_error_click_1 = require("./autocapture/track-error-click");
|
|
15
16
|
var track_thrashed_cursor_1 = require("./autocapture/track-thrashed-cursor");
|
|
16
17
|
/**
|
|
@@ -134,7 +135,7 @@ var frustrationPlugin = function (options) {
|
|
|
134
135
|
_a;
|
|
135
136
|
};
|
|
136
137
|
var setup = function (config, amplitude) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
137
|
-
var allObservables, shouldTrackRageClick, rageClickSubscription, shouldTrackDeadClick, deadClickSubscription, shouldTrackErrorClick, errorClickSubscription, directionChanges, thresholdMs, thrashedCursorSubscription;
|
|
138
|
+
var allObservables, elementSelectorConfigCleanup, shouldTrackRageClick, rageClickSubscription, shouldTrackDeadClick, deadClickSubscription, shouldTrackErrorClick, errorClickSubscription, directionChanges, thresholdMs, thrashedCursorSubscription;
|
|
138
139
|
var _a;
|
|
139
140
|
return tslib_1.__generator(this, function (_b) {
|
|
140
141
|
/* istanbul ignore if */
|
|
@@ -142,6 +143,10 @@ var frustrationPlugin = function (options) {
|
|
|
142
143
|
return [2 /*return*/];
|
|
143
144
|
}
|
|
144
145
|
allObservables = createObservables();
|
|
146
|
+
elementSelectorConfigCleanup = (0, element_selector_config_1.subscribeToElementSelectorConfig)(config, dataExtractor);
|
|
147
|
+
if (elementSelectorConfigCleanup) {
|
|
148
|
+
subscriptions.push({ unsubscribe: elementSelectorConfigCleanup });
|
|
149
|
+
}
|
|
145
150
|
// Create subscriptions only for enabled features
|
|
146
151
|
if (rageClicksEnabled) {
|
|
147
152
|
shouldTrackRageClick = (0, helpers_1.createShouldTrackEvent)(options, rageCssSelectors);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frustration-plugin.js","sourceRoot":"","sources":["../../src/frustration-plugin.ts"],"names":[],"mappings":";;;;AAAA,0CAA0C;AAC1C,4DAYmC;AACnC,6DAAyC;AACzC,qCAAkH;AAClH,mEAAgE;AAChE,mEAAiE;AACjE,2DAAuD;AACvD,6CAMuB;AACvB,mDAAiD;AACjD,qEAAmE;A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Config,\n EnrichmentPlugin,\n FrustrationInteractionsOptions,\n DEFAULT_DATA_ATTRIBUTE_PREFIX,\n multicast,\n Observable,\n Unsubscribable,\n DEFAULT_RAGE_CLICK_ALLOWLIST,\n DEFAULT_DEAD_CLICK_ALLOWLIST,\n DEFAULT_ERROR_CLICK_ALLOWLIST,\n} from '@amplitude/analytics-core';\nimport * as constants from './constants';\nimport { createShouldTrackEvent, ElementBasedTimestampedEvent, NavigateEvent, TimestampedEvent } from './helpers';\nimport { trackDeadClick } from './autocapture/track-dead-click';\nimport { trackRageClicks } from './autocapture/track-rage-click';\nimport { ObservablesEnum } from './autocapture-plugin';\nimport {\n BrowserErrorEvent,\n createClickObservable,\n createErrorObservable,\n createMutationObservable,\n createMouseMoveObservable,\n} from './observables';\nimport { DataExtractor } from './data-extractor';\nimport { trackErrorClicks } from './autocapture/track-error-click';\nimport { trackThrashedCursor } from './autocapture/track-thrashed-cursor';\n\nexport interface AllWindowObservables {\n [ObservablesEnum.ClickObservable]: Observable<ElementBasedTimestampedEvent<MouseEvent>>;\n [ObservablesEnum.MutationObservable]: Observable<TimestampedEvent<MutationRecord[]>>;\n [ObservablesEnum.BrowserErrorObservable]: Observable<TimestampedEvent<BrowserErrorEvent>>;\n [ObservablesEnum.NavigateObservable]?: Observable<TimestampedEvent<NavigateEvent>>;\n [ObservablesEnum.SelectionObservable]?: Observable<void>;\n [ObservablesEnum.MouseMoveObservable]: Observable<MouseEvent>;\n}\n\ntype BrowserEnrichmentPlugin = EnrichmentPlugin<BrowserClient, BrowserConfig>;\n\n/**\n * Helper function to extract the css selector allowlist\n * from the frustration interactions options for a specific\n * autocapture feature.\n */\nfunction getCssSelectorAllowlist(\n options: FrustrationInteractionsOptions,\n attribute: keyof FrustrationInteractionsOptions,\n defaultAllowlist: string[],\n enabled: boolean,\n): string[] {\n if (!enabled) {\n return [];\n }\n const config = options[attribute];\n if (\n typeof config === 'object' &&\n config !== null &&\n 'cssSelectorAllowlist' in config &&\n Array.isArray(config.cssSelectorAllowlist)\n ) {\n return config.cssSelectorAllowlist;\n }\n return defaultAllowlist;\n}\n\nconst MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES = 5;\nconst MAXIMUM_THRASHED_CURSOR_THRESHOLD = 4000;\n\nexport const frustrationPlugin = (options: FrustrationInteractionsOptions = {}): BrowserEnrichmentPlugin => {\n const name = constants.FRUSTRATION_PLUGIN_NAME;\n const type = 'enrichment';\n\n const subscriptions: Unsubscribable[] = [];\n\n let isErrorClicksEnabled = options.errorClicks !== false;\n\n // if errorClicks is not defined, disable it\n // change this once it moves out of @experimental\n if (!options.errorClicks) {\n isErrorClicksEnabled = false;\n }\n\n // Check if each feature is enabled\n const deadClicksEnabled = options.deadClicks !== false && options.deadClicks !== null;\n const rageClicksEnabled = options.rageClicks !== false && options.rageClicks !== null;\n\n let thrashedCursorEnabled = options.thrashedCursor !== false && options.thrashedCursor !== null;\n if (!options.thrashedCursor) {\n thrashedCursorEnabled = false;\n }\n\n // Get CSS selectors for enabled features\n const rageCssSelectors = getCssSelectorAllowlist(\n options,\n 'rageClicks',\n DEFAULT_RAGE_CLICK_ALLOWLIST,\n rageClicksEnabled,\n );\n\n const deadCssSelectors = getCssSelectorAllowlist(\n options,\n 'deadClicks',\n DEFAULT_DEAD_CLICK_ALLOWLIST,\n deadClicksEnabled,\n );\n\n const errorCssSelectors = getCssSelectorAllowlist(\n options,\n 'errorClicks',\n DEFAULT_ERROR_CLICK_ALLOWLIST,\n isErrorClicksEnabled,\n );\n\n const dataAttributePrefix = options.dataAttributePrefix ?? DEFAULT_DATA_ATTRIBUTE_PREFIX;\n\n const dataExtractor = new DataExtractor(options);\n\n // combine the selector lists from enabled features to determine which clicked elements should be filtered\n const combinedCssSelectors = [...new Set([...rageCssSelectors, ...deadCssSelectors, ...errorCssSelectors])];\n\n // Create observables on events on the window\n const createObservables = (): AllWindowObservables => {\n const clickObservable = multicast(\n createClickObservable('pointerdown').map((click) => {\n return dataExtractor.addAdditionalEventProperties(\n click,\n 'click',\n combinedCssSelectors,\n dataAttributePrefix,\n true, // capture when cursor is pointer\n );\n }),\n );\n\n const browserErrorObservables = multicast(\n createErrorObservable().map((error) => {\n return dataExtractor.addTypeAndTimestamp(error, 'error');\n }),\n );\n\n const enrichedMutationObservable = multicast<TimestampedEvent<MutationRecord[]>>(\n createMutationObservable().map((mutation) =>\n dataExtractor.addAdditionalEventProperties(mutation, 'mutation', combinedCssSelectors, dataAttributePrefix),\n ),\n );\n\n let enrichedNavigateObservable: Observable<TimestampedEvent<NavigateEvent>> | undefined;\n\n if (window.navigation) {\n const navigateObservable = new Observable<Event>((observer) => {\n const handler = (event: Event): void => {\n observer.next({\n ...event,\n type: 'navigate',\n });\n };\n window.navigation.addEventListener('navigate', handler);\n return () => {\n window.navigation.removeEventListener('navigate', handler);\n };\n });\n enrichedNavigateObservable = multicast<TimestampedEvent<NavigateEvent>>(\n navigateObservable.map<TimestampedEvent<NavigateEvent>>(\n (navigate) =>\n dataExtractor.addAdditionalEventProperties(\n navigate,\n 'navigate',\n combinedCssSelectors,\n dataAttributePrefix,\n ) as TimestampedEvent<NavigateEvent>,\n ),\n );\n }\n\n const selectionObservable = multicast(\n new Observable<void>((observer) => {\n const handler = () => {\n const el: HTMLElement | null = document.activeElement as HTMLElement;\n\n // handle input and textarea\n\n // if the selectionStart and selectionEnd are the same, it means\n // nothing is selected (collapsed) and the cursor position is one point\n if (el && (el.tagName === 'TEXTAREA' || el.tagName === 'INPUT')) {\n let start: number | null | undefined;\n let end: number | null | undefined;\n try {\n start = (el as HTMLInputElement | HTMLTextAreaElement).selectionStart;\n end = (el as HTMLInputElement | HTMLTextAreaElement).selectionEnd;\n if (start === end) return; // collapsed\n } catch (error) {\n // input that doesn't support selectionStart/selectionEnd (like checkbox)\n // do nothing here\n return;\n }\n return observer.next();\n }\n\n // handle non-input elements\n\n // non-input elements have an attribute called \"isCollapsed\" which\n // if true, indicates there \"is currently not any text selected\"\n // (see https://developer.mozilla.org/en-US/docs/Web/API/Selection/isCollapsed)\n const selection = window.getSelection();\n if (!selection || selection.isCollapsed) return;\n return observer.next();\n };\n window.document.addEventListener('selectionchange', handler);\n return () => {\n window.document.removeEventListener('selectionchange', handler);\n };\n }),\n );\n\n const mouseMoveObservable = multicast(createMouseMoveObservable());\n\n return {\n [ObservablesEnum.ClickObservable]: clickObservable as Observable<ElementBasedTimestampedEvent<MouseEvent>>,\n [ObservablesEnum.MutationObservable]: enrichedMutationObservable,\n [ObservablesEnum.NavigateObservable]: enrichedNavigateObservable,\n [ObservablesEnum.BrowserErrorObservable]: browserErrorObservables,\n [ObservablesEnum.SelectionObservable]: selectionObservable,\n [ObservablesEnum.MouseMoveObservable]: mouseMoveObservable,\n };\n };\n\n const setup: BrowserEnrichmentPlugin['setup'] = async (config, amplitude) => {\n /* istanbul ignore if */\n if (typeof document === 'undefined') {\n return;\n }\n\n // Create observables for events on the window\n const allObservables = createObservables();\n\n // Create subscriptions only for enabled features\n if (rageClicksEnabled) {\n const shouldTrackRageClick = createShouldTrackEvent(options, rageCssSelectors);\n const rageClickSubscription = trackRageClicks({\n allObservables,\n amplitude,\n shouldTrackRageClick,\n });\n subscriptions.push(rageClickSubscription);\n }\n\n if (deadClicksEnabled) {\n const shouldTrackDeadClick = createShouldTrackEvent(options, deadCssSelectors);\n const deadClickSubscription = trackDeadClick({\n amplitude,\n allObservables,\n getEventProperties: (actionType, element) =>\n dataExtractor.getEventProperties(actionType, element, dataAttributePrefix),\n shouldTrackDeadClick,\n });\n subscriptions.push(deadClickSubscription);\n }\n\n if (isErrorClicksEnabled) {\n const shouldTrackErrorClick = createShouldTrackEvent(options, errorCssSelectors);\n const errorClickSubscription = trackErrorClicks({\n amplitude,\n allObservables,\n shouldTrackErrorClick,\n });\n subscriptions.push(errorClickSubscription);\n }\n\n if (thrashedCursorEnabled) {\n let directionChanges, thresholdMs;\n if (typeof options.thrashedCursor === 'object') {\n directionChanges = options.thrashedCursor.directionChanges;\n thresholdMs = options.thrashedCursor.threshold;\n\n if (directionChanges && directionChanges < MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES) {\n config.loggerProvider.warn(\n `'thrashedCursor.directionChanges' of ${directionChanges} is below the minimum of ${MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES}, setting to ${MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES}`,\n );\n directionChanges = MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES;\n }\n if (thresholdMs && thresholdMs > MAXIMUM_THRASHED_CURSOR_THRESHOLD) {\n config.loggerProvider.warn(\n `'thrashedCursor.threshold' of ${thresholdMs} is above the maximum of ${MAXIMUM_THRASHED_CURSOR_THRESHOLD}, setting to ${MAXIMUM_THRASHED_CURSOR_THRESHOLD}`,\n );\n thresholdMs = MAXIMUM_THRASHED_CURSOR_THRESHOLD;\n }\n }\n const thrashedCursorSubscription = trackThrashedCursor({\n amplitude,\n options,\n allObservables,\n directionChanges,\n thresholdMs,\n });\n subscriptions.push(thrashedCursorSubscription);\n }\n\n /* istanbul ignore next */\n config?.loggerProvider?.log(`${name} has been successfully added.`);\n };\n\n const execute: BrowserEnrichmentPlugin['execute'] = async (event) => {\n return event;\n };\n\n const teardown = async () => {\n for (const subscription of subscriptions) {\n subscription.unsubscribe();\n }\n };\n\n return {\n name,\n type,\n setup,\n execute,\n teardown,\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"frustration-plugin.js","sourceRoot":"","sources":["../../src/frustration-plugin.ts"],"names":[],"mappings":";;;;AAAA,0CAA0C;AAC1C,4DAYmC;AACnC,6DAAyC;AACzC,qCAAkH;AAClH,mEAAgE;AAChE,mEAAiE;AACjE,2DAAuD;AACvD,6CAMuB;AACvB,mDAAiD;AACjD,qEAA6E;AAC7E,qEAAmE;AACnE,6EAA0E;AAa1E;;;;GAIG;AACH,SAAS,uBAAuB,CAC9B,OAAuC,EACvC,SAA+C,EAC/C,gBAA0B,EAC1B,OAAgB;IAEhB,IAAI,CAAC,OAAO,EAAE;QACZ,OA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-restricted-globals */\nimport {\n BrowserClient,\n BrowserConfig,\n EnrichmentPlugin,\n FrustrationInteractionsOptions,\n DEFAULT_DATA_ATTRIBUTE_PREFIX,\n multicast,\n Observable,\n Unsubscribable,\n DEFAULT_RAGE_CLICK_ALLOWLIST,\n DEFAULT_DEAD_CLICK_ALLOWLIST,\n DEFAULT_ERROR_CLICK_ALLOWLIST,\n} from '@amplitude/analytics-core';\nimport * as constants from './constants';\nimport { createShouldTrackEvent, ElementBasedTimestampedEvent, NavigateEvent, TimestampedEvent } from './helpers';\nimport { trackDeadClick } from './autocapture/track-dead-click';\nimport { trackRageClicks } from './autocapture/track-rage-click';\nimport { ObservablesEnum } from './autocapture-plugin';\nimport {\n BrowserErrorEvent,\n createClickObservable,\n createErrorObservable,\n createMutationObservable,\n createMouseMoveObservable,\n} from './observables';\nimport { DataExtractor } from './data-extractor';\nimport { subscribeToElementSelectorConfig } from './element-selector-config';\nimport { trackErrorClicks } from './autocapture/track-error-click';\nimport { trackThrashedCursor } from './autocapture/track-thrashed-cursor';\n\nexport interface AllWindowObservables {\n [ObservablesEnum.ClickObservable]: Observable<ElementBasedTimestampedEvent<MouseEvent>>;\n [ObservablesEnum.MutationObservable]: Observable<TimestampedEvent<MutationRecord[]>>;\n [ObservablesEnum.BrowserErrorObservable]: Observable<TimestampedEvent<BrowserErrorEvent>>;\n [ObservablesEnum.NavigateObservable]?: Observable<TimestampedEvent<NavigateEvent>>;\n [ObservablesEnum.SelectionObservable]?: Observable<void>;\n [ObservablesEnum.MouseMoveObservable]: Observable<MouseEvent>;\n}\n\ntype BrowserEnrichmentPlugin = EnrichmentPlugin<BrowserClient, BrowserConfig>;\n\n/**\n * Helper function to extract the css selector allowlist\n * from the frustration interactions options for a specific\n * autocapture feature.\n */\nfunction getCssSelectorAllowlist(\n options: FrustrationInteractionsOptions,\n attribute: keyof FrustrationInteractionsOptions,\n defaultAllowlist: string[],\n enabled: boolean,\n): string[] {\n if (!enabled) {\n return [];\n }\n const config = options[attribute];\n if (\n typeof config === 'object' &&\n config !== null &&\n 'cssSelectorAllowlist' in config &&\n Array.isArray(config.cssSelectorAllowlist)\n ) {\n return config.cssSelectorAllowlist;\n }\n return defaultAllowlist;\n}\n\nconst MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES = 5;\nconst MAXIMUM_THRASHED_CURSOR_THRESHOLD = 4000;\n\nexport const frustrationPlugin = (options: FrustrationInteractionsOptions = {}): BrowserEnrichmentPlugin => {\n const name = constants.FRUSTRATION_PLUGIN_NAME;\n const type = 'enrichment';\n\n const subscriptions: Unsubscribable[] = [];\n\n let isErrorClicksEnabled = options.errorClicks !== false;\n\n // if errorClicks is not defined, disable it\n // change this once it moves out of @experimental\n if (!options.errorClicks) {\n isErrorClicksEnabled = false;\n }\n\n // Check if each feature is enabled\n const deadClicksEnabled = options.deadClicks !== false && options.deadClicks !== null;\n const rageClicksEnabled = options.rageClicks !== false && options.rageClicks !== null;\n\n let thrashedCursorEnabled = options.thrashedCursor !== false && options.thrashedCursor !== null;\n if (!options.thrashedCursor) {\n thrashedCursorEnabled = false;\n }\n\n // Get CSS selectors for enabled features\n const rageCssSelectors = getCssSelectorAllowlist(\n options,\n 'rageClicks',\n DEFAULT_RAGE_CLICK_ALLOWLIST,\n rageClicksEnabled,\n );\n\n const deadCssSelectors = getCssSelectorAllowlist(\n options,\n 'deadClicks',\n DEFAULT_DEAD_CLICK_ALLOWLIST,\n deadClicksEnabled,\n );\n\n const errorCssSelectors = getCssSelectorAllowlist(\n options,\n 'errorClicks',\n DEFAULT_ERROR_CLICK_ALLOWLIST,\n isErrorClicksEnabled,\n );\n\n const dataAttributePrefix = options.dataAttributePrefix ?? DEFAULT_DATA_ATTRIBUTE_PREFIX;\n\n const dataExtractor = new DataExtractor(options);\n\n // combine the selector lists from enabled features to determine which clicked elements should be filtered\n const combinedCssSelectors = [...new Set([...rageCssSelectors, ...deadCssSelectors, ...errorCssSelectors])];\n\n // Create observables on events on the window\n const createObservables = (): AllWindowObservables => {\n const clickObservable = multicast(\n createClickObservable('pointerdown').map((click) => {\n return dataExtractor.addAdditionalEventProperties(\n click,\n 'click',\n combinedCssSelectors,\n dataAttributePrefix,\n true, // capture when cursor is pointer\n );\n }),\n );\n\n const browserErrorObservables = multicast(\n createErrorObservable().map((error) => {\n return dataExtractor.addTypeAndTimestamp(error, 'error');\n }),\n );\n\n const enrichedMutationObservable = multicast<TimestampedEvent<MutationRecord[]>>(\n createMutationObservable().map((mutation) =>\n dataExtractor.addAdditionalEventProperties(mutation, 'mutation', combinedCssSelectors, dataAttributePrefix),\n ),\n );\n\n let enrichedNavigateObservable: Observable<TimestampedEvent<NavigateEvent>> | undefined;\n\n if (window.navigation) {\n const navigateObservable = new Observable<Event>((observer) => {\n const handler = (event: Event): void => {\n observer.next({\n ...event,\n type: 'navigate',\n });\n };\n window.navigation.addEventListener('navigate', handler);\n return () => {\n window.navigation.removeEventListener('navigate', handler);\n };\n });\n enrichedNavigateObservable = multicast<TimestampedEvent<NavigateEvent>>(\n navigateObservable.map<TimestampedEvent<NavigateEvent>>(\n (navigate) =>\n dataExtractor.addAdditionalEventProperties(\n navigate,\n 'navigate',\n combinedCssSelectors,\n dataAttributePrefix,\n ) as TimestampedEvent<NavigateEvent>,\n ),\n );\n }\n\n const selectionObservable = multicast(\n new Observable<void>((observer) => {\n const handler = () => {\n const el: HTMLElement | null = document.activeElement as HTMLElement;\n\n // handle input and textarea\n\n // if the selectionStart and selectionEnd are the same, it means\n // nothing is selected (collapsed) and the cursor position is one point\n if (el && (el.tagName === 'TEXTAREA' || el.tagName === 'INPUT')) {\n let start: number | null | undefined;\n let end: number | null | undefined;\n try {\n start = (el as HTMLInputElement | HTMLTextAreaElement).selectionStart;\n end = (el as HTMLInputElement | HTMLTextAreaElement).selectionEnd;\n if (start === end) return; // collapsed\n } catch (error) {\n // input that doesn't support selectionStart/selectionEnd (like checkbox)\n // do nothing here\n return;\n }\n return observer.next();\n }\n\n // handle non-input elements\n\n // non-input elements have an attribute called \"isCollapsed\" which\n // if true, indicates there \"is currently not any text selected\"\n // (see https://developer.mozilla.org/en-US/docs/Web/API/Selection/isCollapsed)\n const selection = window.getSelection();\n if (!selection || selection.isCollapsed) return;\n return observer.next();\n };\n window.document.addEventListener('selectionchange', handler);\n return () => {\n window.document.removeEventListener('selectionchange', handler);\n };\n }),\n );\n\n const mouseMoveObservable = multicast(createMouseMoveObservable());\n\n return {\n [ObservablesEnum.ClickObservable]: clickObservable as Observable<ElementBasedTimestampedEvent<MouseEvent>>,\n [ObservablesEnum.MutationObservable]: enrichedMutationObservable,\n [ObservablesEnum.NavigateObservable]: enrichedNavigateObservable,\n [ObservablesEnum.BrowserErrorObservable]: browserErrorObservables,\n [ObservablesEnum.SelectionObservable]: selectionObservable,\n [ObservablesEnum.MouseMoveObservable]: mouseMoveObservable,\n };\n };\n\n const setup: BrowserEnrichmentPlugin['setup'] = async (config, amplitude) => {\n /* istanbul ignore if */\n if (typeof document === 'undefined') {\n return;\n }\n\n // Create observables for events on the window\n const allObservables = createObservables();\n\n // Keep the data extractor's selector engine in sync with element-selector\n // remote config so frustration events emit the same selectors as the rest\n // of autocapture when an org enables the engine.\n const elementSelectorConfigCleanup = subscribeToElementSelectorConfig(config, dataExtractor);\n if (elementSelectorConfigCleanup) {\n subscriptions.push({ unsubscribe: elementSelectorConfigCleanup });\n }\n\n // Create subscriptions only for enabled features\n if (rageClicksEnabled) {\n const shouldTrackRageClick = createShouldTrackEvent(options, rageCssSelectors);\n const rageClickSubscription = trackRageClicks({\n allObservables,\n amplitude,\n shouldTrackRageClick,\n });\n subscriptions.push(rageClickSubscription);\n }\n\n if (deadClicksEnabled) {\n const shouldTrackDeadClick = createShouldTrackEvent(options, deadCssSelectors);\n const deadClickSubscription = trackDeadClick({\n amplitude,\n allObservables,\n getEventProperties: (actionType, element) =>\n dataExtractor.getEventProperties(actionType, element, dataAttributePrefix),\n shouldTrackDeadClick,\n });\n subscriptions.push(deadClickSubscription);\n }\n\n if (isErrorClicksEnabled) {\n const shouldTrackErrorClick = createShouldTrackEvent(options, errorCssSelectors);\n const errorClickSubscription = trackErrorClicks({\n amplitude,\n allObservables,\n shouldTrackErrorClick,\n });\n subscriptions.push(errorClickSubscription);\n }\n\n if (thrashedCursorEnabled) {\n let directionChanges, thresholdMs;\n if (typeof options.thrashedCursor === 'object') {\n directionChanges = options.thrashedCursor.directionChanges;\n thresholdMs = options.thrashedCursor.threshold;\n\n if (directionChanges && directionChanges < MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES) {\n config.loggerProvider.warn(\n `'thrashedCursor.directionChanges' of ${directionChanges} is below the minimum of ${MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES}, setting to ${MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES}`,\n );\n directionChanges = MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES;\n }\n if (thresholdMs && thresholdMs > MAXIMUM_THRASHED_CURSOR_THRESHOLD) {\n config.loggerProvider.warn(\n `'thrashedCursor.threshold' of ${thresholdMs} is above the maximum of ${MAXIMUM_THRASHED_CURSOR_THRESHOLD}, setting to ${MAXIMUM_THRASHED_CURSOR_THRESHOLD}`,\n );\n thresholdMs = MAXIMUM_THRASHED_CURSOR_THRESHOLD;\n }\n }\n const thrashedCursorSubscription = trackThrashedCursor({\n amplitude,\n options,\n allObservables,\n directionChanges,\n thresholdMs,\n });\n subscriptions.push(thrashedCursorSubscription);\n }\n\n /* istanbul ignore next */\n config?.loggerProvider?.log(`${name} has been successfully added.`);\n };\n\n const execute: BrowserEnrichmentPlugin['execute'] = async (event) => {\n return event;\n };\n\n const teardown = async () => {\n for (const subscription of subscriptions) {\n subscription.unsubscribe();\n }\n };\n\n return {\n name,\n type,\n setup,\n execute,\n teardown,\n };\n};\n"]}
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Backward-compat re-export.
|
|
3
|
-
*
|
|
4
|
-
* The Chromium-DevTools-derived `cssPath` walker that lived here for years
|
|
5
|
-
* has moved to `@amplitude/element-selector` as `legacyCssPath`. That's now
|
|
6
|
-
* the canonical home — the SDK and the dashboard both import from there,
|
|
7
|
-
* so the two can never drift again.
|
|
8
|
-
*
|
|
9
|
-
* This file stays around as a thin re-export so:
|
|
10
|
-
*
|
|
11
|
-
* - any third-party consumer that historically deep-imported `cssPath` from
|
|
12
|
-
* `@amplitude/plugin-autocapture-browser/src/libs/element-path` continues
|
|
13
|
-
* to work without code changes;
|
|
14
|
-
* - the autocapture plugin's own internals don't have to special-case the
|
|
15
|
-
* rename mid-PR (although `data-extractor` no longer uses it — all
|
|
16
|
-
* routing happens via `generateSelector` from the package).
|
|
17
|
-
*
|
|
18
|
-
* Slated for deletion in a future major once we've audited and confirmed no
|
|
19
|
-
* external imports remain.
|
|
20
|
-
*
|
|
21
|
-
* @deprecated Import `legacyCssPath` from `@amplitude/element-selector` directly.
|
|
22
|
-
*/
|
|
23
|
-
export { legacyCssPath as cssPath } from '@amplitude/element-selector';
|
|
1
|
+
export declare const cssPath: (node: Element, optimized?: boolean) => string;
|
|
24
2
|
//# sourceMappingURL=element-path.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-path.d.ts","sourceRoot":"","sources":["../../../src/libs/element-path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"element-path.d.ts","sourceRoot":"","sources":["../../../src/libs/element-path.ts"],"names":[],"mappings":"AAyCA,eAAO,MAAM,OAAO,SAAmB,OAAO,cAAc,OAAO,KAAG,MAuBrE,CAAC"}
|
|
@@ -1,32 +1,177 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* istanbul ignore file
|
|
3
|
-
runtime behavior of its own. The `legacyCssPath` algorithm is covered
|
|
4
|
-
exhaustively by `@amplitude/element-selector`'s own suite; re-running
|
|
5
|
-
coverage against the re-export adds nothing. */
|
|
2
|
+
/* istanbul ignore file */
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
4
|
exports.cssPath = void 0;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
var tslib_1 = require("tslib");
|
|
6
|
+
// Code is adapted from The Chromium Authors.
|
|
7
|
+
// Source: https://github.com/ChromeDevTools/devtools-frontend/blob/main/front_end/panels/elements/DOMPath.ts#L14
|
|
8
|
+
// License: BSD-style license
|
|
9
|
+
//
|
|
10
|
+
// Copyright 2014 The Chromium Authors
|
|
11
|
+
//
|
|
12
|
+
// Redistribution and use in source and binary forms, with or without
|
|
13
|
+
// modification, are permitted provided that the following conditions are
|
|
14
|
+
// met:
|
|
15
|
+
//
|
|
16
|
+
// * Redistributions of source code must retain the above copyright
|
|
17
|
+
// notice, this list of conditions and the following disclaimer.
|
|
18
|
+
// * Redistributions in binary form must reproduce the above
|
|
19
|
+
// copyright notice, this list of conditions and the following disclaimer
|
|
20
|
+
// in the documentation and/or other materials provided with the
|
|
21
|
+
// distribution.
|
|
22
|
+
// * Neither the name of Google Inc. nor the names of its
|
|
23
|
+
// contributors may be used to endorse or promote products derived from
|
|
24
|
+
// this software without specific prior written permission.
|
|
25
|
+
//
|
|
26
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
27
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
28
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
29
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
30
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
31
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
32
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
33
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
34
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
35
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
36
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
37
|
+
var Step = /** @class */ (function () {
|
|
38
|
+
function Step(value, optimized) {
|
|
39
|
+
this.value = value;
|
|
40
|
+
this.optimized = optimized;
|
|
41
|
+
}
|
|
42
|
+
Step.prototype.toString = function () {
|
|
43
|
+
return this.value;
|
|
44
|
+
};
|
|
45
|
+
return Step;
|
|
46
|
+
}());
|
|
47
|
+
var cssPath = function (node, optimized) {
|
|
48
|
+
// `node` is already an Element; this check is defensive.
|
|
49
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
var steps = [];
|
|
53
|
+
var contextNode = node;
|
|
54
|
+
while (contextNode) {
|
|
55
|
+
var step = cssPathStep(contextNode, Boolean(optimized), contextNode === node);
|
|
56
|
+
if (!step) {
|
|
57
|
+
break;
|
|
58
|
+
} // bail out early
|
|
59
|
+
steps.push(step);
|
|
60
|
+
if (step.optimized) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
contextNode = contextNode.parentElement;
|
|
64
|
+
}
|
|
65
|
+
steps.reverse();
|
|
66
|
+
return steps.join(' > ');
|
|
67
|
+
};
|
|
68
|
+
exports.cssPath = cssPath;
|
|
69
|
+
var cssPathStep = function (node, optimized, isTargetNode) {
|
|
70
|
+
var e_1, _a;
|
|
71
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
var id = node.getAttribute('id');
|
|
75
|
+
if (optimized) {
|
|
76
|
+
if (id) {
|
|
77
|
+
return new Step(idSelector(id), true);
|
|
78
|
+
}
|
|
79
|
+
var nodeNameLower = node.tagName.toLowerCase();
|
|
80
|
+
if (nodeNameLower === 'body' || nodeNameLower === 'head' || nodeNameLower === 'html') {
|
|
81
|
+
return new Step(nodeNameLower, true);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
var nodeName = node.tagName.toLowerCase();
|
|
85
|
+
if (id) {
|
|
86
|
+
return new Step(nodeName + idSelector(id), true);
|
|
87
|
+
}
|
|
88
|
+
var parent = node.parentNode;
|
|
89
|
+
if (!parent || parent.nodeType === Node.DOCUMENT_NODE) {
|
|
90
|
+
return new Step(nodeName, true);
|
|
91
|
+
}
|
|
92
|
+
function prefixedElementClassNames(el) {
|
|
93
|
+
var classAttribute = el.getAttribute('class');
|
|
94
|
+
if (!classAttribute) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
return classAttribute
|
|
98
|
+
.split(/\s+/g)
|
|
99
|
+
.filter(Boolean)
|
|
100
|
+
.map(function (name) {
|
|
101
|
+
// The prefix is required to store "__proto__" in a object-based map.
|
|
102
|
+
return '$' + name;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function idSelector(id) {
|
|
106
|
+
return '#' + CSS.escape(id);
|
|
107
|
+
}
|
|
108
|
+
var prefixedOwnClassNamesArray = prefixedElementClassNames(node);
|
|
109
|
+
var needsClassNames = false;
|
|
110
|
+
var needsNthChild = false;
|
|
111
|
+
var ownIndex = -1;
|
|
112
|
+
var elementIndex = -1;
|
|
113
|
+
var siblings = parent.children;
|
|
114
|
+
for (var i = 0; siblings && (ownIndex === -1 || !needsNthChild) && i < siblings.length; ++i) {
|
|
115
|
+
var sibling = siblings[i];
|
|
116
|
+
if (sibling.nodeType !== Node.ELEMENT_NODE) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
elementIndex += 1;
|
|
120
|
+
if (sibling === node) {
|
|
121
|
+
ownIndex = elementIndex;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (needsNthChild) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (sibling.tagName.toLowerCase() !== nodeName) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
needsClassNames = true;
|
|
131
|
+
var ownClassNames = new Set(prefixedOwnClassNamesArray);
|
|
132
|
+
if (!ownClassNames.size) {
|
|
133
|
+
needsNthChild = true;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
var siblingClassNamesArray = prefixedElementClassNames(sibling);
|
|
137
|
+
for (var j = 0; j < siblingClassNamesArray.length; ++j) {
|
|
138
|
+
var siblingClass = siblingClassNamesArray[j];
|
|
139
|
+
if (!ownClassNames.has(siblingClass)) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
ownClassNames.delete(siblingClass);
|
|
143
|
+
if (!ownClassNames.size) {
|
|
144
|
+
needsNthChild = true;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
var result = nodeName;
|
|
150
|
+
if (isTargetNode &&
|
|
151
|
+
nodeName.toLowerCase() === 'input' &&
|
|
152
|
+
node.getAttribute('type') &&
|
|
153
|
+
!node.getAttribute('id') &&
|
|
154
|
+
!node.getAttribute('class')) {
|
|
155
|
+
result += '[type=' + CSS.escape(node.getAttribute('type') || '') + ']';
|
|
156
|
+
}
|
|
157
|
+
if (needsNthChild) {
|
|
158
|
+
result += ':nth-child(' + String(ownIndex + 1) + ')';
|
|
159
|
+
}
|
|
160
|
+
else if (needsClassNames) {
|
|
161
|
+
try {
|
|
162
|
+
for (var prefixedOwnClassNamesArray_1 = tslib_1.__values(prefixedOwnClassNamesArray), prefixedOwnClassNamesArray_1_1 = prefixedOwnClassNamesArray_1.next(); !prefixedOwnClassNamesArray_1_1.done; prefixedOwnClassNamesArray_1_1 = prefixedOwnClassNamesArray_1.next()) {
|
|
163
|
+
var prefixedName = prefixedOwnClassNamesArray_1_1.value;
|
|
164
|
+
result += '.' + CSS.escape(prefixedName.slice(1));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
168
|
+
finally {
|
|
169
|
+
try {
|
|
170
|
+
if (prefixedOwnClassNamesArray_1_1 && !prefixedOwnClassNamesArray_1_1.done && (_a = prefixedOwnClassNamesArray_1.return)) _a.call(prefixedOwnClassNamesArray_1);
|
|
171
|
+
}
|
|
172
|
+
finally { if (e_1) throw e_1.error; }
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return new Step(result, false);
|
|
176
|
+
};
|
|
32
177
|
//# sourceMappingURL=element-path.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-path.js","sourceRoot":"","sources":["../../../src/libs/element-path.ts"],"names":[],"mappings":";AAAA;;;kDAGkD;;;AAElD;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,gEAAuE;AAA9D,2GAAA,aAAa,OAAW","sourcesContent":["/* istanbul ignore file -- This file is a deprecated thin re-export with no\n runtime behavior of its own. The `legacyCssPath` algorithm is covered\n exhaustively by `@amplitude/element-selector`'s own suite; re-running\n coverage against the re-export adds nothing. */\n\n/**\n * Backward-compat re-export.\n *\n * The Chromium-DevTools-derived `cssPath` walker that lived here for years\n * has moved to `@amplitude/element-selector` as `legacyCssPath`. That's now\n * the canonical home — the SDK and the dashboard both import from there,\n * so the two can never drift again.\n *\n * This file stays around as a thin re-export so:\n *\n * - any third-party consumer that historically deep-imported `cssPath` from\n * `@amplitude/plugin-autocapture-browser/src/libs/element-path` continues\n * to work without code changes;\n * - the autocapture plugin's own internals don't have to special-case the\n * rename mid-PR (although `data-extractor` no longer uses it — all\n * routing happens via `generateSelector` from the package).\n *\n * Slated for deletion in a future major once we've audited and confirmed no\n * external imports remain.\n *\n * @deprecated Import `legacyCssPath` from `@amplitude/element-selector` directly.\n */\n\nexport { legacyCssPath as cssPath } from '@amplitude/element-selector';\n"]}
|
|
1
|
+
{"version":3,"file":"element-path.js","sourceRoot":"","sources":["../../../src/libs/element-path.ts"],"names":[],"mappings":";AAAA,0BAA0B;;;;AAE1B,6CAA6C;AAC7C,iHAAiH;AACjH,6BAA6B;AAC7B,EAAE;AACF,sCAAsC;AACtC,EAAE;AACF,qEAAqE;AACrE,yEAAyE;AACzE,OAAO;AACP,EAAE;AACF,sEAAsE;AACtE,gEAAgE;AAChE,+DAA+D;AAC/D,yEAAyE;AACzE,gEAAgE;AAChE,gBAAgB;AAChB,4DAA4D;AAC5D,uEAAuE;AACvE,2DAA2D;AAC3D,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,wEAAwE;AACxE,uEAAuE;AACvE,wEAAwE;AACxE,mEAAmE;AACnE,wEAAwE;AACxE,wEAAwE;AACxE,sEAAsE;AACtE,wEAAwE;AACxE,uEAAuE;AAEvE;IACE,cAAmB,KAAa,EAAS,SAAkB;QAAxC,UAAK,GAAL,KAAK,CAAQ;QAAS,cAAS,GAAT,SAAS,CAAS;IAAG,CAAC;IAC/D,uBAAQ,GAAR;QACE,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IACH,WAAC;AAAD,CAAC,AALD,IAKC;AAEM,IAAM,OAAO,GAAG,UAAU,IAAa,EAAE,SAAmB;IACjE,yDAAyD;IACzD,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,EAAE;QACvC,OAAO,EAAE,CAAC;KACX;IAED,IAAM,KAAK,GAAW,EAAE,CAAC;IACzB,IAAI,WAAW,GAAmB,IAAI,CAAC;IAEvC,OAAO,WAAW,EAAE;QACl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jB,MAAM,IAAI,aAAa,GAAG,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;KACtD;SAAM,IAAI,eAAe,EAAE;;YAC1B,KAA2B,IAAA,+BAAA,iBAAA,0BAA0B,CAAA,sEAAA,8GAAE;gBAAlD,IAAM,YAAY,uCAAA;gBACrB,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;aACnD;;;;;;;;;KACF;IAED,OAAO,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC,CAAC","sourcesContent":["/* istanbul ignore file */\n\n// Code is adapted from The Chromium Authors.\n// Source: https://github.com/ChromeDevTools/devtools-frontend/blob/main/front_end/panels/elements/DOMPath.ts#L14\n// License: BSD-style license\n//\n// Copyright 2014 The Chromium Authors\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n// * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n// * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n// * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\nclass Step {\n constructor(public value: string, public optimized: boolean) {}\n toString() {\n return this.value;\n }\n}\n\nexport const cssPath = function (node: Element, optimized?: boolean): string {\n // `node` is already an Element; this check is defensive.\n if (node.nodeType !== Node.ELEMENT_NODE) {\n return '';\n }\n\n const steps: Step[] = [];\n let contextNode: Element | null = node;\n\n while (contextNode) {\n const step = cssPathStep(contextNode, Boolean(optimized), contextNode === node);\n if (!step) {\n break;\n } // bail out early\n steps.push(step);\n if (step.optimized) {\n break;\n }\n contextNode = contextNode.parentElement;\n }\n\n steps.reverse();\n return steps.join(' > ');\n};\n\nconst cssPathStep = function (node: Element, optimized: boolean, isTargetNode: boolean): Step | null {\n if (node.nodeType !== Node.ELEMENT_NODE) {\n return null;\n }\n\n const id = node.getAttribute('id');\n if (optimized) {\n if (id) {\n return new Step(idSelector(id), true);\n }\n\n const nodeNameLower = node.tagName.toLowerCase();\n if (nodeNameLower === 'body' || nodeNameLower === 'head' || nodeNameLower === 'html') {\n return new Step(nodeNameLower, true);\n }\n }\n\n const nodeName = node.tagName.toLowerCase();\n\n if (id) {\n return new Step(nodeName + idSelector(id), true);\n }\n\n const parent = node.parentNode;\n if (!parent || parent.nodeType === Node.DOCUMENT_NODE) {\n return new Step(nodeName, true);\n }\n\n function prefixedElementClassNames(el: Element): string[] {\n const classAttribute = el.getAttribute('class');\n if (!classAttribute) {\n return [];\n }\n return classAttribute\n .split(/\\s+/g)\n .filter(Boolean)\n .map(function (name) {\n // The prefix is required to store \"__proto__\" in a object-based map.\n return '$' + name;\n });\n }\n\n function idSelector(id: string): string {\n return '#' + CSS.escape(id);\n }\n\n const prefixedOwnClassNamesArray = prefixedElementClassNames(node);\n let needsClassNames = false;\n let needsNthChild = false;\n let ownIndex = -1;\n let elementIndex = -1;\n\n const siblings: HTMLCollectionOf<Element> = parent.children;\n\n for (let i = 0; siblings && (ownIndex === -1 || !needsNthChild) && i < siblings.length; ++i) {\n const sibling = siblings[i];\n if (sibling.nodeType !== Node.ELEMENT_NODE) {\n continue;\n }\n\n elementIndex += 1;\n if (sibling === node) {\n ownIndex = elementIndex;\n continue;\n }\n if (needsNthChild) {\n continue;\n }\n\n if (sibling.tagName.toLowerCase() !== nodeName) {\n continue;\n }\n\n needsClassNames = true;\n const ownClassNames = new Set<string>(prefixedOwnClassNamesArray);\n if (!ownClassNames.size) {\n needsNthChild = true;\n continue;\n }\n\n const siblingClassNamesArray = prefixedElementClassNames(sibling);\n for (let j = 0; j < siblingClassNamesArray.length; ++j) {\n const siblingClass = siblingClassNamesArray[j];\n if (!ownClassNames.has(siblingClass)) {\n continue;\n }\n ownClassNames.delete(siblingClass);\n if (!ownClassNames.size) {\n needsNthChild = true;\n break;\n }\n }\n }\n\n let result = nodeName;\n if (\n isTargetNode &&\n nodeName.toLowerCase() === 'input' &&\n node.getAttribute('type') &&\n !node.getAttribute('id') &&\n !node.getAttribute('class')\n ) {\n result += '[type=' + CSS.escape(node.getAttribute('type') || '') + ']';\n }\n if (needsNthChild) {\n result += ':nth-child(' + String(ownIndex + 1) + ')';\n } else if (needsClassNames) {\n for (const prefixedName of prefixedOwnClassNamesArray) {\n result += '.' + CSS.escape(prefixedName.slice(1));\n }\n }\n\n return new Step(result, false);\n};\n"]}
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.28.0
|
|
1
|
+
export declare const VERSION = "1.28.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/cjs/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAC"}
|
package/lib/cjs/version.js
CHANGED
package/lib/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '1.28.0';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocapture-plugin.d.ts","sourceRoot":"","sources":["../../src/autocapture-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,0BAA0B,EAK/B,kBAAkB,EAKnB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAEL,KAAK,4BAA4B,EACjC,KAAK,gBAAgB,EACrB,KAAK,aAAa,EACnB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"autocapture-plugin.d.ts","sourceRoot":"","sources":["../../src/autocapture-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,0BAA0B,EAK/B,kBAAkB,EAKnB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAEL,KAAK,4BAA4B,EACjC,KAAK,gBAAgB,EACrB,KAAK,aAAa,EACnB,MAAM,WAAW,CAAC;AAqBnB,OAAO,EAAE,UAAU,EAAkB,MAAM,2BAA2B,CAAC;AAIvE,KAA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D,CAAC,eAAe,CAAC,kBAAkB,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED,eAAO,MAAM,iBAAiB,aACnB,0BAA0B,YACzB;IAAE,iBAAiB,EAAE,kBAAkB,CAAA;CAAE,KAClD,uBAwYF,CAAC"}
|
|
@@ -12,69 +12,10 @@ import { trackScroll } from './autocapture/track-scroll';
|
|
|
12
12
|
import { createClickObservable, createScrollObservable, createExposureObservable, createMutationObservable, } from './observables';
|
|
13
13
|
import { createLabeledEventToTriggerMap, createTriggerEvaluator, groupLabeledEventIdsByEventType, } from './pageActions/triggers';
|
|
14
14
|
import { DataExtractor } from './data-extractor';
|
|
15
|
+
import { subscribeToElementSelectorConfig } from './element-selector-config';
|
|
15
16
|
import { Observable } from '@amplitude/analytics-core';
|
|
16
|
-
import { createSelectorEngine, resolveSelectorConfig, } from '@amplitude/element-selector';
|
|
17
17
|
import { trackExposure } from './autocapture/track-exposure';
|
|
18
18
|
import { fireViewportContentUpdated, onExposure } from './autocapture/track-viewport-content-updated';
|
|
19
|
-
var subscribeRemoteConfig = function (config, key, callback) {
|
|
20
|
-
var remoteConfigClient = config.remoteConfigClient;
|
|
21
|
-
if (!remoteConfigClient) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
var subscriptionId = remoteConfigClient.subscribe(key, 'all', callback);
|
|
25
|
-
return {
|
|
26
|
-
unsubscribe: function () {
|
|
27
|
-
remoteConfigClient.unsubscribe(subscriptionId);
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
var attachElementSelectorSurface = function (amplitude, selectorEngine) {
|
|
32
|
-
// Expose a narrowed, read-only surface of the engine on the customer's
|
|
33
|
-
// BrowserClient instance so downstream consumers can use the same engine the
|
|
34
|
-
// SDK is running. Attach to the instance, not window.amplitude, so custom
|
|
35
|
-
// global names and multiple SDK instances do not clobber each other.
|
|
36
|
-
var elementSelectorClient = amplitude;
|
|
37
|
-
var hadPreviousElementSelector = Object.prototype.hasOwnProperty.call(elementSelectorClient, 'elementSelector');
|
|
38
|
-
var previousElementSelector = elementSelectorClient.elementSelector;
|
|
39
|
-
var elementSelectorSurface = {
|
|
40
|
-
generate: function (el) { return selectorEngine.generate(el); },
|
|
41
|
-
getConfig: function () { return selectorEngine.getConfig(); },
|
|
42
|
-
onConfigChange: function (cb) { return selectorEngine.onConfigChange(cb); },
|
|
43
|
-
};
|
|
44
|
-
/* istanbul ignore next */
|
|
45
|
-
elementSelectorClient.elementSelector = elementSelectorSurface;
|
|
46
|
-
return {
|
|
47
|
-
unsubscribe: function () {
|
|
48
|
-
if (hadPreviousElementSelector) {
|
|
49
|
-
elementSelectorClient.elementSelector = previousElementSelector;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
delete elementSelectorClient.elementSelector;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
var setupElementSelector = function (config, amplitude, dataExtractor) {
|
|
58
|
-
var subscriptions = [];
|
|
59
|
-
// Construct the engine eagerly with defaults so `dataExtractor.getElementPath`
|
|
60
|
-
// can route through it from the first emission. When `enabled` is false in
|
|
61
|
-
// the resolved config (the default), `getElementPath` falls back to the
|
|
62
|
-
// legacy `cssPath` algorithm.
|
|
63
|
-
var initialSelectorConfig = resolveSelectorConfig(undefined, config.loggerProvider);
|
|
64
|
-
var selectorEngine = createSelectorEngine(initialSelectorConfig, { logger: config.loggerProvider });
|
|
65
|
-
dataExtractor.setSelectorEngine(selectorEngine);
|
|
66
|
-
subscriptions.push(attachElementSelectorSurface(amplitude, selectorEngine));
|
|
67
|
-
if (config.fetchRemoteConfig) {
|
|
68
|
-
var elementSelectorSubscription = subscribeRemoteConfig(config, 'configs.analyticsSDK.autocapture.elementSelector', function (remoteSelectorConfig) {
|
|
69
|
-
var nextResolved = resolveSelectorConfig(remoteSelectorConfig, config.loggerProvider);
|
|
70
|
-
selectorEngine.updateConfig(nextResolved);
|
|
71
|
-
});
|
|
72
|
-
if (elementSelectorSubscription) {
|
|
73
|
-
subscriptions.push(elementSelectorSubscription);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return subscriptions;
|
|
77
|
-
};
|
|
78
19
|
export var ObservablesEnum;
|
|
79
20
|
(function (ObservablesEnum) {
|
|
80
21
|
ObservablesEnum["ClickObservable"] = "clickObservable";
|
|
@@ -195,7 +136,7 @@ export var autocapturePlugin = function (options, context) {
|
|
|
195
136
|
}
|
|
196
137
|
};
|
|
197
138
|
var setup = function (config, amplitude) { return __awaiter(void 0, void 0, void 0, function () {
|
|
198
|
-
var pageViewEndFired, lastScroll,
|
|
139
|
+
var pageViewEndFired, lastScroll, elementSelectorConfigCleanup, shouldTrackEvent, shouldTrackActionClick, allObservables, clickTrackingSubscription, changeSubscription, actionClickSubscription, scrollTracker, trackers, globalScope, handleViewportContentUpdated, handleExposure, beforeUnloadHandler_1, navigateObservable, popstateHandler_1, originalPushState_1, allowlist, actionClickAllowlist, messenger;
|
|
199
140
|
var _a;
|
|
200
141
|
return __generator(this, function (_b) {
|
|
201
142
|
/* istanbul ignore if */
|
|
@@ -211,15 +152,15 @@ export var autocapturePlugin = function (options, context) {
|
|
|
211
152
|
config.loggerProvider.debug('Remote config client is not provided, skipping remote config fetch');
|
|
212
153
|
}
|
|
213
154
|
else {
|
|
214
|
-
|
|
155
|
+
config.remoteConfigClient.subscribe('configs.analyticsSDK.pageActions', 'all', function (remoteConfig) {
|
|
215
156
|
recomputePageActionsData(remoteConfig);
|
|
216
157
|
});
|
|
217
|
-
if (pageActionsSubscription) {
|
|
218
|
-
subscriptions.push(pageActionsSubscription);
|
|
219
|
-
}
|
|
220
158
|
}
|
|
221
159
|
}
|
|
222
|
-
|
|
160
|
+
elementSelectorConfigCleanup = subscribeToElementSelectorConfig(config, dataExtractor);
|
|
161
|
+
if (elementSelectorConfigCleanup) {
|
|
162
|
+
subscriptions.push({ unsubscribe: elementSelectorConfigCleanup });
|
|
163
|
+
}
|
|
223
164
|
shouldTrackEvent = createShouldTrackEvent(options, options.cssSelectorAllowlist);
|
|
224
165
|
shouldTrackActionClick = createShouldTrackEvent(options, options.actionClickAllowlist);
|
|
225
166
|
allObservables = createObservables();
|