@amplitude/plugin-autocapture-browser
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.0-beta.2
import { Logger } from '@amplitude/analytics-types'; | ||
export type JSONValue = string | number | boolean | { | ||
export type JSONValue = string | number | boolean | null | { | ||
[x: string]: JSONValue; | ||
@@ -4,0 +4,0 @@ } | Array<JSONValue>; |
@@ -0,1 +1,2 @@ | ||
import { JSONValue } from './helpers'; | ||
import { Hierarchy, HierarchyNode } from './typings/autocapture'; | ||
@@ -5,2 +6,12 @@ export declare function getElementProperties(element: Element | null): HierarchyNode | null; | ||
export declare const getHierarchy: (element: Element | null) => Hierarchy; | ||
export declare function ensureListUnderLimit(list: Hierarchy | JSONValue[], bytesLimit: number): Hierarchy | JSONValue[]; | ||
/** | ||
* Converts a JSON-compatible value to a Python-compatible string representation. | ||
* This function handles various data types and ensures proper escaping and formatting. | ||
* | ||
* @param value - The value to be converted (can be any JSON-compatible type) | ||
* @param nested - Indicates if the value is nested within another structure (default: false) | ||
* @returns A string representation of the value compatible with Python, or null if conversion fails | ||
*/ | ||
export declare function ensureUnicodePythonCompatible(value: HierarchyNode | JSONValue | null, nested?: boolean): string | null; | ||
//# sourceMappingURL=hierarchy.d.ts.map |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getHierarchy = exports.getAncestors = exports.getElementProperties = void 0; | ||
exports.ensureUnicodePythonCompatible = exports.ensureListUnderLimit = exports.getHierarchy = exports.getAncestors = exports.getElementProperties = void 0; | ||
var tslib_1 = require("tslib"); | ||
@@ -108,23 +108,102 @@ var helpers_1 = require("./helpers"); | ||
var getHierarchy = function (element) { | ||
var outChars = 2; | ||
var hierarchy = []; | ||
if (!element) { | ||
return hierarchy; | ||
return []; | ||
} | ||
// Get list of ancestors including itself and get properties at each level in the hierarchy | ||
var ancestors = getAncestors(element); | ||
for (var i = 0; i < ancestors.length; i++) { | ||
var elProperties = getElementProperties(ancestors[i]); | ||
var elPropertiesLength = JSON.stringify(elProperties).length; | ||
// If adding the next ancestor would exceed the max hierarchy length, stop | ||
var commaLength = i > 0 ? 1 : 0; | ||
if (outChars + elPropertiesLength + commaLength > MAX_HIERARCHY_LENGTH) { | ||
break; | ||
} | ||
outChars += elPropertiesLength + commaLength; | ||
hierarchy.unshift(elProperties); | ||
} | ||
hierarchy = ensureListUnderLimit(ancestors.map(function (el) { return getElementProperties(el); }), MAX_HIERARCHY_LENGTH); | ||
return hierarchy; | ||
}; | ||
exports.getHierarchy = getHierarchy; | ||
function ensureListUnderLimit(list, bytesLimit) { | ||
var numChars = 0; | ||
for (var i = 0; i < list.length; i++) { | ||
var node = list[i]; | ||
if (node === null) { | ||
// simulate 'None' in python | ||
numChars += 4; | ||
} | ||
else { | ||
var value = ensureUnicodePythonCompatible(node); | ||
// Using Array.from(string).length instead of string.length | ||
// to correctly count Unicode characters (including emojis) | ||
numChars += value ? Array.from(value).length : 4; | ||
} | ||
if (numChars > bytesLimit) { | ||
return list.slice(0, i); | ||
} | ||
} | ||
return list; | ||
} | ||
exports.ensureListUnderLimit = ensureListUnderLimit; | ||
/** | ||
* Converts a JSON-compatible value to a Python-compatible string representation. | ||
* This function handles various data types and ensures proper escaping and formatting. | ||
* | ||
* @param value - The value to be converted (can be any JSON-compatible type) | ||
* @param nested - Indicates if the value is nested within another structure (default: false) | ||
* @returns A string representation of the value compatible with Python, or null if conversion fails | ||
*/ | ||
function ensureUnicodePythonCompatible(value, nested) { | ||
if (nested === void 0) { nested = false; } | ||
try { | ||
if (value == null) { | ||
// Handle null values | ||
if (nested) { | ||
return 'None'; // Represent null as 'None' in Python when nested | ||
} | ||
return null; // Return null for top-level null values | ||
} | ||
else if (typeof value === 'string') { | ||
if (nested) { | ||
// Escape special characters in nested strings | ||
value = value.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r'); | ||
// Handle quotes in the string | ||
if (value.includes('"')) { | ||
return "'".concat(value, "'"); // Wrap in single quotes if it contains double quotes | ||
} | ||
if (value.includes("'")) { | ||
return "\"".concat(value.replace(/'/g, "\\'"), "\""); // Wrap in double quotes and escape single quotes | ||
} | ||
return "'".concat(value, "'"); // Default to wrapping in single quotes | ||
} | ||
return value; // Return non-nested strings as-is | ||
} | ||
else if (typeof value === 'boolean') { | ||
// Convert boolean to Python-style capitalized string | ||
return value ? 'True' : 'False'; | ||
} | ||
else if (Array.isArray(value)) { | ||
// Handle arrays by recursively converting each element | ||
var elements = value.map(function (o) { return ensureUnicodePythonCompatible(o, true); }); | ||
return "[".concat(elements.join(', '), "]"); | ||
} | ||
else if (typeof value === 'object') { | ||
// Handle objects (dictionaries in Python) | ||
var entries = Object.entries(value) | ||
.filter(function (_a) { | ||
var _b = tslib_1.__read(_a, 1), key = _b[0]; | ||
return key != null; | ||
}) // Filter out null keys | ||
.map(function (_a) { | ||
var _b = tslib_1.__read(_a, 2), key = _b[0], val = _b[1]; | ||
return "".concat(String(ensureUnicodePythonCompatible(key, true)), ": ").concat(String(ensureUnicodePythonCompatible(val, true))); | ||
}); | ||
var result = "{".concat(entries.join(', '), "}"); | ||
// Handle single quotes in the resulting string | ||
if (result.includes("\\'")) { | ||
result = result.replace(/'/g, "'").replace(/'/g, "\\'"); | ||
} | ||
return result; | ||
} | ||
// For any other types, return their string representation; | ||
return value.toString(); | ||
} | ||
catch (e) { | ||
// Return null if any error occurs during the conversion | ||
return null; | ||
} | ||
} | ||
exports.ensureUnicodePythonCompatible = ensureUnicodePythonCompatible; | ||
//# sourceMappingURL=hierarchy.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "1.0.0-beta.0"; | ||
export declare const VERSION = "1.0.0-beta.1"; | ||
//# sourceMappingURL=version.d.ts.map |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VERSION = void 0; | ||
exports.VERSION = '1.0.0-beta.0'; | ||
exports.VERSION = '1.0.0-beta.1'; | ||
//# sourceMappingURL=version.js.map |
import { Logger } from '@amplitude/analytics-types'; | ||
export type JSONValue = string | number | boolean | { | ||
export type JSONValue = string | number | boolean | null | { | ||
[x: string]: JSONValue; | ||
@@ -4,0 +4,0 @@ } | Array<JSONValue>; |
@@ -0,1 +1,2 @@ | ||
import { JSONValue } from './helpers'; | ||
import { Hierarchy, HierarchyNode } from './typings/autocapture'; | ||
@@ -5,2 +6,12 @@ export declare function getElementProperties(element: Element | null): HierarchyNode | null; | ||
export declare const getHierarchy: (element: Element | null) => Hierarchy; | ||
export declare function ensureListUnderLimit(list: Hierarchy | JSONValue[], bytesLimit: number): Hierarchy | JSONValue[]; | ||
/** | ||
* Converts a JSON-compatible value to a Python-compatible string representation. | ||
* This function handles various data types and ensures proper escaping and formatting. | ||
* | ||
* @param value - The value to be converted (can be any JSON-compatible type) | ||
* @param nested - Indicates if the value is nested within another structure (default: false) | ||
* @returns A string representation of the value compatible with Python, or null if conversion fails | ||
*/ | ||
export declare function ensureUnicodePythonCompatible(value: HierarchyNode | JSONValue | null, nested?: boolean): string | null; | ||
//# sourceMappingURL=hierarchy.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { __values } from "tslib"; | ||
import { __read, __values } from "tslib"; | ||
import { isNonSensitiveElement } from './helpers'; | ||
@@ -104,22 +104,99 @@ var BLOCKED_ATTRIBUTES = [ | ||
export var getHierarchy = function (element) { | ||
var outChars = 2; | ||
var hierarchy = []; | ||
if (!element) { | ||
return hierarchy; | ||
return []; | ||
} | ||
// Get list of ancestors including itself and get properties at each level in the hierarchy | ||
var ancestors = getAncestors(element); | ||
for (var i = 0; i < ancestors.length; i++) { | ||
var elProperties = getElementProperties(ancestors[i]); | ||
var elPropertiesLength = JSON.stringify(elProperties).length; | ||
// If adding the next ancestor would exceed the max hierarchy length, stop | ||
var commaLength = i > 0 ? 1 : 0; | ||
if (outChars + elPropertiesLength + commaLength > MAX_HIERARCHY_LENGTH) { | ||
break; | ||
hierarchy = ensureListUnderLimit(ancestors.map(function (el) { return getElementProperties(el); }), MAX_HIERARCHY_LENGTH); | ||
return hierarchy; | ||
}; | ||
export function ensureListUnderLimit(list, bytesLimit) { | ||
var numChars = 0; | ||
for (var i = 0; i < list.length; i++) { | ||
var node = list[i]; | ||
if (node === null) { | ||
// simulate 'None' in python | ||
numChars += 4; | ||
} | ||
outChars += elPropertiesLength + commaLength; | ||
hierarchy.unshift(elProperties); | ||
else { | ||
var value = ensureUnicodePythonCompatible(node); | ||
// Using Array.from(string).length instead of string.length | ||
// to correctly count Unicode characters (including emojis) | ||
numChars += value ? Array.from(value).length : 4; | ||
} | ||
if (numChars > bytesLimit) { | ||
return list.slice(0, i); | ||
} | ||
} | ||
return hierarchy; | ||
}; | ||
return list; | ||
} | ||
/** | ||
* Converts a JSON-compatible value to a Python-compatible string representation. | ||
* This function handles various data types and ensures proper escaping and formatting. | ||
* | ||
* @param value - The value to be converted (can be any JSON-compatible type) | ||
* @param nested - Indicates if the value is nested within another structure (default: false) | ||
* @returns A string representation of the value compatible with Python, or null if conversion fails | ||
*/ | ||
export function ensureUnicodePythonCompatible(value, nested) { | ||
if (nested === void 0) { nested = false; } | ||
try { | ||
if (value == null) { | ||
// Handle null values | ||
if (nested) { | ||
return 'None'; // Represent null as 'None' in Python when nested | ||
} | ||
return null; // Return null for top-level null values | ||
} | ||
else if (typeof value === 'string') { | ||
if (nested) { | ||
// Escape special characters in nested strings | ||
value = value.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r'); | ||
// Handle quotes in the string | ||
if (value.includes('"')) { | ||
return "'".concat(value, "'"); // Wrap in single quotes if it contains double quotes | ||
} | ||
if (value.includes("'")) { | ||
return "\"".concat(value.replace(/'/g, "\\'"), "\""); // Wrap in double quotes and escape single quotes | ||
} | ||
return "'".concat(value, "'"); // Default to wrapping in single quotes | ||
} | ||
return value; // Return non-nested strings as-is | ||
} | ||
else if (typeof value === 'boolean') { | ||
// Convert boolean to Python-style capitalized string | ||
return value ? 'True' : 'False'; | ||
} | ||
else if (Array.isArray(value)) { | ||
// Handle arrays by recursively converting each element | ||
var elements = value.map(function (o) { return ensureUnicodePythonCompatible(o, true); }); | ||
return "[".concat(elements.join(', '), "]"); | ||
} | ||
else if (typeof value === 'object') { | ||
// Handle objects (dictionaries in Python) | ||
var entries = Object.entries(value) | ||
.filter(function (_a) { | ||
var _b = __read(_a, 1), key = _b[0]; | ||
return key != null; | ||
}) // Filter out null keys | ||
.map(function (_a) { | ||
var _b = __read(_a, 2), key = _b[0], val = _b[1]; | ||
return "".concat(String(ensureUnicodePythonCompatible(key, true)), ": ").concat(String(ensureUnicodePythonCompatible(val, true))); | ||
}); | ||
var result = "{".concat(entries.join(', '), "}"); | ||
// Handle single quotes in the resulting string | ||
if (result.includes("\\'")) { | ||
result = result.replace(/'/g, "'").replace(/'/g, "\\'"); | ||
} | ||
return result; | ||
} | ||
// For any other types, return their string representation; | ||
return value.toString(); | ||
} | ||
catch (e) { | ||
// Return null if any error occurs during the conversion | ||
return null; | ||
} | ||
} | ||
//# sourceMappingURL=hierarchy.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "1.0.0-beta.0"; | ||
export declare const VERSION = "1.0.0-beta.1"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export var VERSION = '1.0.0-beta.0'; | ||
export var VERSION = '1.0.0-beta.1'; | ||
//# sourceMappingURL=version.js.map |
@@ -1,1 +0,1 @@ | ||
var amplitudeAutocapturePlugin=function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},t.apply(this,arguments)};function n(e,t,n,r){return new(n||(n=Promise))((function(o,i){function l(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}u((r=r.apply(e,t||[])).next())}))}function r(e,t){var n,r,o,i,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(l=0)),l;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=l.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=t.call(e,l)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function o(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),l=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)l.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return l}function l(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}var a,u,c="[Amplitude] Element Tag",d="[Amplitude] Element Text",s="[Amplitude] Element Selector",f="[Amplitude] Page URL",v="https://app.amplitude.com",p={US:v,EU:"https://app.eu.amplitude.com",STAGING:"https://apps.stag2.amplitude.com"},g="amp-visual-tagging-selector-highlight";function h(e,n){if(e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";var r={root:document.body,idName:function(e){return!0},className:function(e){return!0},tagName:function(e){return!0},attr:function(e,t){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};a=t(t({},r),n),u=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(a.root,r);var o=m(e,"all",(function(){return m(e,"two",(function(){return m(e,"one",(function(){return m(e,"none")}))}))}));if(o){var i=C(L(o,e));return i.length>0&&(o=i[0]),w(o)}throw new Error("Selector was not found.")}function m(e,t,n){for(var r=null,u=[],c=e,d=0,s=function(){var e,s,f=k(function(e){var t=e.getAttribute("id");if(t&&a.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(c))||k.apply(void 0,l([],i(function(e){var t=Array.from(e.attributes).filter((function(e){return a.attr(e.name,e.value)}));return t.map((function(e){return{name:"[".concat(CSS.escape(e.name),'="').concat(CSS.escape(e.value),'"]'),penalty:.5}}))}(c)),!1))||k.apply(void 0,l([],i(function(e){var t=Array.from(e.classList).filter(a.className);return t.map((function(e){return{name:"."+CSS.escape(e),penalty:1}}))}(c)),!1))||k(function(e){var t=e.tagName.toLowerCase();if(a.tagName(t))return{name:t,penalty:2};return null}(c))||[{name:"*",penalty:3}],v=function(e){var t=e.parentNode;if(!t)return null;var n=t.firstChild;if(!n)return null;var r=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&r++,n!==e);)n=n.nextSibling;return r}(c);if("all"==t)v&&(f=f.concat(f.filter(A).map((function(e){return S(e,v)}))));else if("two"==t)f=f.slice(0,1),v&&(f=f.concat(f.filter(A).map((function(e){return S(e,v)}))));else if("one"==t){var p=i(f=f.slice(0,1),1)[0];v&&A(p)&&(f=[S(p,v)])}else"none"==t&&(f=[{name:"*",penalty:3}],v&&(f=[S(f[0],v)]));try{for(var g=(e=void 0,o(f)),h=g.next();!h.done;h=g.next()){(p=h.value).level=d}}catch(t){e={error:t}}finally{try{h&&!h.done&&(s=g.return)&&s.call(g)}finally{if(e)throw e.error}}if(u.push(f),u.length>=a.seedMinLength&&(r=y(u,n)))return"break";c=c.parentElement,d++};c;){if("break"===s())break}return r||(r=y(u,n)),!r&&n?n():r}function y(e,t){var n,r,i=C(T(e));if(i.length>a.threshold)return t?t():null;try{for(var l=o(i),u=l.next();!u.done;u=l.next()){var c=u.value;if(E(c))return c}}catch(e){n={error:e}}finally{try{u&&!u.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}return null}function w(e){for(var t=e[0],n=t.name,r=1;r<e.length;r++){var o=e[r].level||0;n=t.level===o-1?"".concat(e[r].name," > ").concat(n):"".concat(e[r].name," ").concat(n),t=e[r]}return n}function b(e){return e.map((function(e){return e.penalty})).reduce((function(e,t){return e+t}),0)}function E(e){var t=w(e);switch(u.querySelectorAll(t).length){case 0:throw new Error("Can't select any node with this selector: ".concat(t));case 1:return!0;default:return!1}}function S(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function A(e){return"html"!==e.name&&!e.name.startsWith("#")}function k(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(N);return n.length>0?n:null}function N(e){return null!=e}function T(e,t){var n,i,l,a,u,c;return void 0===t&&(t=[]),r(this,(function(r){switch(r.label){case 0:if(!(e.length>0))return[3,9];r.label=1;case 1:r.trys.push([1,6,7,8]),n=o(e[0]),i=n.next(),r.label=2;case 2:return i.done?[3,5]:(l=i.value,[5,o(T(e.slice(1,e.length),t.concat(l)))]);case 3:r.sent(),r.label=4;case 4:return i=n.next(),[3,2];case 5:return[3,8];case 6:return a=r.sent(),u={error:a},[3,8];case 7:try{i&&!i.done&&(c=n.return)&&c.call(n)}finally{if(u)throw u.error}return[7];case 8:return[3,11];case 9:return[4,t];case 10:r.sent(),r.label=11;case 11:return[2]}}))}function C(e){return l([],i(e),!1).sort((function(e,t){return b(e)-b(t)}))}function L(e,t,n){var c,d,s;return void 0===n&&(n={counter:0,visited:new Map}),r(this,(function(r){switch(r.label){case 0:if(!(e.length>2&&e.length>a.optimizedMinLength))return[3,5];c=1,r.label=1;case 1:return c<e.length-1?n.counter>a.maxNumberOfTries?[2]:(n.counter+=1,(d=l([],i(e),!1)).splice(c,1),s=w(d),n.visited.has(s)?[2]:E(d)&&function(e,t){return u.querySelector(w(e))===t}(d,t)?[4,d]:[3,4]):[3,5];case 2:return r.sent(),n.visited.set(s,!0),[5,o(L(d,t,n))];case 3:r.sent(),r.label=4;case 4:return c++,[3,1];case 5:return[2]}}))}var x=["input","select","textarea"],O=function(e){if(null==e)return!1;if("string"==typeof e){if(/^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/.test((e||"").replace(/[- ]/g,"")))return!1;if(/(^\d{3}-?\d{2}-?\d{4}$)/.test(e))return!1}return!0},M=function(e){var t,n,r=null===(n=null===(t=null==e?void 0:e.tagName)||void 0===t?void 0:t.toLowerCase)||void 0===n?void 0:n.call(t),o="true"===e.getAttribute("contenteditable");return!x.includes(r)&&!o},P=function(e){var t="";return M(e)&&e.childNodes&&e.childNodes.length&&e.childNodes.forEach((function(e){var n,r="";(n=e)&&3===n.nodeType?e.textContent&&(r=e.textContent):r=P(e),t+=r.split(/(\s+)/).filter(O).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)})),t},q=function(e,t){var n,r,o="";try{return o=h(e,{className:function(e){return e!==g}})}catch(e){if(t){var i=e;t.warn("Failed to get selector with finder, use fallback strategy instead: ".concat(i.toString()))}}var l=null===(r=null===(n=null==e?void 0:e.tagName)||void 0===n?void 0:n.toLowerCase)||void 0===r?void 0:r.call(n);if(l&&(o=l),e.id)o="#".concat(e.id);else if(e.className){var a=e.className.split(" ").filter((function(e){return e!==g})).join(".");a&&(o="".concat(o,".").concat(a))}return o},j=function(e){return Object.keys(e).reduce((function(t,n){var r=e[n];return function(e){return null==e||"object"==typeof e&&0===Object.keys(e).length||"string"==typeof e&&0===e.trim().length}(r)||(t[n]=r),t}),{})},R=function(e){var t=e.parentElement;if(!t)return"";var n=t.querySelector(":scope>span,h1,h2,h3,h4,h5,h6");if(n){var r=n.textContent||"";return O(r)?r:""}return R(t)},D=function(e,t){if(e&&"querySelectorAll"in e&&"function"==typeof e.querySelectorAll){var n=t.reduce((function(t,n){n&&Array.from(e.querySelectorAll(n)).forEach((function(e){t.add(e)}));return t}),new Set);return Array.from(n)}return[]},_=function(e,t){return e?t.some((function(t){var n;return null===(n=null==e?void 0:e.matches)||void 0===n?void 0:n.call(e,t)}))?e:_(null==e?void 0:e.parentElement,t):null},U=function(e,t){var n,r,o;if(!e)return{};var i=null===(o=null===(r=null==e?void 0:e.tagName)||void 0===r?void 0:r.toLowerCase)||void 0===o?void 0:o.call(r),l=q(e,t),a=((n={})[c]=i,n[d]=P(e),n[s]=l,n[f]=window.location.href.split("?")[0],n);return j(a)};var H=function(){function e(e){var t=(void 0===e?{}:e).origin,n=void 0===t?v:t,r=this;this.endpoint=v,this.requestCallbacks={},this.onSelect=function(e){r.notify({action:"element-selected",data:e})},this.onTrack=function(e,t){"selector-mode-changed"===e?r.notify({action:"track-selector-mode-changed",data:t}):"selector-moved"===e&&r.notify({action:"track-selector-moved",data:t})},this.endpoint=n}return e.prototype.notify=function(e){var t,n,r,o;null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message sent: ",JSON.stringify(e)),null===(o=null===(r=window.opener)||void 0===r?void 0:r.postMessage)||void 0===o||o.call(r,e,this.endpoint)},e.prototype.sendRequest=function(e,t,n){var r=this;void 0===n&&(n={timeout:15e3});var o="".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),i={id:o,action:e,args:t};return new Promise((function(t,l){r.requestCallbacks[o]={resolve:t,reject:l},r.notify(i),(null==n?void 0:n.timeout)>0&&setTimeout((function(){l(new Error("".concat(e," timed out (id: ").concat(o,")"))),delete r.requestCallbacks[o]}),n.timeout)}))},e.prototype.handleResponse=function(e){var t;this.requestCallbacks[e.id]?(this.requestCallbacks[e.id].resolve(e.responseData),delete this.requestCallbacks[e.id]):null===(t=this.logger)||void 0===t||t.warn("No callback found for request id: ".concat(e.id))},e.prototype.setup=function(e){var t=this,n=void 0===e?{}:e,r=n.logger,o=n.endpoint,i=n.isElementSelectable;this.logger=r,o&&this.endpoint===v&&(this.endpoint=o);var l=null;window.addEventListener("message",(function(e){var n,r,o,a,u;if(null===(r=null===(n=t.logger)||void 0===n?void 0:n.debug)||void 0===r||r.call(n,"Message received: ",JSON.stringify(e)),t.endpoint===e.origin){var c,d=null==e?void 0:e.data,s=null==d?void 0:d.action;if(s)if("id"in d)null===(a=null===(o=t.logger)||void 0===o?void 0:o.debug)||void 0===a||a.call(o,"Received Response to previous request: ",JSON.stringify(e)),t.handleResponse(d);else if("ping"===s)t.notify({action:"pong"});else if("initialize-visual-tagging-selector"===s){var f=null==d?void 0:d.data;(c="https://cdn.amplitude.com/libs/visual-tagging-selector-1.0.0-alpha.js.gz",new Promise((function(e,t){var n;try{var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src=c,r.addEventListener("load",(function(){e({status:!0})}),{once:!0}),r.addEventListener("error",(function(){t({status:!1,message:"Failed to load the script ".concat(c)})})),null===(n=document.head)||void 0===n||n.appendChild(r)}catch(e){t(e)}}))).then((function(){var e;l=null===(e=null===window||void 0===window?void 0:window.amplitudeVisualTaggingSelector)||void 0===e?void 0:e.call(window,{getEventTagProps:U,isElementSelectable:function(e){return!i||i((null==f?void 0:f.actionType)||"click",e)},onTrack:t.onTrack,onSelect:t.onSelect,visualHighlightClass:g,messenger:t}),t.notify({action:"selector-loaded"})})).catch((function(){var e;null===(e=t.logger)||void 0===e||e.warn("Failed to initialize visual tagging selector")}))}else"close-visual-tagging-selector"===s&&(null===(u=null==l?void 0:l.close)||void 0===u||u.call(l))}})),this.notify({action:"page-loaded"})},e}(),F=["id","class","style","value","onclick","onchange","oninput","onblur","onsubmit","onfocus","onkeydown","onkeyup","onkeypress","data-reactid","data-react-checksum","data-reactroot"],W=["type"],z=["svg","path","g"],I=["password","hidden"];function J(e){var t,n,r,i,l,a;if(null===e)return null;var u=e.tagName.toLowerCase(),c={tag:u},d=Array.from(null!==(i=null===(r=e.parentElement)||void 0===r?void 0:r.children)&&void 0!==i?i:[]);d.length&&(c.index=d.indexOf(e),c.indexOfType=d.filter((function(t){return t.tagName===e.tagName})).indexOf(e));var s=null===(a=null===(l=e.previousElementSibling)||void 0===l?void 0:l.tagName)||void 0===a?void 0:a.toLowerCase();s&&(c.prevSib=s);var f=e.id;f&&(c.id=f);var v=Array.from(e.classList);v.length&&(c.classes=v);var p={},g=Array.from(e.attributes).filter((function(e){return!F.includes(e.name)})),h=!M(e);if(!I.includes(e.type)&&!z.includes(u))try{for(var m=o(g),y=m.next();!y.done;y=m.next()){var w=y.value;h&&!W.includes(w.name)||(p[w.name]=String(w.value).substring(0,128))}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=m.return)&&n.call(m)}finally{if(t)throw t.error}}return Object.keys(p).length&&(c.attrs=p),c}var V=["a","button","input","select","textarea","label","[data-amp-default-track]",".amp-default-track"],B="data-amp-track-",G=function(e){void 0===e&&(e={});var o,i=e.cssSelectorAllowlist,l=void 0===i?V:i,a=e.pageUrlAllowlist,u=e.shouldTrackEventResolver,v=e.dataAttributePrefix,g=void 0===v?B:v,h=e.visualTaggingOptions,m=void 0===h?{enabled:!0,messenger:new H}:h,y="@amplitude/plugin-autocapture-browser",w=[],b=void 0,E=function(e,t,n){e.addEventListener(t,n),w.push({element:e,type:t,handler:n})},S=function(e,t){var n,r,o;if(!t)return!1;var i=null===(r=null===(n=null==t?void 0:t.tagName)||void 0===n?void 0:n.toLowerCase)||void 0===r?void 0:r.call(n);if(!i)return!1;if(u)return u(e,t);if(!function(e,t){return!t||!t.length||t.some((function(t){return"string"==typeof t?e===t:e.match(t)}))}(window.location.href,a))return!1;var c=(null==t?void 0:t.type)||"";if("string"==typeof c)switch(c.toLowerCase()){case"hidden":case"password":return!1}if(l){var d=l.some((function(e){var n;return!!(null===(n=null==t?void 0:t.matches)||void 0===n?void 0:n.call(t,e))}));if(!d)return!1}switch(i){case"input":case"select":case"textarea":return"change"===e||"click"===e;default:var s=null===(o=null===window||void 0===window?void 0:window.getComputedStyle)||void 0===o?void 0:o.call(window,t);return!(!s||"pointer"!==s.getPropertyValue("cursor")||"click"!==e)||"click"===e}},A=function(e,t){var n,r,o,i=null===(o=null===(r=null==t?void 0:t.tagName)||void 0===r?void 0:r.toLowerCase)||void 0===o?void 0:o.call(r),l="function"==typeof t.getBoundingClientRect?t.getBoundingClientRect():{left:null,top:null},a=t.getAttribute("aria-label"),u=function(e,t){return e.getAttributeNames().reduce((function(n,r){if(r.startsWith(t)){var o=r.replace(t,""),i=e.getAttribute(r);o&&(n[o]=i||"")}return n}),{})}(t,g),v=R(t),p=q(t,b),h=((n={})["[Amplitude] Element ID"]=t.id,n["[Amplitude] Element Class"]=t.className,n["[Amplitude] Element Hierarchy"]=function(e){var t=2,n=[];if(!e)return n;for(var r=function(e){var t=[];if(!e)return t;t.push(e);for(var n=e.parentElement;n&&"HTML"!==n.tagName;)t.push(n),n=n.parentElement;return t}(e),o=0;o<r.length;o++){var i=J(r[o]),l=JSON.stringify(i).length,a=o>0?1:0;if(t+l+a>1024)break;t+=l+a,n.unshift(i)}return n}(t),n[c]=i,n[d]=P(t),n["[Amplitude] Element Position Left"]=null==l.left?null:Math.round(l.left),n["[Amplitude] Element Position Top"]=null==l.top?null:Math.round(l.top),n["[Amplitude] Element Aria Label"]=a,n["[Amplitude] Element Attributes"]=u,n[s]=p,n["[Amplitude] Element Parent Label"]=v,n[f]=window.location.href.split("?")[0],n["[Amplitude] Page Title"]="undefined"!=typeof document&&document.title||"",n["[Amplitude] Viewport Height"]=window.innerHeight,n["[Amplitude] Viewport Width"]=window.innerWidth,n);return"a"===i&&"click"===e&&t instanceof HTMLAnchorElement&&(h["[Amplitude] Element Href"]=t.href),j(h)};return{name:y,type:"enrichment",setup:function(e,i){return n(void 0,void 0,void 0,(function(){var n,a,u,c,d;return r(this,(function(r){return i?(b=e.loggerProvider,"undefined"==typeof document||(n=function(e){S("click",e)&&E(e,"click",(function(t){(null==t?void 0:t.target)!=(null==t?void 0:t.currentTarget)&&_(null==t?void 0:t.target,l)!=(null==t?void 0:t.currentTarget)||null==i||i.track("[Amplitude] Element Clicked",A("click",e))})),S("change",e)&&E(e,"change",(function(t){(null==t?void 0:t.target)!=(null==t?void 0:t.currentTarget)&&_(null==t?void 0:t.target,l)!=(null==t?void 0:t.currentTarget)||null==i||i.track("[Amplitude] Element Changed",A("change",e))}))},"undefined"!=typeof MutationObserver&&(o=new MutationObserver((function(e){e.forEach((function(e){e.addedNodes.forEach((function(e){n(e),"querySelectorAll"in e&&"function"==typeof e.querySelectorAll&&D(e,l).map(n)}))}))}))),a=function(){D(document.body,l).forEach(n),null==o||o.observe(document.body,{subtree:!0,childList:!0})},document.body?a():window.addEventListener("load",a),null===(c=null==e?void 0:e.loggerProvider)||void 0===c||c.log("".concat(y," has been successfully added.")),window.opener&&m.enabled&&(null===(d=m.messenger)||void 0===d||d.setup(t(t({logger:null==e?void 0:e.loggerProvider},(null==e?void 0:e.serverZone)&&{endpoint:p[e.serverZone]}),{isElementSelectable:S})))),[2]):(null===(u=null==e?void 0:e.loggerProvider)||void 0===u||u.warn("".concat(y," plugin requires a later version of @amplitude/analytics-browser. Events are not tracked.")),[2])}))}))},execute:function(e){return n(void 0,void 0,void 0,(function(){return r(this,(function(t){return[2,e]}))}))},teardown:function(){return n(void 0,void 0,void 0,(function(){return r(this,(function(e){return o&&o.disconnect(),w.forEach((function(e){var t=e.element,n=e.type,r=e.handler;null==t||t.removeEventListener(n,r)})),w=[],[2]}))}))}}};return e.DEFAULT_CSS_SELECTOR_ALLOWLIST=V,e.DEFAULT_DATA_ATTRIBUTE_PREFIX=B,e.WindowMessenger=H,e.autocapturePlugin=G,e.plugin=G,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var amplitudeAutocapturePlugin=function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},t.apply(this,arguments)};function n(e,t,n,r){return new(n||(n=Promise))((function(o,i){function l(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}u((r=r.apply(e,t||[])).next())}))}function r(e,t){var n,r,o,i,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(l=0)),l;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=l.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=t.call(e,l)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function o(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),l=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)l.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return l}function l(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}var a,u,c="[Amplitude] Element Tag",s="[Amplitude] Element Text",d="[Amplitude] Element Selector",f="[Amplitude] Page URL",v="https://app.amplitude.com",p={US:v,EU:"https://app.eu.amplitude.com",STAGING:"https://apps.stag2.amplitude.com"},g="amp-visual-tagging-selector-highlight";function h(e,n){if(e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";var r={root:document.body,idName:function(e){return!0},className:function(e){return!0},tagName:function(e){return!0},attr:function(e,t){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};a=t(t({},r),n),u=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(a.root,r);var o=m(e,"all",(function(){return m(e,"two",(function(){return m(e,"one",(function(){return m(e,"none")}))}))}));if(o){var i=C(L(o,e));return i.length>0&&(o=i[0]),w(o)}throw new Error("Selector was not found.")}function m(e,t,n){for(var r=null,u=[],c=e,s=0,d=function(){var e,d,f=N(function(e){var t=e.getAttribute("id");if(t&&a.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(c))||N.apply(void 0,l([],i(function(e){var t=Array.from(e.attributes).filter((function(e){return a.attr(e.name,e.value)}));return t.map((function(e){return{name:"[".concat(CSS.escape(e.name),'="').concat(CSS.escape(e.value),'"]'),penalty:.5}}))}(c)),!1))||N.apply(void 0,l([],i(function(e){var t=Array.from(e.classList).filter(a.className);return t.map((function(e){return{name:"."+CSS.escape(e),penalty:1}}))}(c)),!1))||N(function(e){var t=e.tagName.toLowerCase();if(a.tagName(t))return{name:t,penalty:2};return null}(c))||[{name:"*",penalty:3}],v=function(e){var t=e.parentNode;if(!t)return null;var n=t.firstChild;if(!n)return null;var r=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&r++,n!==e);)n=n.nextSibling;return r}(c);if("all"==t)v&&(f=f.concat(f.filter(S).map((function(e){return A(e,v)}))));else if("two"==t)f=f.slice(0,1),v&&(f=f.concat(f.filter(S).map((function(e){return A(e,v)}))));else if("one"==t){var p=i(f=f.slice(0,1),1)[0];v&&S(p)&&(f=[A(p,v)])}else"none"==t&&(f=[{name:"*",penalty:3}],v&&(f=[A(f[0],v)]));try{for(var g=(e=void 0,o(f)),h=g.next();!h.done;h=g.next()){(p=h.value).level=s}}catch(t){e={error:t}}finally{try{h&&!h.done&&(d=g.return)&&d.call(g)}finally{if(e)throw e.error}}if(u.push(f),u.length>=a.seedMinLength&&(r=y(u,n)))return"break";c=c.parentElement,s++};c;){if("break"===d())break}return r||(r=y(u,n)),!r&&n?n():r}function y(e,t){var n,r,i=C(T(e));if(i.length>a.threshold)return t?t():null;try{for(var l=o(i),u=l.next();!u.done;u=l.next()){var c=u.value;if(E(c))return c}}catch(e){n={error:e}}finally{try{u&&!u.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}return null}function w(e){for(var t=e[0],n=t.name,r=1;r<e.length;r++){var o=e[r].level||0;n=t.level===o-1?"".concat(e[r].name," > ").concat(n):"".concat(e[r].name," ").concat(n),t=e[r]}return n}function b(e){return e.map((function(e){return e.penalty})).reduce((function(e,t){return e+t}),0)}function E(e){var t=w(e);switch(u.querySelectorAll(t).length){case 0:throw new Error("Can't select any node with this selector: ".concat(t));case 1:return!0;default:return!1}}function A(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function S(e){return"html"!==e.name&&!e.name.startsWith("#")}function N(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(k);return n.length>0?n:null}function k(e){return null!=e}function T(e,t){var n,i,l,a,u,c;return void 0===t&&(t=[]),r(this,(function(r){switch(r.label){case 0:if(!(e.length>0))return[3,9];r.label=1;case 1:r.trys.push([1,6,7,8]),n=o(e[0]),i=n.next(),r.label=2;case 2:return i.done?[3,5]:(l=i.value,[5,o(T(e.slice(1,e.length),t.concat(l)))]);case 3:r.sent(),r.label=4;case 4:return i=n.next(),[3,2];case 5:return[3,8];case 6:return a=r.sent(),u={error:a},[3,8];case 7:try{i&&!i.done&&(c=n.return)&&c.call(n)}finally{if(u)throw u.error}return[7];case 8:return[3,11];case 9:return[4,t];case 10:r.sent(),r.label=11;case 11:return[2]}}))}function C(e){return l([],i(e),!1).sort((function(e,t){return b(e)-b(t)}))}function L(e,t,n){var c,s,d;return void 0===n&&(n={counter:0,visited:new Map}),r(this,(function(r){switch(r.label){case 0:if(!(e.length>2&&e.length>a.optimizedMinLength))return[3,5];c=1,r.label=1;case 1:return c<e.length-1?n.counter>a.maxNumberOfTries?[2]:(n.counter+=1,(s=l([],i(e),!1)).splice(c,1),d=w(s),n.visited.has(d)?[2]:E(s)&&function(e,t){return u.querySelector(w(e))===t}(s,t)?[4,s]:[3,4]):[3,5];case 2:return r.sent(),n.visited.set(d,!0),[5,o(L(s,t,n))];case 3:r.sent(),r.label=4;case 4:return c++,[3,1];case 5:return[2]}}))}var x=["input","select","textarea"],O=function(e){if(null==e)return!1;if("string"==typeof e){if(/^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/.test((e||"").replace(/[- ]/g,"")))return!1;if(/(^\d{3}-?\d{2}-?\d{4}$)/.test(e))return!1}return!0},M=function(e){var t,n,r=null===(n=null===(t=null==e?void 0:e.tagName)||void 0===t?void 0:t.toLowerCase)||void 0===n?void 0:n.call(t),o="true"===e.getAttribute("contenteditable");return!x.includes(r)&&!o},P=function(e){var t="";return M(e)&&e.childNodes&&e.childNodes.length&&e.childNodes.forEach((function(e){var n,r="";(n=e)&&3===n.nodeType?e.textContent&&(r=e.textContent):r=P(e),t+=r.split(/(\s+)/).filter(O).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)})),t},q=function(e,t){var n,r,o="";try{return o=h(e,{className:function(e){return e!==g}})}catch(e){if(t){var i=e;t.warn("Failed to get selector with finder, use fallback strategy instead: ".concat(i.toString()))}}var l=null===(r=null===(n=null==e?void 0:e.tagName)||void 0===n?void 0:n.toLowerCase)||void 0===r?void 0:r.call(n);if(l&&(o=l),e.id)o="#".concat(e.id);else if(e.className){var a=e.className.split(" ").filter((function(e){return e!==g})).join(".");a&&(o="".concat(o,".").concat(a))}return o},j=function(e){return Object.keys(e).reduce((function(t,n){var r=e[n];return function(e){return null==e||"object"==typeof e&&0===Object.keys(e).length||"string"==typeof e&&0===e.trim().length}(r)||(t[n]=r),t}),{})},R=function(e){var t=e.parentElement;if(!t)return"";var n=t.querySelector(":scope>span,h1,h2,h3,h4,h5,h6");if(n){var r=n.textContent||"";return O(r)?r:""}return R(t)},D=function(e,t){if(e&&"querySelectorAll"in e&&"function"==typeof e.querySelectorAll){var n=t.reduce((function(t,n){n&&Array.from(e.querySelectorAll(n)).forEach((function(e){t.add(e)}));return t}),new Set);return Array.from(n)}return[]},_=function(e,t){return e?t.some((function(t){var n;return null===(n=null==e?void 0:e.matches)||void 0===n?void 0:n.call(e,t)}))?e:_(null==e?void 0:e.parentElement,t):null},U=function(e,t){var n,r,o;if(!e)return{};var i=null===(o=null===(r=null==e?void 0:e.tagName)||void 0===r?void 0:r.toLowerCase)||void 0===o?void 0:o.call(r),l=q(e,t),a=((n={})[c]=i,n[s]=P(e),n[d]=l,n[f]=window.location.href.split("?")[0],n);return j(a)};var F=function(){function e(e){var t=(void 0===e?{}:e).origin,n=void 0===t?v:t,r=this;this.endpoint=v,this.requestCallbacks={},this.onSelect=function(e){r.notify({action:"element-selected",data:e})},this.onTrack=function(e,t){"selector-mode-changed"===e?r.notify({action:"track-selector-mode-changed",data:t}):"selector-moved"===e&&r.notify({action:"track-selector-moved",data:t})},this.endpoint=n}return e.prototype.notify=function(e){var t,n,r,o;null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message sent: ",JSON.stringify(e)),null===(o=null===(r=window.opener)||void 0===r?void 0:r.postMessage)||void 0===o||o.call(r,e,this.endpoint)},e.prototype.sendRequest=function(e,t,n){var r=this;void 0===n&&(n={timeout:15e3});var o="".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),i={id:o,action:e,args:t};return new Promise((function(t,l){r.requestCallbacks[o]={resolve:t,reject:l},r.notify(i),(null==n?void 0:n.timeout)>0&&setTimeout((function(){l(new Error("".concat(e," timed out (id: ").concat(o,")"))),delete r.requestCallbacks[o]}),n.timeout)}))},e.prototype.handleResponse=function(e){var t;this.requestCallbacks[e.id]?(this.requestCallbacks[e.id].resolve(e.responseData),delete this.requestCallbacks[e.id]):null===(t=this.logger)||void 0===t||t.warn("No callback found for request id: ".concat(e.id))},e.prototype.setup=function(e){var t=this,n=void 0===e?{}:e,r=n.logger,o=n.endpoint,i=n.isElementSelectable;this.logger=r,o&&this.endpoint===v&&(this.endpoint=o);var l=null;window.addEventListener("message",(function(e){var n,r,o,a,u;if(null===(r=null===(n=t.logger)||void 0===n?void 0:n.debug)||void 0===r||r.call(n,"Message received: ",JSON.stringify(e)),t.endpoint===e.origin){var c,s=null==e?void 0:e.data,d=null==s?void 0:s.action;if(d)if("id"in s)null===(a=null===(o=t.logger)||void 0===o?void 0:o.debug)||void 0===a||a.call(o,"Received Response to previous request: ",JSON.stringify(e)),t.handleResponse(s);else if("ping"===d)t.notify({action:"pong"});else if("initialize-visual-tagging-selector"===d){var f=null==s?void 0:s.data;(c="https://cdn.amplitude.com/libs/visual-tagging-selector-1.0.0-alpha.js.gz",new Promise((function(e,t){var n;try{var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src=c,r.addEventListener("load",(function(){e({status:!0})}),{once:!0}),r.addEventListener("error",(function(){t({status:!1,message:"Failed to load the script ".concat(c)})})),null===(n=document.head)||void 0===n||n.appendChild(r)}catch(e){t(e)}}))).then((function(){var e;l=null===(e=null===window||void 0===window?void 0:window.amplitudeVisualTaggingSelector)||void 0===e?void 0:e.call(window,{getEventTagProps:U,isElementSelectable:function(e){return!i||i((null==f?void 0:f.actionType)||"click",e)},onTrack:t.onTrack,onSelect:t.onSelect,visualHighlightClass:g,messenger:t}),t.notify({action:"selector-loaded"})})).catch((function(){var e;null===(e=t.logger)||void 0===e||e.warn("Failed to initialize visual tagging selector")}))}else"close-visual-tagging-selector"===d&&(null===(u=null==l?void 0:l.close)||void 0===u||u.call(l))}})),this.notify({action:"page-loaded"})},e}(),H=["id","class","style","value","onclick","onchange","oninput","onblur","onsubmit","onfocus","onkeydown","onkeyup","onkeypress","data-reactid","data-react-checksum","data-reactroot"],W=["type"],z=["svg","path","g"],I=["password","hidden"];var V=function(e){var t;return e?(t=function(e,t){for(var n=0,r=0;r<e.length;r++){var o=e[r];if(null===o)n+=4;else{var i=B(o);n+=i?Array.from(i).length:4}if(n>t)return e.slice(0,r)}return e}(function(e){var t=[];if(!e)return t;t.push(e);for(var n=e.parentElement;n&&"HTML"!==n.tagName;)t.push(n),n=n.parentElement;return t}(e).map((function(e){return function(e){var t,n,r,i,l,a;if(null===e)return null;var u=e.tagName.toLowerCase(),c={tag:u},s=Array.from(null!==(i=null===(r=e.parentElement)||void 0===r?void 0:r.children)&&void 0!==i?i:[]);s.length&&(c.index=s.indexOf(e),c.indexOfType=s.filter((function(t){return t.tagName===e.tagName})).indexOf(e));var d=null===(a=null===(l=e.previousElementSibling)||void 0===l?void 0:l.tagName)||void 0===a?void 0:a.toLowerCase();d&&(c.prevSib=d);var f=e.id;f&&(c.id=f);var v=Array.from(e.classList);v.length&&(c.classes=v);var p={},g=Array.from(e.attributes).filter((function(e){return!H.includes(e.name)})),h=!M(e);if(!I.includes(e.type)&&!z.includes(u))try{for(var m=o(g),y=m.next();!y.done;y=m.next()){var w=y.value;h&&!W.includes(w.name)||(p[w.name]=String(w.value).substring(0,128))}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=m.return)&&n.call(m)}finally{if(t)throw t.error}}return Object.keys(p).length&&(c.attrs=p),c}(e)})),1024),t):[]};function B(e,t){void 0===t&&(t=!1);try{if(null==e)return t?"None":null;if("string"==typeof e)return t?(e=e.replace(/\\/g,"\\\\").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")).includes('"')?"'".concat(e,"'"):e.includes("'")?'"'.concat(e.replace(/'/g,"\\'"),'"'):"'".concat(e,"'"):e;if("boolean"==typeof e)return e?"True":"False";if(Array.isArray(e)){var n=e.map((function(e){return B(e,!0)}));return"[".concat(n.join(", "),"]")}if("object"==typeof e){var r=Object.entries(e).filter((function(e){return null!=i(e,1)[0]})).map((function(e){var t=i(e,2),n=t[0],r=t[1];return"".concat(String(B(n,!0)),": ").concat(String(B(r,!0)))})),o="{".concat(r.join(", "),"}");return o.includes("\\'")&&(o=o.replace(/'/g,"'").replace(/'/g,"\\'")),o}return e.toString()}catch(e){return null}}var G=["a","button","input","select","textarea","label","[data-amp-default-track]",".amp-default-track"],J="data-amp-track-",Z=function(e){void 0===e&&(e={});var o,i=e.cssSelectorAllowlist,l=void 0===i?G:i,a=e.pageUrlAllowlist,u=e.shouldTrackEventResolver,v=e.dataAttributePrefix,g=void 0===v?J:v,h=e.visualTaggingOptions,m=void 0===h?{enabled:!0,messenger:new F}:h,y="@amplitude/plugin-autocapture-browser",w=[],b=void 0,E=function(e,t,n){e.addEventListener(t,n),w.push({element:e,type:t,handler:n})},A=function(e,t){var n,r,o;if(!t)return!1;var i=null===(r=null===(n=null==t?void 0:t.tagName)||void 0===n?void 0:n.toLowerCase)||void 0===r?void 0:r.call(n);if(!i)return!1;if(u)return u(e,t);if(!function(e,t){return!t||!t.length||t.some((function(t){return"string"==typeof t?e===t:e.match(t)}))}(window.location.href,a))return!1;var c=(null==t?void 0:t.type)||"";if("string"==typeof c)switch(c.toLowerCase()){case"hidden":case"password":return!1}if(l){var s=l.some((function(e){var n;return!!(null===(n=null==t?void 0:t.matches)||void 0===n?void 0:n.call(t,e))}));if(!s)return!1}switch(i){case"input":case"select":case"textarea":return"change"===e||"click"===e;default:var d=null===(o=null===window||void 0===window?void 0:window.getComputedStyle)||void 0===o?void 0:o.call(window,t);return!(!d||"pointer"!==d.getPropertyValue("cursor")||"click"!==e)||"click"===e}},S=function(e,t){var n,r,o,i=null===(o=null===(r=null==t?void 0:t.tagName)||void 0===r?void 0:r.toLowerCase)||void 0===o?void 0:o.call(r),l="function"==typeof t.getBoundingClientRect?t.getBoundingClientRect():{left:null,top:null},a=t.getAttribute("aria-label"),u=function(e,t){return e.getAttributeNames().reduce((function(n,r){if(r.startsWith(t)){var o=r.replace(t,""),i=e.getAttribute(r);o&&(n[o]=i||"")}return n}),{})}(t,g),v=R(t),p=q(t,b),h=((n={})["[Amplitude] Element ID"]=t.id,n["[Amplitude] Element Class"]=t.className,n["[Amplitude] Element Hierarchy"]=V(t),n[c]=i,n[s]=P(t),n["[Amplitude] Element Position Left"]=null==l.left?null:Math.round(l.left),n["[Amplitude] Element Position Top"]=null==l.top?null:Math.round(l.top),n["[Amplitude] Element Aria Label"]=a,n["[Amplitude] Element Attributes"]=u,n[d]=p,n["[Amplitude] Element Parent Label"]=v,n[f]=window.location.href.split("?")[0],n["[Amplitude] Page Title"]="undefined"!=typeof document&&document.title||"",n["[Amplitude] Viewport Height"]=window.innerHeight,n["[Amplitude] Viewport Width"]=window.innerWidth,n);return"a"===i&&"click"===e&&t instanceof HTMLAnchorElement&&(h["[Amplitude] Element Href"]=t.href),j(h)};return{name:y,type:"enrichment",setup:function(e,i){return n(void 0,void 0,void 0,(function(){var n,a,u,c,s;return r(this,(function(r){return i?(b=e.loggerProvider,"undefined"==typeof document||(n=function(e){A("click",e)&&E(e,"click",(function(t){(null==t?void 0:t.target)!=(null==t?void 0:t.currentTarget)&&_(null==t?void 0:t.target,l)!=(null==t?void 0:t.currentTarget)||null==i||i.track("[Amplitude] Element Clicked",S("click",e))})),A("change",e)&&E(e,"change",(function(t){(null==t?void 0:t.target)!=(null==t?void 0:t.currentTarget)&&_(null==t?void 0:t.target,l)!=(null==t?void 0:t.currentTarget)||null==i||i.track("[Amplitude] Element Changed",S("change",e))}))},"undefined"!=typeof MutationObserver&&(o=new MutationObserver((function(e){e.forEach((function(e){e.addedNodes.forEach((function(e){n(e),"querySelectorAll"in e&&"function"==typeof e.querySelectorAll&&D(e,l).map(n)}))}))}))),a=function(){D(document.body,l).forEach(n),null==o||o.observe(document.body,{subtree:!0,childList:!0})},document.body?a():window.addEventListener("load",a),null===(c=null==e?void 0:e.loggerProvider)||void 0===c||c.log("".concat(y," has been successfully added.")),window.opener&&m.enabled&&(null===(s=m.messenger)||void 0===s||s.setup(t(t({logger:null==e?void 0:e.loggerProvider},(null==e?void 0:e.serverZone)&&{endpoint:p[e.serverZone]}),{isElementSelectable:A})))),[2]):(null===(u=null==e?void 0:e.loggerProvider)||void 0===u||u.warn("".concat(y," plugin requires a later version of @amplitude/analytics-browser. Events are not tracked.")),[2])}))}))},execute:function(e){return n(void 0,void 0,void 0,(function(){return r(this,(function(t){return[2,e]}))}))},teardown:function(){return n(void 0,void 0,void 0,(function(){return r(this,(function(e){return o&&o.disconnect(),w.forEach((function(e){var t=e.element,n=e.type,r=e.handler;null==t||t.removeEventListener(n,r)})),w=[],[2]}))}))}}};return e.DEFAULT_CSS_SELECTOR_ALLOWLIST=G,e.DEFAULT_DATA_ATTRIBUTE_PREFIX=J,e.WindowMessenger=F,e.autocapturePlugin=Z,e.plugin=Z,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).amplitude={})}(this,(function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},t.apply(this,arguments)};function n(e,t,n,r){return new(n||(n=Promise))((function(o,i){function l(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}u((r=r.apply(e,t||[])).next())}))}function r(e,t){var n,r,o,i,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(l=0)),l;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=l.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=t.call(e,l)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function o(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),l=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)l.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return l}function l(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}var a,u,c="[Amplitude] Element Tag",d="[Amplitude] Element Text",s="[Amplitude] Element Selector",f="[Amplitude] Page URL",v="https://app.amplitude.com",p={US:v,EU:"https://app.eu.amplitude.com",STAGING:"https://apps.stag2.amplitude.com"},g="amp-visual-tagging-selector-highlight";function h(e,n){if(e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";var r={root:document.body,idName:function(e){return!0},className:function(e){return!0},tagName:function(e){return!0},attr:function(e,t){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};a=t(t({},r),n),u=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(a.root,r);var o=m(e,"all",(function(){return m(e,"two",(function(){return m(e,"one",(function(){return m(e,"none")}))}))}));if(o){var i=C(L(o,e));return i.length>0&&(o=i[0]),w(o)}throw new Error("Selector was not found.")}function m(e,t,n){for(var r=null,u=[],c=e,d=0,s=function(){var e,s,f=k(function(e){var t=e.getAttribute("id");if(t&&a.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(c))||k.apply(void 0,l([],i(function(e){var t=Array.from(e.attributes).filter((function(e){return a.attr(e.name,e.value)}));return t.map((function(e){return{name:"[".concat(CSS.escape(e.name),'="').concat(CSS.escape(e.value),'"]'),penalty:.5}}))}(c)),!1))||k.apply(void 0,l([],i(function(e){var t=Array.from(e.classList).filter(a.className);return t.map((function(e){return{name:"."+CSS.escape(e),penalty:1}}))}(c)),!1))||k(function(e){var t=e.tagName.toLowerCase();if(a.tagName(t))return{name:t,penalty:2};return null}(c))||[{name:"*",penalty:3}],v=function(e){var t=e.parentNode;if(!t)return null;var n=t.firstChild;if(!n)return null;var r=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&r++,n!==e);)n=n.nextSibling;return r}(c);if("all"==t)v&&(f=f.concat(f.filter(A).map((function(e){return S(e,v)}))));else if("two"==t)f=f.slice(0,1),v&&(f=f.concat(f.filter(A).map((function(e){return S(e,v)}))));else if("one"==t){var p=i(f=f.slice(0,1),1)[0];v&&A(p)&&(f=[S(p,v)])}else"none"==t&&(f=[{name:"*",penalty:3}],v&&(f=[S(f[0],v)]));try{for(var g=(e=void 0,o(f)),h=g.next();!h.done;h=g.next()){(p=h.value).level=d}}catch(t){e={error:t}}finally{try{h&&!h.done&&(s=g.return)&&s.call(g)}finally{if(e)throw e.error}}if(u.push(f),u.length>=a.seedMinLength&&(r=y(u,n)))return"break";c=c.parentElement,d++};c;){if("break"===s())break}return r||(r=y(u,n)),!r&&n?n():r}function y(e,t){var n,r,i=C(T(e));if(i.length>a.threshold)return t?t():null;try{for(var l=o(i),u=l.next();!u.done;u=l.next()){var c=u.value;if(E(c))return c}}catch(e){n={error:e}}finally{try{u&&!u.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}return null}function w(e){for(var t=e[0],n=t.name,r=1;r<e.length;r++){var o=e[r].level||0;n=t.level===o-1?"".concat(e[r].name," > ").concat(n):"".concat(e[r].name," ").concat(n),t=e[r]}return n}function b(e){return e.map((function(e){return e.penalty})).reduce((function(e,t){return e+t}),0)}function E(e){var t=w(e);switch(u.querySelectorAll(t).length){case 0:throw new Error("Can't select any node with this selector: ".concat(t));case 1:return!0;default:return!1}}function S(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function A(e){return"html"!==e.name&&!e.name.startsWith("#")}function k(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(N);return n.length>0?n:null}function N(e){return null!=e}function T(e,t){var n,i,l,a,u,c;return void 0===t&&(t=[]),r(this,(function(r){switch(r.label){case 0:if(!(e.length>0))return[3,9];r.label=1;case 1:r.trys.push([1,6,7,8]),n=o(e[0]),i=n.next(),r.label=2;case 2:return i.done?[3,5]:(l=i.value,[5,o(T(e.slice(1,e.length),t.concat(l)))]);case 3:r.sent(),r.label=4;case 4:return i=n.next(),[3,2];case 5:return[3,8];case 6:return a=r.sent(),u={error:a},[3,8];case 7:try{i&&!i.done&&(c=n.return)&&c.call(n)}finally{if(u)throw u.error}return[7];case 8:return[3,11];case 9:return[4,t];case 10:r.sent(),r.label=11;case 11:return[2]}}))}function C(e){return l([],i(e),!1).sort((function(e,t){return b(e)-b(t)}))}function L(e,t,n){var c,d,s;return void 0===n&&(n={counter:0,visited:new Map}),r(this,(function(r){switch(r.label){case 0:if(!(e.length>2&&e.length>a.optimizedMinLength))return[3,5];c=1,r.label=1;case 1:return c<e.length-1?n.counter>a.maxNumberOfTries?[2]:(n.counter+=1,(d=l([],i(e),!1)).splice(c,1),s=w(d),n.visited.has(s)?[2]:E(d)&&function(e,t){return u.querySelector(w(e))===t}(d,t)?[4,d]:[3,4]):[3,5];case 2:return r.sent(),n.visited.set(s,!0),[5,o(L(d,t,n))];case 3:r.sent(),r.label=4;case 4:return c++,[3,1];case 5:return[2]}}))}var x=["input","select","textarea"],O=function(e){if(null==e)return!1;if("string"==typeof e){if(/^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/.test((e||"").replace(/[- ]/g,"")))return!1;if(/(^\d{3}-?\d{2}-?\d{4}$)/.test(e))return!1}return!0},M=function(e){var t,n,r=null===(n=null===(t=null==e?void 0:e.tagName)||void 0===t?void 0:t.toLowerCase)||void 0===n?void 0:n.call(t),o="true"===e.getAttribute("contenteditable");return!x.includes(r)&&!o},P=function(e){var t="";return M(e)&&e.childNodes&&e.childNodes.length&&e.childNodes.forEach((function(e){var n,r="";(n=e)&&3===n.nodeType?e.textContent&&(r=e.textContent):r=P(e),t+=r.split(/(\s+)/).filter(O).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)})),t},q=function(e,t){var n,r,o="";try{return o=h(e,{className:function(e){return e!==g}})}catch(e){if(t){var i=e;t.warn("Failed to get selector with finder, use fallback strategy instead: ".concat(i.toString()))}}var l=null===(r=null===(n=null==e?void 0:e.tagName)||void 0===n?void 0:n.toLowerCase)||void 0===r?void 0:r.call(n);if(l&&(o=l),e.id)o="#".concat(e.id);else if(e.className){var a=e.className.split(" ").filter((function(e){return e!==g})).join(".");a&&(o="".concat(o,".").concat(a))}return o},j=function(e){return Object.keys(e).reduce((function(t,n){var r=e[n];return function(e){return null==e||"object"==typeof e&&0===Object.keys(e).length||"string"==typeof e&&0===e.trim().length}(r)||(t[n]=r),t}),{})},R=function(e){var t=e.parentElement;if(!t)return"";var n=t.querySelector(":scope>span,h1,h2,h3,h4,h5,h6");if(n){var r=n.textContent||"";return O(r)?r:""}return R(t)},D=function(e,t){if(e&&"querySelectorAll"in e&&"function"==typeof e.querySelectorAll){var n=t.reduce((function(t,n){n&&Array.from(e.querySelectorAll(n)).forEach((function(e){t.add(e)}));return t}),new Set);return Array.from(n)}return[]},_=function(e,t){return e?t.some((function(t){var n;return null===(n=null==e?void 0:e.matches)||void 0===n?void 0:n.call(e,t)}))?e:_(null==e?void 0:e.parentElement,t):null},U=function(e,t){var n,r,o;if(!e)return{};var i=null===(o=null===(r=null==e?void 0:e.tagName)||void 0===r?void 0:r.toLowerCase)||void 0===o?void 0:o.call(r),l=q(e,t),a=((n={})[c]=i,n[d]=P(e),n[s]=l,n[f]=window.location.href.split("?")[0],n);return j(a)};var H=function(){function e(e){var t=(void 0===e?{}:e).origin,n=void 0===t?v:t,r=this;this.endpoint=v,this.requestCallbacks={},this.onSelect=function(e){r.notify({action:"element-selected",data:e})},this.onTrack=function(e,t){"selector-mode-changed"===e?r.notify({action:"track-selector-mode-changed",data:t}):"selector-moved"===e&&r.notify({action:"track-selector-moved",data:t})},this.endpoint=n}return e.prototype.notify=function(e){var t,n,r,o;null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message sent: ",JSON.stringify(e)),null===(o=null===(r=window.opener)||void 0===r?void 0:r.postMessage)||void 0===o||o.call(r,e,this.endpoint)},e.prototype.sendRequest=function(e,t,n){var r=this;void 0===n&&(n={timeout:15e3});var o="".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),i={id:o,action:e,args:t};return new Promise((function(t,l){r.requestCallbacks[o]={resolve:t,reject:l},r.notify(i),(null==n?void 0:n.timeout)>0&&setTimeout((function(){l(new Error("".concat(e," timed out (id: ").concat(o,")"))),delete r.requestCallbacks[o]}),n.timeout)}))},e.prototype.handleResponse=function(e){var t;this.requestCallbacks[e.id]?(this.requestCallbacks[e.id].resolve(e.responseData),delete this.requestCallbacks[e.id]):null===(t=this.logger)||void 0===t||t.warn("No callback found for request id: ".concat(e.id))},e.prototype.setup=function(e){var t=this,n=void 0===e?{}:e,r=n.logger,o=n.endpoint,i=n.isElementSelectable;this.logger=r,o&&this.endpoint===v&&(this.endpoint=o);var l=null;window.addEventListener("message",(function(e){var n,r,o,a,u;if(null===(r=null===(n=t.logger)||void 0===n?void 0:n.debug)||void 0===r||r.call(n,"Message received: ",JSON.stringify(e)),t.endpoint===e.origin){var c,d=null==e?void 0:e.data,s=null==d?void 0:d.action;if(s)if("id"in d)null===(a=null===(o=t.logger)||void 0===o?void 0:o.debug)||void 0===a||a.call(o,"Received Response to previous request: ",JSON.stringify(e)),t.handleResponse(d);else if("ping"===s)t.notify({action:"pong"});else if("initialize-visual-tagging-selector"===s){var f=null==d?void 0:d.data;(c="https://cdn.amplitude.com/libs/visual-tagging-selector-1.0.0-alpha.js.gz",new Promise((function(e,t){var n;try{var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src=c,r.addEventListener("load",(function(){e({status:!0})}),{once:!0}),r.addEventListener("error",(function(){t({status:!1,message:"Failed to load the script ".concat(c)})})),null===(n=document.head)||void 0===n||n.appendChild(r)}catch(e){t(e)}}))).then((function(){var e;l=null===(e=null===window||void 0===window?void 0:window.amplitudeVisualTaggingSelector)||void 0===e?void 0:e.call(window,{getEventTagProps:U,isElementSelectable:function(e){return!i||i((null==f?void 0:f.actionType)||"click",e)},onTrack:t.onTrack,onSelect:t.onSelect,visualHighlightClass:g,messenger:t}),t.notify({action:"selector-loaded"})})).catch((function(){var e;null===(e=t.logger)||void 0===e||e.warn("Failed to initialize visual tagging selector")}))}else"close-visual-tagging-selector"===s&&(null===(u=null==l?void 0:l.close)||void 0===u||u.call(l))}})),this.notify({action:"page-loaded"})},e}(),F=["id","class","style","value","onclick","onchange","oninput","onblur","onsubmit","onfocus","onkeydown","onkeyup","onkeypress","data-reactid","data-react-checksum","data-reactroot"],W=["type"],z=["svg","path","g"],I=["password","hidden"];function J(e){var t,n,r,i,l,a;if(null===e)return null;var u=e.tagName.toLowerCase(),c={tag:u},d=Array.from(null!==(i=null===(r=e.parentElement)||void 0===r?void 0:r.children)&&void 0!==i?i:[]);d.length&&(c.index=d.indexOf(e),c.indexOfType=d.filter((function(t){return t.tagName===e.tagName})).indexOf(e));var s=null===(a=null===(l=e.previousElementSibling)||void 0===l?void 0:l.tagName)||void 0===a?void 0:a.toLowerCase();s&&(c.prevSib=s);var f=e.id;f&&(c.id=f);var v=Array.from(e.classList);v.length&&(c.classes=v);var p={},g=Array.from(e.attributes).filter((function(e){return!F.includes(e.name)})),h=!M(e);if(!I.includes(e.type)&&!z.includes(u))try{for(var m=o(g),y=m.next();!y.done;y=m.next()){var w=y.value;h&&!W.includes(w.name)||(p[w.name]=String(w.value).substring(0,128))}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=m.return)&&n.call(m)}finally{if(t)throw t.error}}return Object.keys(p).length&&(c.attrs=p),c}var V=["a","button","input","select","textarea","label","[data-amp-default-track]",".amp-default-track"],B="data-amp-track-",G=function(e){void 0===e&&(e={});var o,i=e.cssSelectorAllowlist,l=void 0===i?V:i,a=e.pageUrlAllowlist,u=e.shouldTrackEventResolver,v=e.dataAttributePrefix,g=void 0===v?B:v,h=e.visualTaggingOptions,m=void 0===h?{enabled:!0,messenger:new H}:h,y="@amplitude/plugin-autocapture-browser",w=[],b=void 0,E=function(e,t,n){e.addEventListener(t,n),w.push({element:e,type:t,handler:n})},S=function(e,t){var n,r,o;if(!t)return!1;var i=null===(r=null===(n=null==t?void 0:t.tagName)||void 0===n?void 0:n.toLowerCase)||void 0===r?void 0:r.call(n);if(!i)return!1;if(u)return u(e,t);if(!function(e,t){return!t||!t.length||t.some((function(t){return"string"==typeof t?e===t:e.match(t)}))}(window.location.href,a))return!1;var c=(null==t?void 0:t.type)||"";if("string"==typeof c)switch(c.toLowerCase()){case"hidden":case"password":return!1}if(l){var d=l.some((function(e){var n;return!!(null===(n=null==t?void 0:t.matches)||void 0===n?void 0:n.call(t,e))}));if(!d)return!1}switch(i){case"input":case"select":case"textarea":return"change"===e||"click"===e;default:var s=null===(o=null===window||void 0===window?void 0:window.getComputedStyle)||void 0===o?void 0:o.call(window,t);return!(!s||"pointer"!==s.getPropertyValue("cursor")||"click"!==e)||"click"===e}},A=function(e,t){var n,r,o,i=null===(o=null===(r=null==t?void 0:t.tagName)||void 0===r?void 0:r.toLowerCase)||void 0===o?void 0:o.call(r),l="function"==typeof t.getBoundingClientRect?t.getBoundingClientRect():{left:null,top:null},a=t.getAttribute("aria-label"),u=function(e,t){return e.getAttributeNames().reduce((function(n,r){if(r.startsWith(t)){var o=r.replace(t,""),i=e.getAttribute(r);o&&(n[o]=i||"")}return n}),{})}(t,g),v=R(t),p=q(t,b),h=((n={})["[Amplitude] Element ID"]=t.id,n["[Amplitude] Element Class"]=t.className,n["[Amplitude] Element Hierarchy"]=function(e){var t=2,n=[];if(!e)return n;for(var r=function(e){var t=[];if(!e)return t;t.push(e);for(var n=e.parentElement;n&&"HTML"!==n.tagName;)t.push(n),n=n.parentElement;return t}(e),o=0;o<r.length;o++){var i=J(r[o]),l=JSON.stringify(i).length,a=o>0?1:0;if(t+l+a>1024)break;t+=l+a,n.unshift(i)}return n}(t),n[c]=i,n[d]=P(t),n["[Amplitude] Element Position Left"]=null==l.left?null:Math.round(l.left),n["[Amplitude] Element Position Top"]=null==l.top?null:Math.round(l.top),n["[Amplitude] Element Aria Label"]=a,n["[Amplitude] Element Attributes"]=u,n[s]=p,n["[Amplitude] Element Parent Label"]=v,n[f]=window.location.href.split("?")[0],n["[Amplitude] Page Title"]="undefined"!=typeof document&&document.title||"",n["[Amplitude] Viewport Height"]=window.innerHeight,n["[Amplitude] Viewport Width"]=window.innerWidth,n);return"a"===i&&"click"===e&&t instanceof HTMLAnchorElement&&(h["[Amplitude] Element Href"]=t.href),j(h)};return{name:y,type:"enrichment",setup:function(e,i){return n(void 0,void 0,void 0,(function(){var n,a,u,c,d;return r(this,(function(r){return i?(b=e.loggerProvider,"undefined"==typeof document||(n=function(e){S("click",e)&&E(e,"click",(function(t){(null==t?void 0:t.target)!=(null==t?void 0:t.currentTarget)&&_(null==t?void 0:t.target,l)!=(null==t?void 0:t.currentTarget)||null==i||i.track("[Amplitude] Element Clicked",A("click",e))})),S("change",e)&&E(e,"change",(function(t){(null==t?void 0:t.target)!=(null==t?void 0:t.currentTarget)&&_(null==t?void 0:t.target,l)!=(null==t?void 0:t.currentTarget)||null==i||i.track("[Amplitude] Element Changed",A("change",e))}))},"undefined"!=typeof MutationObserver&&(o=new MutationObserver((function(e){e.forEach((function(e){e.addedNodes.forEach((function(e){n(e),"querySelectorAll"in e&&"function"==typeof e.querySelectorAll&&D(e,l).map(n)}))}))}))),a=function(){D(document.body,l).forEach(n),null==o||o.observe(document.body,{subtree:!0,childList:!0})},document.body?a():window.addEventListener("load",a),null===(c=null==e?void 0:e.loggerProvider)||void 0===c||c.log("".concat(y," has been successfully added.")),window.opener&&m.enabled&&(null===(d=m.messenger)||void 0===d||d.setup(t(t({logger:null==e?void 0:e.loggerProvider},(null==e?void 0:e.serverZone)&&{endpoint:p[e.serverZone]}),{isElementSelectable:S})))),[2]):(null===(u=null==e?void 0:e.loggerProvider)||void 0===u||u.warn("".concat(y," plugin requires a later version of @amplitude/analytics-browser. Events are not tracked.")),[2])}))}))},execute:function(e){return n(void 0,void 0,void 0,(function(){return r(this,(function(t){return[2,e]}))}))},teardown:function(){return n(void 0,void 0,void 0,(function(){return r(this,(function(e){return o&&o.disconnect(),w.forEach((function(e){var t=e.element,n=e.type,r=e.handler;null==t||t.removeEventListener(n,r)})),w=[],[2]}))}))}}};e.DEFAULT_CSS_SELECTOR_ALLOWLIST=V,e.DEFAULT_DATA_ATTRIBUTE_PREFIX=B,e.WindowMessenger=H,e.autocapturePlugin=G,e.plugin=G,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).amplitude={})}(this,(function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},t.apply(this,arguments)};function n(e,t,n,r){return new(n||(n=Promise))((function(o,i){function l(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}u((r=r.apply(e,t||[])).next())}))}function r(e,t){var n,r,o,i,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(l=0)),l;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=l.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=t.call(e,l)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function o(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),l=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)l.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return l}function l(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}var a,u,c="[Amplitude] Element Tag",s="[Amplitude] Element Text",d="[Amplitude] Element Selector",f="[Amplitude] Page URL",v="https://app.amplitude.com",p={US:v,EU:"https://app.eu.amplitude.com",STAGING:"https://apps.stag2.amplitude.com"},g="amp-visual-tagging-selector-highlight";function h(e,n){if(e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";var r={root:document.body,idName:function(e){return!0},className:function(e){return!0},tagName:function(e){return!0},attr:function(e,t){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};a=t(t({},r),n),u=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(a.root,r);var o=m(e,"all",(function(){return m(e,"two",(function(){return m(e,"one",(function(){return m(e,"none")}))}))}));if(o){var i=C(L(o,e));return i.length>0&&(o=i[0]),w(o)}throw new Error("Selector was not found.")}function m(e,t,n){for(var r=null,u=[],c=e,s=0,d=function(){var e,d,f=N(function(e){var t=e.getAttribute("id");if(t&&a.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(c))||N.apply(void 0,l([],i(function(e){var t=Array.from(e.attributes).filter((function(e){return a.attr(e.name,e.value)}));return t.map((function(e){return{name:"[".concat(CSS.escape(e.name),'="').concat(CSS.escape(e.value),'"]'),penalty:.5}}))}(c)),!1))||N.apply(void 0,l([],i(function(e){var t=Array.from(e.classList).filter(a.className);return t.map((function(e){return{name:"."+CSS.escape(e),penalty:1}}))}(c)),!1))||N(function(e){var t=e.tagName.toLowerCase();if(a.tagName(t))return{name:t,penalty:2};return null}(c))||[{name:"*",penalty:3}],v=function(e){var t=e.parentNode;if(!t)return null;var n=t.firstChild;if(!n)return null;var r=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&r++,n!==e);)n=n.nextSibling;return r}(c);if("all"==t)v&&(f=f.concat(f.filter(A).map((function(e){return S(e,v)}))));else if("two"==t)f=f.slice(0,1),v&&(f=f.concat(f.filter(A).map((function(e){return S(e,v)}))));else if("one"==t){var p=i(f=f.slice(0,1),1)[0];v&&A(p)&&(f=[S(p,v)])}else"none"==t&&(f=[{name:"*",penalty:3}],v&&(f=[S(f[0],v)]));try{for(var g=(e=void 0,o(f)),h=g.next();!h.done;h=g.next()){(p=h.value).level=s}}catch(t){e={error:t}}finally{try{h&&!h.done&&(d=g.return)&&d.call(g)}finally{if(e)throw e.error}}if(u.push(f),u.length>=a.seedMinLength&&(r=y(u,n)))return"break";c=c.parentElement,s++};c;){if("break"===d())break}return r||(r=y(u,n)),!r&&n?n():r}function y(e,t){var n,r,i=C(T(e));if(i.length>a.threshold)return t?t():null;try{for(var l=o(i),u=l.next();!u.done;u=l.next()){var c=u.value;if(E(c))return c}}catch(e){n={error:e}}finally{try{u&&!u.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}return null}function w(e){for(var t=e[0],n=t.name,r=1;r<e.length;r++){var o=e[r].level||0;n=t.level===o-1?"".concat(e[r].name," > ").concat(n):"".concat(e[r].name," ").concat(n),t=e[r]}return n}function b(e){return e.map((function(e){return e.penalty})).reduce((function(e,t){return e+t}),0)}function E(e){var t=w(e);switch(u.querySelectorAll(t).length){case 0:throw new Error("Can't select any node with this selector: ".concat(t));case 1:return!0;default:return!1}}function S(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function A(e){return"html"!==e.name&&!e.name.startsWith("#")}function N(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(k);return n.length>0?n:null}function k(e){return null!=e}function T(e,t){var n,i,l,a,u,c;return void 0===t&&(t=[]),r(this,(function(r){switch(r.label){case 0:if(!(e.length>0))return[3,9];r.label=1;case 1:r.trys.push([1,6,7,8]),n=o(e[0]),i=n.next(),r.label=2;case 2:return i.done?[3,5]:(l=i.value,[5,o(T(e.slice(1,e.length),t.concat(l)))]);case 3:r.sent(),r.label=4;case 4:return i=n.next(),[3,2];case 5:return[3,8];case 6:return a=r.sent(),u={error:a},[3,8];case 7:try{i&&!i.done&&(c=n.return)&&c.call(n)}finally{if(u)throw u.error}return[7];case 8:return[3,11];case 9:return[4,t];case 10:r.sent(),r.label=11;case 11:return[2]}}))}function C(e){return l([],i(e),!1).sort((function(e,t){return b(e)-b(t)}))}function L(e,t,n){var c,s,d;return void 0===n&&(n={counter:0,visited:new Map}),r(this,(function(r){switch(r.label){case 0:if(!(e.length>2&&e.length>a.optimizedMinLength))return[3,5];c=1,r.label=1;case 1:return c<e.length-1?n.counter>a.maxNumberOfTries?[2]:(n.counter+=1,(s=l([],i(e),!1)).splice(c,1),d=w(s),n.visited.has(d)?[2]:E(s)&&function(e,t){return u.querySelector(w(e))===t}(s,t)?[4,s]:[3,4]):[3,5];case 2:return r.sent(),n.visited.set(d,!0),[5,o(L(s,t,n))];case 3:r.sent(),r.label=4;case 4:return c++,[3,1];case 5:return[2]}}))}var x=["input","select","textarea"],O=function(e){if(null==e)return!1;if("string"==typeof e){if(/^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/.test((e||"").replace(/[- ]/g,"")))return!1;if(/(^\d{3}-?\d{2}-?\d{4}$)/.test(e))return!1}return!0},M=function(e){var t,n,r=null===(n=null===(t=null==e?void 0:e.tagName)||void 0===t?void 0:t.toLowerCase)||void 0===n?void 0:n.call(t),o="true"===e.getAttribute("contenteditable");return!x.includes(r)&&!o},P=function(e){var t="";return M(e)&&e.childNodes&&e.childNodes.length&&e.childNodes.forEach((function(e){var n,r="";(n=e)&&3===n.nodeType?e.textContent&&(r=e.textContent):r=P(e),t+=r.split(/(\s+)/).filter(O).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)})),t},j=function(e,t){var n,r,o="";try{return o=h(e,{className:function(e){return e!==g}})}catch(e){if(t){var i=e;t.warn("Failed to get selector with finder, use fallback strategy instead: ".concat(i.toString()))}}var l=null===(r=null===(n=null==e?void 0:e.tagName)||void 0===n?void 0:n.toLowerCase)||void 0===r?void 0:r.call(n);if(l&&(o=l),e.id)o="#".concat(e.id);else if(e.className){var a=e.className.split(" ").filter((function(e){return e!==g})).join(".");a&&(o="".concat(o,".").concat(a))}return o},q=function(e){return Object.keys(e).reduce((function(t,n){var r=e[n];return function(e){return null==e||"object"==typeof e&&0===Object.keys(e).length||"string"==typeof e&&0===e.trim().length}(r)||(t[n]=r),t}),{})},R=function(e){var t=e.parentElement;if(!t)return"";var n=t.querySelector(":scope>span,h1,h2,h3,h4,h5,h6");if(n){var r=n.textContent||"";return O(r)?r:""}return R(t)},D=function(e,t){if(e&&"querySelectorAll"in e&&"function"==typeof e.querySelectorAll){var n=t.reduce((function(t,n){n&&Array.from(e.querySelectorAll(n)).forEach((function(e){t.add(e)}));return t}),new Set);return Array.from(n)}return[]},_=function(e,t){return e?t.some((function(t){var n;return null===(n=null==e?void 0:e.matches)||void 0===n?void 0:n.call(e,t)}))?e:_(null==e?void 0:e.parentElement,t):null},U=function(e,t){var n,r,o;if(!e)return{};var i=null===(o=null===(r=null==e?void 0:e.tagName)||void 0===r?void 0:r.toLowerCase)||void 0===o?void 0:o.call(r),l=j(e,t),a=((n={})[c]=i,n[s]=P(e),n[d]=l,n[f]=window.location.href.split("?")[0],n);return q(a)};var F=function(){function e(e){var t=(void 0===e?{}:e).origin,n=void 0===t?v:t,r=this;this.endpoint=v,this.requestCallbacks={},this.onSelect=function(e){r.notify({action:"element-selected",data:e})},this.onTrack=function(e,t){"selector-mode-changed"===e?r.notify({action:"track-selector-mode-changed",data:t}):"selector-moved"===e&&r.notify({action:"track-selector-moved",data:t})},this.endpoint=n}return e.prototype.notify=function(e){var t,n,r,o;null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message sent: ",JSON.stringify(e)),null===(o=null===(r=window.opener)||void 0===r?void 0:r.postMessage)||void 0===o||o.call(r,e,this.endpoint)},e.prototype.sendRequest=function(e,t,n){var r=this;void 0===n&&(n={timeout:15e3});var o="".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),i={id:o,action:e,args:t};return new Promise((function(t,l){r.requestCallbacks[o]={resolve:t,reject:l},r.notify(i),(null==n?void 0:n.timeout)>0&&setTimeout((function(){l(new Error("".concat(e," timed out (id: ").concat(o,")"))),delete r.requestCallbacks[o]}),n.timeout)}))},e.prototype.handleResponse=function(e){var t;this.requestCallbacks[e.id]?(this.requestCallbacks[e.id].resolve(e.responseData),delete this.requestCallbacks[e.id]):null===(t=this.logger)||void 0===t||t.warn("No callback found for request id: ".concat(e.id))},e.prototype.setup=function(e){var t=this,n=void 0===e?{}:e,r=n.logger,o=n.endpoint,i=n.isElementSelectable;this.logger=r,o&&this.endpoint===v&&(this.endpoint=o);var l=null;window.addEventListener("message",(function(e){var n,r,o,a,u;if(null===(r=null===(n=t.logger)||void 0===n?void 0:n.debug)||void 0===r||r.call(n,"Message received: ",JSON.stringify(e)),t.endpoint===e.origin){var c,s=null==e?void 0:e.data,d=null==s?void 0:s.action;if(d)if("id"in s)null===(a=null===(o=t.logger)||void 0===o?void 0:o.debug)||void 0===a||a.call(o,"Received Response to previous request: ",JSON.stringify(e)),t.handleResponse(s);else if("ping"===d)t.notify({action:"pong"});else if("initialize-visual-tagging-selector"===d){var f=null==s?void 0:s.data;(c="https://cdn.amplitude.com/libs/visual-tagging-selector-1.0.0-alpha.js.gz",new Promise((function(e,t){var n;try{var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src=c,r.addEventListener("load",(function(){e({status:!0})}),{once:!0}),r.addEventListener("error",(function(){t({status:!1,message:"Failed to load the script ".concat(c)})})),null===(n=document.head)||void 0===n||n.appendChild(r)}catch(e){t(e)}}))).then((function(){var e;l=null===(e=null===window||void 0===window?void 0:window.amplitudeVisualTaggingSelector)||void 0===e?void 0:e.call(window,{getEventTagProps:U,isElementSelectable:function(e){return!i||i((null==f?void 0:f.actionType)||"click",e)},onTrack:t.onTrack,onSelect:t.onSelect,visualHighlightClass:g,messenger:t}),t.notify({action:"selector-loaded"})})).catch((function(){var e;null===(e=t.logger)||void 0===e||e.warn("Failed to initialize visual tagging selector")}))}else"close-visual-tagging-selector"===d&&(null===(u=null==l?void 0:l.close)||void 0===u||u.call(l))}})),this.notify({action:"page-loaded"})},e}(),H=["id","class","style","value","onclick","onchange","oninput","onblur","onsubmit","onfocus","onkeydown","onkeyup","onkeypress","data-reactid","data-react-checksum","data-reactroot"],W=["type"],z=["svg","path","g"],I=["password","hidden"];var V=function(e){var t;return e?(t=function(e,t){for(var n=0,r=0;r<e.length;r++){var o=e[r];if(null===o)n+=4;else{var i=B(o);n+=i?Array.from(i).length:4}if(n>t)return e.slice(0,r)}return e}(function(e){var t=[];if(!e)return t;t.push(e);for(var n=e.parentElement;n&&"HTML"!==n.tagName;)t.push(n),n=n.parentElement;return t}(e).map((function(e){return function(e){var t,n,r,i,l,a;if(null===e)return null;var u=e.tagName.toLowerCase(),c={tag:u},s=Array.from(null!==(i=null===(r=e.parentElement)||void 0===r?void 0:r.children)&&void 0!==i?i:[]);s.length&&(c.index=s.indexOf(e),c.indexOfType=s.filter((function(t){return t.tagName===e.tagName})).indexOf(e));var d=null===(a=null===(l=e.previousElementSibling)||void 0===l?void 0:l.tagName)||void 0===a?void 0:a.toLowerCase();d&&(c.prevSib=d);var f=e.id;f&&(c.id=f);var v=Array.from(e.classList);v.length&&(c.classes=v);var p={},g=Array.from(e.attributes).filter((function(e){return!H.includes(e.name)})),h=!M(e);if(!I.includes(e.type)&&!z.includes(u))try{for(var m=o(g),y=m.next();!y.done;y=m.next()){var w=y.value;h&&!W.includes(w.name)||(p[w.name]=String(w.value).substring(0,128))}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=m.return)&&n.call(m)}finally{if(t)throw t.error}}return Object.keys(p).length&&(c.attrs=p),c}(e)})),1024),t):[]};function B(e,t){void 0===t&&(t=!1);try{if(null==e)return t?"None":null;if("string"==typeof e)return t?(e=e.replace(/\\/g,"\\\\").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")).includes('"')?"'".concat(e,"'"):e.includes("'")?'"'.concat(e.replace(/'/g,"\\'"),'"'):"'".concat(e,"'"):e;if("boolean"==typeof e)return e?"True":"False";if(Array.isArray(e)){var n=e.map((function(e){return B(e,!0)}));return"[".concat(n.join(", "),"]")}if("object"==typeof e){var r=Object.entries(e).filter((function(e){return null!=i(e,1)[0]})).map((function(e){var t=i(e,2),n=t[0],r=t[1];return"".concat(String(B(n,!0)),": ").concat(String(B(r,!0)))})),o="{".concat(r.join(", "),"}");return o.includes("\\'")&&(o=o.replace(/'/g,"'").replace(/'/g,"\\'")),o}return e.toString()}catch(e){return null}}var G=["a","button","input","select","textarea","label","[data-amp-default-track]",".amp-default-track"],J="data-amp-track-",Z=function(e){void 0===e&&(e={});var o,i=e.cssSelectorAllowlist,l=void 0===i?G:i,a=e.pageUrlAllowlist,u=e.shouldTrackEventResolver,v=e.dataAttributePrefix,g=void 0===v?J:v,h=e.visualTaggingOptions,m=void 0===h?{enabled:!0,messenger:new F}:h,y="@amplitude/plugin-autocapture-browser",w=[],b=void 0,E=function(e,t,n){e.addEventListener(t,n),w.push({element:e,type:t,handler:n})},S=function(e,t){var n,r,o;if(!t)return!1;var i=null===(r=null===(n=null==t?void 0:t.tagName)||void 0===n?void 0:n.toLowerCase)||void 0===r?void 0:r.call(n);if(!i)return!1;if(u)return u(e,t);if(!function(e,t){return!t||!t.length||t.some((function(t){return"string"==typeof t?e===t:e.match(t)}))}(window.location.href,a))return!1;var c=(null==t?void 0:t.type)||"";if("string"==typeof c)switch(c.toLowerCase()){case"hidden":case"password":return!1}if(l){var s=l.some((function(e){var n;return!!(null===(n=null==t?void 0:t.matches)||void 0===n?void 0:n.call(t,e))}));if(!s)return!1}switch(i){case"input":case"select":case"textarea":return"change"===e||"click"===e;default:var d=null===(o=null===window||void 0===window?void 0:window.getComputedStyle)||void 0===o?void 0:o.call(window,t);return!(!d||"pointer"!==d.getPropertyValue("cursor")||"click"!==e)||"click"===e}},A=function(e,t){var n,r,o,i=null===(o=null===(r=null==t?void 0:t.tagName)||void 0===r?void 0:r.toLowerCase)||void 0===o?void 0:o.call(r),l="function"==typeof t.getBoundingClientRect?t.getBoundingClientRect():{left:null,top:null},a=t.getAttribute("aria-label"),u=function(e,t){return e.getAttributeNames().reduce((function(n,r){if(r.startsWith(t)){var o=r.replace(t,""),i=e.getAttribute(r);o&&(n[o]=i||"")}return n}),{})}(t,g),v=R(t),p=j(t,b),h=((n={})["[Amplitude] Element ID"]=t.id,n["[Amplitude] Element Class"]=t.className,n["[Amplitude] Element Hierarchy"]=V(t),n[c]=i,n[s]=P(t),n["[Amplitude] Element Position Left"]=null==l.left?null:Math.round(l.left),n["[Amplitude] Element Position Top"]=null==l.top?null:Math.round(l.top),n["[Amplitude] Element Aria Label"]=a,n["[Amplitude] Element Attributes"]=u,n[d]=p,n["[Amplitude] Element Parent Label"]=v,n[f]=window.location.href.split("?")[0],n["[Amplitude] Page Title"]="undefined"!=typeof document&&document.title||"",n["[Amplitude] Viewport Height"]=window.innerHeight,n["[Amplitude] Viewport Width"]=window.innerWidth,n);return"a"===i&&"click"===e&&t instanceof HTMLAnchorElement&&(h["[Amplitude] Element Href"]=t.href),q(h)};return{name:y,type:"enrichment",setup:function(e,i){return n(void 0,void 0,void 0,(function(){var n,a,u,c,s;return r(this,(function(r){return i?(b=e.loggerProvider,"undefined"==typeof document||(n=function(e){S("click",e)&&E(e,"click",(function(t){(null==t?void 0:t.target)!=(null==t?void 0:t.currentTarget)&&_(null==t?void 0:t.target,l)!=(null==t?void 0:t.currentTarget)||null==i||i.track("[Amplitude] Element Clicked",A("click",e))})),S("change",e)&&E(e,"change",(function(t){(null==t?void 0:t.target)!=(null==t?void 0:t.currentTarget)&&_(null==t?void 0:t.target,l)!=(null==t?void 0:t.currentTarget)||null==i||i.track("[Amplitude] Element Changed",A("change",e))}))},"undefined"!=typeof MutationObserver&&(o=new MutationObserver((function(e){e.forEach((function(e){e.addedNodes.forEach((function(e){n(e),"querySelectorAll"in e&&"function"==typeof e.querySelectorAll&&D(e,l).map(n)}))}))}))),a=function(){D(document.body,l).forEach(n),null==o||o.observe(document.body,{subtree:!0,childList:!0})},document.body?a():window.addEventListener("load",a),null===(c=null==e?void 0:e.loggerProvider)||void 0===c||c.log("".concat(y," has been successfully added.")),window.opener&&m.enabled&&(null===(s=m.messenger)||void 0===s||s.setup(t(t({logger:null==e?void 0:e.loggerProvider},(null==e?void 0:e.serverZone)&&{endpoint:p[e.serverZone]}),{isElementSelectable:S})))),[2]):(null===(u=null==e?void 0:e.loggerProvider)||void 0===u||u.warn("".concat(y," plugin requires a later version of @amplitude/analytics-browser. Events are not tracked.")),[2])}))}))},execute:function(e){return n(void 0,void 0,void 0,(function(){return r(this,(function(t){return[2,e]}))}))},teardown:function(){return n(void 0,void 0,void 0,(function(){return r(this,(function(e){return o&&o.disconnect(),w.forEach((function(e){var t=e.element,n=e.type,r=e.handler;null==t||t.removeEventListener(n,r)})),w=[],[2]}))}))}}};e.DEFAULT_CSS_SELECTOR_ALLOWLIST=G,e.DEFAULT_DATA_ATTRIBUTE_PREFIX=J,e.WindowMessenger=F,e.autocapturePlugin=Z,e.plugin=Z,Object.defineProperty(e,"__esModule",{value:!0})})); |
import { Logger } from '@amplitude/analytics-types'; | ||
export type JSONValue = string | number | boolean | { | ||
export type JSONValue = string | number | boolean | null | { | ||
[x: string]: JSONValue; | ||
@@ -4,0 +4,0 @@ } | Array<JSONValue>; |
@@ -0,1 +1,2 @@ | ||
import { JSONValue } from './helpers'; | ||
import { Hierarchy, HierarchyNode } from './typings/autocapture'; | ||
@@ -5,2 +6,12 @@ export declare function getElementProperties(element: Element | null): HierarchyNode | null; | ||
export declare const getHierarchy: (element: Element | null) => Hierarchy; | ||
export declare function ensureListUnderLimit(list: Hierarchy | JSONValue[], bytesLimit: number): Hierarchy | JSONValue[]; | ||
/** | ||
* Converts a JSON-compatible value to a Python-compatible string representation. | ||
* This function handles various data types and ensures proper escaping and formatting. | ||
* | ||
* @param value - The value to be converted (can be any JSON-compatible type) | ||
* @param nested - Indicates if the value is nested within another structure (default: false) | ||
* @returns A string representation of the value compatible with Python, or null if conversion fails | ||
*/ | ||
export declare function ensureUnicodePythonCompatible(value: HierarchyNode | JSONValue | null, nested?: boolean): string | null; | ||
//# sourceMappingURL=hierarchy.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "1.0.0-beta.0"; | ||
export declare const VERSION = "1.0.0-beta.1"; | ||
//# sourceMappingURL=version.d.ts.map |
{ | ||
"name": "@amplitude/plugin-autocapture-browser", | ||
"version": "1.0.0-beta.1", | ||
"version": "1.0.0-beta.2", | ||
"description": "", | ||
@@ -60,3 +60,3 @@ "author": "Amplitude Inc", | ||
], | ||
"gitHead": "c06628a018b7b2062fc357147c8c832810b3a922" | ||
"gitHead": "25e93059b952a89b450201683355aa3ebe1c6ffa" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
376544
3150