@amplitude/analytics-browser 2.22.0 → 2.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +1 -1
  2. package/lib/cjs/config/joined-config.d.ts +28 -0
  3. package/lib/cjs/config/joined-config.d.ts.map +1 -1
  4. package/lib/cjs/config/joined-config.js +88 -4
  5. package/lib/cjs/config/joined-config.js.map +1 -1
  6. package/lib/cjs/config.d.ts +1 -1
  7. package/lib/cjs/version.d.ts +1 -1
  8. package/lib/cjs/version.js +1 -1
  9. package/lib/cjs/version.js.map +1 -1
  10. package/lib/esm/config/joined-config.d.ts +28 -0
  11. package/lib/esm/config/joined-config.d.ts.map +1 -1
  12. package/lib/esm/config/joined-config.js +86 -3
  13. package/lib/esm/config/joined-config.js.map +1 -1
  14. package/lib/esm/config.d.ts +1 -1
  15. package/lib/esm/version.d.ts +1 -1
  16. package/lib/esm/version.js +1 -1
  17. package/lib/esm/version.js.map +1 -1
  18. package/lib/scripts/amplitude-bookmarklet-snippet-min.js +1 -1
  19. package/lib/scripts/amplitude-bookmarklet.html +1 -1
  20. package/lib/scripts/amplitude-gtm-min.js +1 -1
  21. package/lib/scripts/amplitude-gtm-min.js.gz +0 -0
  22. package/lib/scripts/amplitude-gtm-min.js.map +1 -1
  23. package/lib/scripts/amplitude-gtm-snippet-min.js +1 -1
  24. package/lib/scripts/amplitude-min.js +1 -1
  25. package/lib/scripts/amplitude-min.js.gz +0 -0
  26. package/lib/scripts/amplitude-min.js.map +1 -1
  27. package/lib/scripts/amplitude-min.umd.js +1 -1
  28. package/lib/scripts/amplitude-min.umd.js.gz +0 -0
  29. package/lib/scripts/amplitude-snippet-instructions.html +1 -1
  30. package/lib/scripts/amplitude-snippet-min.js +1 -1
  31. package/lib/scripts/config/joined-config.d.ts +28 -0
  32. package/lib/scripts/config/joined-config.d.ts.map +1 -1
  33. package/lib/scripts/config.d.ts +1 -1
  34. package/lib/scripts/version.d.ts +1 -1
  35. package/package.json +7 -7
package/README.md CHANGED
@@ -53,7 +53,7 @@ This SDK is also available through CDN. Copy the script loader below and paste b
53
53
  <!-- README_SNIPPET_BLOCK -->
54
54
  ```html
55
55
  <script type="text/javascript">
56
- !function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},o=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))};!function(e,t,r){e._q.push({name:t,args:Array.prototype.slice.call(r,0)})}(e,t,Array.prototype.slice.call(arguments))}},i=function(e){for(var t=0;t<y.length;t++)o(e,y[t],!1);for(var r=0;r<m.length;r++)o(e,m[r],!0)};r.invoked=!0;var a=t.createElement("script");a.type="text/javascript",a.integrity="sha384-IUW8RjRN702gJvUVDSmYo1mlK5T6rvXQB7Naxm+l1aeYOyifGXytp09FVaoZPXhr",a.crossOrigin="anonymous",a.async=!0,a.src="https://cdn.amplitude.com/libs/analytics-browser-2.22.0-min.js.gz",a.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var c=t.getElementsByTagName("script")[0];c.parentNode.insertBefore(a,c);for(var u=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],p=0;p<l.length;p++)n(u,l[p]);r.Identify=u;for(var d=function(){return this._q=[],this},f=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setReceipt","setReceiptSig","setCurrency","setEventProperties"],v=0;v<f.length;v++)n(d,f[v]);r.Revenue=d;var y=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],m=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];i(r),r.createInstance=function(e){return r._iq[e]={_q:[]},i(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
56
+ !function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},o=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))};!function(e,t,r){e._q.push({name:t,args:Array.prototype.slice.call(r,0)})}(e,t,Array.prototype.slice.call(arguments))}},i=function(e){for(var t=0;t<v.length;t++)o(e,v[t],!1);for(var r=0;r<g.length;r++)o(e,g[r],!0)};r.invoked=!0;var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-VDysG3y8O289yWNGGS5ESEU5j/t67M0RoQzTAd8C0RU6oep9uB64PVjIqHkX7O4N",c.crossOrigin="anonymous",c.async=!0,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.22.1-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var a=t.getElementsByTagName("script")[0];a.parentNode.insertBefore(c,a);for(var u=function(){return this._q=[],this},p=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],l=0;l<p.length;l++)n(u,p[l]);r.Identify=u;for(var d=function(){return this._q=[],this},y=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setReceipt","setReceiptSig","setCurrency","setEventProperties"],f=0;f<y.length;f++)n(d,y[f]);r.Revenue=d;var v=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],g=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];i(r),r.createInstance=function(e){return r._iq[e]={_q:[]},i(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
57
57
 
58
58
  amplitude.init("<YOUR_API_KEY>");
59
59
  </script>
@@ -8,6 +8,34 @@ export interface ElementInteractionsOptionsRemoteConfig extends ElementInteracti
8
8
  */
9
9
  pageUrlAllowlistRegex?: string[];
10
10
  }
11
+ /**
12
+ * Performs a deep transformation of a remote config object so that
13
+ * it matches the expected schema of the local config.
14
+ *
15
+ * Specifically, it normalizes nested `enabled` flags into concise union types.
16
+ *
17
+ * ### Transformation Rules:
18
+ * - If an object has `enabled: true`, it is replaced by the same object without the `enabled` field.
19
+ * - If it has only `enabled: true`, it is replaced with `true`.
20
+ * - If it has `enabled: false`, it is replaced with `false` regardless of other fields.
21
+ *
22
+ * ### Examples:
23
+ * Input: { prop: { enabled: true, hello: 'world' }}
24
+ * Output: { prop: { hello: 'world' } }
25
+ *
26
+ * Input: { prop: { enabled: true }}
27
+ * Output: { prop: true }
28
+ *
29
+ * Input: { prop: { enabled: false, hello: 'world' }}
30
+ * Output: { prop: false }
31
+ *
32
+ * Input: { prop: { hello: 'world' }}
33
+ * Output: { prop: { hello: 'world' } } // No change
34
+ *
35
+ * @param config Remote config object to be transformed
36
+ * @returns Transformed config object compatible with local schema
37
+ */
38
+ export declare function translateRemoteConfigToLocal(config?: Record<string, any>): void;
11
39
  /**
12
40
  * Updates the browser config in place by applying remote configuration settings.
13
41
  * Primarily merges autocapture settings from the remote config into the browser config.
@@ -1 +1 @@
1
- {"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,0BAA0B,EAC/B,aAAa,EACb,YAAY,EACb,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,8BAA+B,SAAQ,kBAAkB;IACxE,mBAAmB,CAAC,EAAE,OAAO,GAAG,sCAAsC,CAAC;CACxE;AACD,MAAM,WAAW,sCAAuC,SAAQ,0BAA0B;IACxF;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAOD;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CACjD,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,aAAa,EAAE,aAAa,GAC3B,IAAI,CAwFN"}
1
+ {"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,0BAA0B,EAC/B,aAAa,EACb,YAAY,EACb,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,8BAA+B,SAAQ,kBAAkB;IACxE,mBAAmB,CAAC,EAAE,OAAO,GAAG,sCAAsC,CAAC;CACxE;AACD,MAAM,WAAW,sCAAuC,SAAQ,0BAA0B;IACxF;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QA2CxE;AAED;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CACjD,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,aAAa,EAAE,aAAa,GAC3B,IAAI,CA2FN"}
@@ -1,7 +1,89 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateBrowserConfigWithRemoteConfig = void 0;
3
+ exports.updateBrowserConfigWithRemoteConfig = exports.translateRemoteConfigToLocal = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ /**
6
+ * Performs a deep transformation of a remote config object so that
7
+ * it matches the expected schema of the local config.
8
+ *
9
+ * Specifically, it normalizes nested `enabled` flags into concise union types.
10
+ *
11
+ * ### Transformation Rules:
12
+ * - If an object has `enabled: true`, it is replaced by the same object without the `enabled` field.
13
+ * - If it has only `enabled: true`, it is replaced with `true`.
14
+ * - If it has `enabled: false`, it is replaced with `false` regardless of other fields.
15
+ *
16
+ * ### Examples:
17
+ * Input: { prop: { enabled: true, hello: 'world' }}
18
+ * Output: { prop: { hello: 'world' } }
19
+ *
20
+ * Input: { prop: { enabled: true }}
21
+ * Output: { prop: true }
22
+ *
23
+ * Input: { prop: { enabled: false, hello: 'world' }}
24
+ * Output: { prop: false }
25
+ *
26
+ * Input: { prop: { hello: 'world' }}
27
+ * Output: { prop: { hello: 'world' } } // No change
28
+ *
29
+ * @param config Remote config object to be transformed
30
+ * @returns Transformed config object compatible with local schema
31
+ */
32
+ function translateRemoteConfigToLocal(config) {
33
+ var e_1, _a;
34
+ // Disabling type checking rules because remote config comes from a remote source
35
+ // and this function needs to handle any unexpected values
36
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access,
37
+ @typescript-eslint/no-unsafe-assignment,
38
+ @typescript-eslint/no-unsafe-argument
39
+ */
40
+ if (typeof config !== 'object' || config === null) {
41
+ return;
42
+ }
43
+ // translations are not applied on array properties
44
+ if (Array.isArray(config)) {
45
+ return;
46
+ }
47
+ var propertyNames = Object.keys(config);
48
+ try {
49
+ for (var propertyNames_1 = tslib_1.__values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
50
+ var propertyName = propertyNames_1_1.value;
51
+ try {
52
+ var value = config[propertyName];
53
+ // transform objects with { enabled } property to boolean | object
54
+ if (typeof (value === null || value === void 0 ? void 0 : value.enabled) === 'boolean') {
55
+ if (value.enabled) {
56
+ // if enabled is true, set the value to the rest of the object
57
+ // or true if the object has no other properties
58
+ delete value.enabled;
59
+ if (Object.keys(value).length === 0) {
60
+ config[propertyName] = true;
61
+ }
62
+ }
63
+ else {
64
+ // If enabled is false, set the value to false
65
+ config[propertyName] = false;
66
+ }
67
+ }
68
+ // recursively translate properties of the value
69
+ translateRemoteConfigToLocal(value);
70
+ }
71
+ catch (e) {
72
+ // a failure here means that an accessor threw an error
73
+ // so don't translate it
74
+ // TODO(diagnostics): add a diagnostic event for this
75
+ }
76
+ }
77
+ }
78
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
79
+ finally {
80
+ try {
81
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
82
+ }
83
+ finally { if (e_1) throw e_1.error; }
84
+ }
85
+ }
86
+ exports.translateRemoteConfigToLocal = translateRemoteConfigToLocal;
5
87
  /**
6
88
  * Updates the browser config in place by applying remote configuration settings.
7
89
  * Primarily merges autocapture settings from the remote config into the browser config.
@@ -10,11 +92,13 @@ var tslib_1 = require("tslib");
10
92
  * @param browserConfig - The browser config object to update (modified in place)
11
93
  */
12
94
  function updateBrowserConfigWithRemoteConfig(remoteConfig, browserConfig) {
13
- var e_1, _a;
95
+ var e_2, _a;
14
96
  var _b, _c;
15
97
  if (!remoteConfig) {
16
98
  return;
17
99
  }
100
+ // translate remote config to local compatible format
101
+ translateRemoteConfigToLocal(remoteConfig);
18
102
  try {
19
103
  browserConfig.loggerProvider.debug('Update browser config with remote configuration:', JSON.stringify(remoteConfig));
20
104
  // type cast error will be thrown if remoteConfig is not a valid RemoteConfigBrowserSDK
@@ -52,12 +136,12 @@ function updateBrowserConfigWithRemoteConfig(remoteConfig, browserConfig) {
52
136
  }
53
137
  }
54
138
  }
55
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
139
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
56
140
  finally {
57
141
  try {
58
142
  if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
59
143
  }
60
- finally { if (e_1) throw e_1.error; }
144
+ finally { if (e_2) throw e_2.error; }
61
145
  }
62
146
  var combinedPageUrlAllowlist = exactAllowList.concat(regexList);
63
147
  transformedRcElementInteractions.pageUrlAllowlist = combinedPageUrlAllowlist;
@@ -1 +1 @@
1
- {"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";;;;AAsBA;;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C,cAAc,CAAC,KAAK,CAAC,4CAA4C,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;KACjH;IAAC,OAAO,CAAC,EAAE;QACV,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,yDAAyD,EAAE,CAAC,CAAC,CAAC;KAClG;AACH,CAAC;AA3FD,kFA2FC","sourcesContent":["import {\n AutocaptureOptions,\n type ElementInteractionsOptions,\n BrowserConfig,\n RemoteConfig,\n} from '@amplitude/analytics-core';\n\nexport interface AutocaptureOptionsRemoteConfig extends AutocaptureOptions {\n elementInteractions?: boolean | ElementInteractionsOptionsRemoteConfig;\n}\nexport interface ElementInteractionsOptionsRemoteConfig extends ElementInteractionsOptions {\n /**\n * Related to pageUrlAllowlist but holds regex strings which will be initialized and appended to pageUrlAllowlist\n */\n pageUrlAllowlistRegex?: string[];\n}\n\n// Type alias for the remote config structure we expect (this is what comes from the filtered browserSDK config)\ntype RemoteConfigBrowserSDK = {\n autocapture?: AutocaptureOptionsRemoteConfig | boolean;\n};\n\n/**\n * Updates the browser config in place by applying remote configuration settings.\n * Primarily merges autocapture settings from the remote config into the browser config.\n *\n * @param remoteConfig - The remote configuration to apply, or null if none available\n * @param browserConfig - The browser config object to update (modified in place)\n */\nexport function updateBrowserConfigWithRemoteConfig(\n remoteConfig: RemoteConfig | null,\n browserConfig: BrowserConfig,\n): void {\n if (!remoteConfig) {\n return;\n }\n\n try {\n browserConfig.loggerProvider.debug(\n 'Update browser config with remote configuration:',\n JSON.stringify(remoteConfig),\n );\n\n // type cast error will be thrown if remoteConfig is not a valid RemoteConfigBrowserSDK\n // and it will be caught by the try-catch block\n const typedRemoteConfig = remoteConfig as RemoteConfigBrowserSDK;\n\n // merge remoteConfig.autocapture and browserConfig.autocapture\n // if a field is in remoteConfig.autocapture, use that value\n // if a field is not in remoteConfig.autocapture, use the value from browserConfig.autocapture\n if (typedRemoteConfig && 'autocapture' in typedRemoteConfig) {\n if (typeof typedRemoteConfig.autocapture === 'boolean') {\n browserConfig.autocapture = typedRemoteConfig.autocapture;\n }\n\n if (typeof typedRemoteConfig.autocapture === 'object' && typedRemoteConfig.autocapture !== null) {\n const transformedAutocaptureRemoteConfig = { ...typedRemoteConfig.autocapture };\n\n if (browserConfig.autocapture === undefined) {\n browserConfig.autocapture = typedRemoteConfig.autocapture;\n }\n\n // Handle Element Interactions config initialization\n if (\n typeof typedRemoteConfig.autocapture.elementInteractions === 'object' &&\n typedRemoteConfig.autocapture.elementInteractions !== null &&\n typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex?.length\n ) {\n transformedAutocaptureRemoteConfig.elementInteractions = {\n ...typedRemoteConfig.autocapture.elementInteractions,\n };\n const transformedRcElementInteractions = transformedAutocaptureRemoteConfig.elementInteractions;\n\n const exactAllowList = transformedRcElementInteractions.pageUrlAllowlist ?? [];\n // Convert string patterns to RegExp objects, warn on invalid patterns and skip them\n const regexList = [];\n for (const pattern of typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex) {\n try {\n regexList.push(new RegExp(pattern));\n } catch (regexError) {\n browserConfig.loggerProvider.warn(`Invalid regex pattern: ${pattern}`, regexError);\n }\n }\n\n const combinedPageUrlAllowlist = exactAllowList.concat(regexList);\n\n transformedRcElementInteractions.pageUrlAllowlist = combinedPageUrlAllowlist;\n delete transformedRcElementInteractions.pageUrlAllowlistRegex;\n }\n\n if (typeof browserConfig.autocapture === 'boolean') {\n browserConfig.autocapture = {\n attribution: browserConfig.autocapture,\n fileDownloads: browserConfig.autocapture,\n formInteractions: browserConfig.autocapture,\n pageViews: browserConfig.autocapture,\n sessions: browserConfig.autocapture,\n elementInteractions: browserConfig.autocapture,\n webVitals: browserConfig.autocapture,\n frustrationInteractions: browserConfig.autocapture,\n ...transformedAutocaptureRemoteConfig,\n };\n }\n\n if (typeof browserConfig.autocapture === 'object') {\n browserConfig.autocapture = {\n ...browserConfig.autocapture,\n ...transformedAutocaptureRemoteConfig,\n };\n }\n }\n\n // Override default tracking options if autocapture is updated by remote config\n browserConfig.defaultTracking = browserConfig.autocapture;\n }\n\n browserConfig.loggerProvider.debug('Browser config after remote config update:', JSON.stringify(browserConfig));\n } catch (e) {\n browserConfig.loggerProvider.error('Failed to apply remote configuration because of error: ', e);\n }\n}\n"]}
1
+ {"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";;;;AAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,4BAA4B,CAAC,MAA4B;;IACvE,iFAAiF;IACjF,0DAA0D;IAC1D;;;KAGC;IACD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE;QACjD,OAAO;KACR;IAED,mDAAmD;IACnD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO;KACR;IAED,IAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;QAC1C,KAA2B,IAAA,kBAAA,iBAAA,aAAa,CAAA,4CAAA,uEAAE;YAArC,IAAM,YAAY,0BAAA;YACrB,IAAI;gBACF,IAAM,KAAK,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;gBACnC,kEAAkE;gBAClE,IAAI,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAA,KAAK,SAAS,EAAE;oBACvC,IAAI,KAAK,CAAC,OAAO,EAAE;wBACjB,8DAA8D;wBAC9D,gDAAgD;wBAChD,OAAO,KAAK,CAAC,OAAO,CAAC;wBACrB,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;4BAClC,MAAc,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;yBACtC;qBACF;yBAAM;wBACL,8CAA8C;wBAC7C,MAAc,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;qBACvC;iBACF;gBAED,gDAAgD;gBAChD,4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,aAAa,CAAC,WAAW,KAAK,QAAQ,EAAE;oBACjD,aAAa,CAAC,WAAW,yCACpB,aAAa,CAAC,WAAW,GACzB,kCAAkC,CACtC,CAAC;iBACH;aACF;YAED,+EAA+E;YAC/E,aAAa,CAAC,eAAe,GAAG,aAAa,CAAC,WAAW,CAAC;SAC3D;QAED,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,4CAA4C,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;KACjH;IAAC,OAAO,CAAC,EAAE;QACV,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,yDAAyD,EAAE,CAAC,CAAC,CAAC;KAClG;AACH,CAAC;AA9FD,kFA8FC","sourcesContent":["import {\n AutocaptureOptions,\n type ElementInteractionsOptions,\n BrowserConfig,\n RemoteConfig,\n} from '@amplitude/analytics-core';\n\nexport interface AutocaptureOptionsRemoteConfig extends AutocaptureOptions {\n elementInteractions?: boolean | ElementInteractionsOptionsRemoteConfig;\n}\nexport interface ElementInteractionsOptionsRemoteConfig extends ElementInteractionsOptions {\n /**\n * Related to pageUrlAllowlist but holds regex strings which will be initialized and appended to pageUrlAllowlist\n */\n pageUrlAllowlistRegex?: string[];\n}\n\n// Type alias for the remote config structure we expect (this is what comes from the filtered browserSDK config)\ntype RemoteConfigBrowserSDK = {\n autocapture?: AutocaptureOptionsRemoteConfig | boolean;\n};\n\n/**\n * Performs a deep transformation of a remote config object so that\n * it matches the expected schema of the local config.\n *\n * Specifically, it normalizes nested `enabled` flags into concise union types.\n *\n * ### Transformation Rules:\n * - If an object has `enabled: true`, it is replaced by the same object without the `enabled` field.\n * - If it has only `enabled: true`, it is replaced with `true`.\n * - If it has `enabled: false`, it is replaced with `false` regardless of other fields.\n *\n * ### Examples:\n * Input: { prop: { enabled: true, hello: 'world' }}\n * Output: { prop: { hello: 'world' } }\n *\n * Input: { prop: { enabled: true }}\n * Output: { prop: true }\n *\n * Input: { prop: { enabled: false, hello: 'world' }}\n * Output: { prop: false }\n *\n * Input: { prop: { hello: 'world' }}\n * Output: { prop: { hello: 'world' } } // No change\n *\n * @param config Remote config object to be transformed\n * @returns Transformed config object compatible with local schema\n */\nexport function translateRemoteConfigToLocal(config?: Record<string, any>) {\n // Disabling type checking rules because remote config comes from a remote source\n // and this function needs to handle any unexpected values\n /* eslint-disable @typescript-eslint/no-unsafe-member-access,\n @typescript-eslint/no-unsafe-assignment,\n @typescript-eslint/no-unsafe-argument\n */\n if (typeof config !== 'object' || config === null) {\n return;\n }\n\n // translations are not applied on array properties\n if (Array.isArray(config)) {\n return;\n }\n\n const propertyNames = Object.keys(config);\n for (const propertyName of propertyNames) {\n try {\n const value = config[propertyName];\n // transform objects with { enabled } property to boolean | object\n if (typeof value?.enabled === 'boolean') {\n if (value.enabled) {\n // if enabled is true, set the value to the rest of the object\n // or true if the object has no other properties\n delete value.enabled;\n if (Object.keys(value).length === 0) {\n (config as any)[propertyName] = true;\n }\n } else {\n // If enabled is false, set the value to false\n (config as any)[propertyName] = false;\n }\n }\n\n // recursively translate properties of the value\n translateRemoteConfigToLocal(value as Record<string, any>);\n } catch (e) {\n // a failure here means that an accessor threw an error\n // so don't translate it\n // TODO(diagnostics): add a diagnostic event for this\n }\n }\n}\n\n/**\n * Updates the browser config in place by applying remote configuration settings.\n * Primarily merges autocapture settings from the remote config into the browser config.\n *\n * @param remoteConfig - The remote configuration to apply, or null if none available\n * @param browserConfig - The browser config object to update (modified in place)\n */\nexport function updateBrowserConfigWithRemoteConfig(\n remoteConfig: RemoteConfig | null,\n browserConfig: BrowserConfig,\n): void {\n if (!remoteConfig) {\n return;\n }\n\n // translate remote config to local compatible format\n translateRemoteConfigToLocal(remoteConfig);\n\n try {\n browserConfig.loggerProvider.debug(\n 'Update browser config with remote configuration:',\n JSON.stringify(remoteConfig),\n );\n\n // type cast error will be thrown if remoteConfig is not a valid RemoteConfigBrowserSDK\n // and it will be caught by the try-catch block\n const typedRemoteConfig = remoteConfig as RemoteConfigBrowserSDK;\n\n // merge remoteConfig.autocapture and browserConfig.autocapture\n // if a field is in remoteConfig.autocapture, use that value\n // if a field is not in remoteConfig.autocapture, use the value from browserConfig.autocapture\n if (typedRemoteConfig && 'autocapture' in typedRemoteConfig) {\n if (typeof typedRemoteConfig.autocapture === 'boolean') {\n browserConfig.autocapture = typedRemoteConfig.autocapture;\n }\n\n if (typeof typedRemoteConfig.autocapture === 'object' && typedRemoteConfig.autocapture !== null) {\n const transformedAutocaptureRemoteConfig = { ...typedRemoteConfig.autocapture };\n\n if (browserConfig.autocapture === undefined) {\n browserConfig.autocapture = typedRemoteConfig.autocapture;\n }\n\n // Handle Element Interactions config initialization\n if (\n typeof typedRemoteConfig.autocapture.elementInteractions === 'object' &&\n typedRemoteConfig.autocapture.elementInteractions !== null &&\n typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex?.length\n ) {\n transformedAutocaptureRemoteConfig.elementInteractions = {\n ...typedRemoteConfig.autocapture.elementInteractions,\n };\n const transformedRcElementInteractions = transformedAutocaptureRemoteConfig.elementInteractions;\n\n const exactAllowList = transformedRcElementInteractions.pageUrlAllowlist ?? [];\n // Convert string patterns to RegExp objects, warn on invalid patterns and skip them\n const regexList = [];\n for (const pattern of typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex) {\n try {\n regexList.push(new RegExp(pattern));\n } catch (regexError) {\n browserConfig.loggerProvider.warn(`Invalid regex pattern: ${pattern}`, regexError);\n }\n }\n\n const combinedPageUrlAllowlist = exactAllowList.concat(regexList);\n\n transformedRcElementInteractions.pageUrlAllowlist = combinedPageUrlAllowlist;\n delete transformedRcElementInteractions.pageUrlAllowlistRegex;\n }\n\n if (typeof browserConfig.autocapture === 'boolean') {\n browserConfig.autocapture = {\n attribution: browserConfig.autocapture,\n fileDownloads: browserConfig.autocapture,\n formInteractions: browserConfig.autocapture,\n pageViews: browserConfig.autocapture,\n sessions: browserConfig.autocapture,\n elementInteractions: browserConfig.autocapture,\n webVitals: browserConfig.autocapture,\n frustrationInteractions: browserConfig.autocapture,\n ...transformedAutocaptureRemoteConfig,\n };\n }\n\n if (typeof browserConfig.autocapture === 'object') {\n browserConfig.autocapture = {\n ...browserConfig.autocapture,\n ...transformedAutocaptureRemoteConfig,\n };\n }\n }\n\n // Override default tracking options if autocapture is updated by remote config\n browserConfig.defaultTracking = browserConfig.autocapture;\n }\n\n browserConfig.loggerProvider.debug('Browser config after remote config update:', JSON.stringify(browserConfig));\n } catch (e) {\n browserConfig.loggerProvider.error('Failed to apply remote configuration because of error: ', e);\n }\n}\n"]}
@@ -31,7 +31,7 @@ export declare class BrowserConfig extends Config implements IBrowserConfig {
31
31
  useBatch: boolean;
32
32
  fetchRemoteConfig: boolean;
33
33
  networkTrackingOptions?: NetworkTrackingOptions | undefined;
34
- readonly version = "2.22.0";
34
+ readonly version = "2.22.1";
35
35
  protected _cookieStorage: Storage<UserSession>;
36
36
  protected _deviceId?: string;
37
37
  protected _lastEventId?: number;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.22.0";
1
+ export declare const VERSION = "2.22.1";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '2.22.0';
4
+ exports.VERSION = '2.22.1';
5
5
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '2.22.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '2.22.1';\n"]}
@@ -8,6 +8,34 @@ export interface ElementInteractionsOptionsRemoteConfig extends ElementInteracti
8
8
  */
9
9
  pageUrlAllowlistRegex?: string[];
10
10
  }
11
+ /**
12
+ * Performs a deep transformation of a remote config object so that
13
+ * it matches the expected schema of the local config.
14
+ *
15
+ * Specifically, it normalizes nested `enabled` flags into concise union types.
16
+ *
17
+ * ### Transformation Rules:
18
+ * - If an object has `enabled: true`, it is replaced by the same object without the `enabled` field.
19
+ * - If it has only `enabled: true`, it is replaced with `true`.
20
+ * - If it has `enabled: false`, it is replaced with `false` regardless of other fields.
21
+ *
22
+ * ### Examples:
23
+ * Input: { prop: { enabled: true, hello: 'world' }}
24
+ * Output: { prop: { hello: 'world' } }
25
+ *
26
+ * Input: { prop: { enabled: true }}
27
+ * Output: { prop: true }
28
+ *
29
+ * Input: { prop: { enabled: false, hello: 'world' }}
30
+ * Output: { prop: false }
31
+ *
32
+ * Input: { prop: { hello: 'world' }}
33
+ * Output: { prop: { hello: 'world' } } // No change
34
+ *
35
+ * @param config Remote config object to be transformed
36
+ * @returns Transformed config object compatible with local schema
37
+ */
38
+ export declare function translateRemoteConfigToLocal(config?: Record<string, any>): void;
11
39
  /**
12
40
  * Updates the browser config in place by applying remote configuration settings.
13
41
  * Primarily merges autocapture settings from the remote config into the browser config.
@@ -1 +1 @@
1
- {"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,0BAA0B,EAC/B,aAAa,EACb,YAAY,EACb,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,8BAA+B,SAAQ,kBAAkB;IACxE,mBAAmB,CAAC,EAAE,OAAO,GAAG,sCAAsC,CAAC;CACxE;AACD,MAAM,WAAW,sCAAuC,SAAQ,0BAA0B;IACxF;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAOD;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CACjD,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,aAAa,EAAE,aAAa,GAC3B,IAAI,CAwFN"}
1
+ {"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,0BAA0B,EAC/B,aAAa,EACb,YAAY,EACb,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,8BAA+B,SAAQ,kBAAkB;IACxE,mBAAmB,CAAC,EAAE,OAAO,GAAG,sCAAsC,CAAC;CACxE;AACD,MAAM,WAAW,sCAAuC,SAAQ,0BAA0B;IACxF;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QA2CxE;AAED;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CACjD,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,aAAa,EAAE,aAAa,GAC3B,IAAI,CA2FN"}
@@ -1,4 +1,85 @@
1
1
  import { __assign, __values } from "tslib";
2
+ /**
3
+ * Performs a deep transformation of a remote config object so that
4
+ * it matches the expected schema of the local config.
5
+ *
6
+ * Specifically, it normalizes nested `enabled` flags into concise union types.
7
+ *
8
+ * ### Transformation Rules:
9
+ * - If an object has `enabled: true`, it is replaced by the same object without the `enabled` field.
10
+ * - If it has only `enabled: true`, it is replaced with `true`.
11
+ * - If it has `enabled: false`, it is replaced with `false` regardless of other fields.
12
+ *
13
+ * ### Examples:
14
+ * Input: { prop: { enabled: true, hello: 'world' }}
15
+ * Output: { prop: { hello: 'world' } }
16
+ *
17
+ * Input: { prop: { enabled: true }}
18
+ * Output: { prop: true }
19
+ *
20
+ * Input: { prop: { enabled: false, hello: 'world' }}
21
+ * Output: { prop: false }
22
+ *
23
+ * Input: { prop: { hello: 'world' }}
24
+ * Output: { prop: { hello: 'world' } } // No change
25
+ *
26
+ * @param config Remote config object to be transformed
27
+ * @returns Transformed config object compatible with local schema
28
+ */
29
+ export function translateRemoteConfigToLocal(config) {
30
+ var e_1, _a;
31
+ // Disabling type checking rules because remote config comes from a remote source
32
+ // and this function needs to handle any unexpected values
33
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access,
34
+ @typescript-eslint/no-unsafe-assignment,
35
+ @typescript-eslint/no-unsafe-argument
36
+ */
37
+ if (typeof config !== 'object' || config === null) {
38
+ return;
39
+ }
40
+ // translations are not applied on array properties
41
+ if (Array.isArray(config)) {
42
+ return;
43
+ }
44
+ var propertyNames = Object.keys(config);
45
+ try {
46
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
47
+ var propertyName = propertyNames_1_1.value;
48
+ try {
49
+ var value = config[propertyName];
50
+ // transform objects with { enabled } property to boolean | object
51
+ if (typeof (value === null || value === void 0 ? void 0 : value.enabled) === 'boolean') {
52
+ if (value.enabled) {
53
+ // if enabled is true, set the value to the rest of the object
54
+ // or true if the object has no other properties
55
+ delete value.enabled;
56
+ if (Object.keys(value).length === 0) {
57
+ config[propertyName] = true;
58
+ }
59
+ }
60
+ else {
61
+ // If enabled is false, set the value to false
62
+ config[propertyName] = false;
63
+ }
64
+ }
65
+ // recursively translate properties of the value
66
+ translateRemoteConfigToLocal(value);
67
+ }
68
+ catch (e) {
69
+ // a failure here means that an accessor threw an error
70
+ // so don't translate it
71
+ // TODO(diagnostics): add a diagnostic event for this
72
+ }
73
+ }
74
+ }
75
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
76
+ finally {
77
+ try {
78
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
79
+ }
80
+ finally { if (e_1) throw e_1.error; }
81
+ }
82
+ }
2
83
  /**
3
84
  * Updates the browser config in place by applying remote configuration settings.
4
85
  * Primarily merges autocapture settings from the remote config into the browser config.
@@ -7,11 +88,13 @@ import { __assign, __values } from "tslib";
7
88
  * @param browserConfig - The browser config object to update (modified in place)
8
89
  */
9
90
  export function updateBrowserConfigWithRemoteConfig(remoteConfig, browserConfig) {
10
- var e_1, _a;
91
+ var e_2, _a;
11
92
  var _b, _c;
12
93
  if (!remoteConfig) {
13
94
  return;
14
95
  }
96
+ // translate remote config to local compatible format
97
+ translateRemoteConfigToLocal(remoteConfig);
15
98
  try {
16
99
  browserConfig.loggerProvider.debug('Update browser config with remote configuration:', JSON.stringify(remoteConfig));
17
100
  // type cast error will be thrown if remoteConfig is not a valid RemoteConfigBrowserSDK
@@ -49,12 +132,12 @@ export function updateBrowserConfigWithRemoteConfig(remoteConfig, browserConfig)
49
132
  }
50
133
  }
51
134
  }
52
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
135
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
53
136
  finally {
54
137
  try {
55
138
  if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
56
139
  }
57
- finally { if (e_1) throw e_1.error; }
140
+ finally { if (e_2) throw e_2.error; }
58
141
  }
59
142
  var combinedPageUrlAllowlist = exactAllowList.concat(regexList);
60
143
  transformedRcElementInteractions.pageUrlAllowlist = combinedPageUrlAllowlist;
@@ -1 +1 @@
1
- {"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";AAsBA;;;;;;GAMG;AACH,MAAM,UAAU,mCAAmC,CACjD,YAAiC,EACjC,aAA4B;;;IAE5B,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IAED,IAAI;QACF,aAAa,CAAC,cAAc,CAAC,KAAK,CAChC,kDAAkD,EAClD,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAC7B,CAAC;QAEF,uFAAuF;QACvF,+CAA+C;QAC/C,IAAM,iBAAiB,GAAG,YAAsC,CAAC;QAEjE,+DAA+D;QAC/D,4DAA4D;QAC5D,8FAA8F;QAC9F,IAAI,iBAAiB,IAAI,aAAa,IAAI,iBAAiB,EAAE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pF;yBACF;;;;;;;;;oBAED,IAAM,wBAAwB,GAAG,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBAElE,gCAAgC,CAAC,gBAAgB,GAAG,wBAAwB,CAAC;oBAC7E,OAAO,gCAAgC,CAAC,qBAAqB,CAAC;iBAC/D;gBAED,IAAI,OAAO,aAAa,CAAC,WAAW,KAAK,SAAS,EAAE;oBAClD,aAAa,CAAC,WAAW,cACvB,WAAW,EAAE,aAAa,CAAC,WAAW,EACtC,aAAa,EAAE,aAAa,CAAC,WAAW,EACxC,gBAAgB,EAAE,aAAa,CAAC,WAAW,EAC3C,SAAS,EAAE,aAAa,CAAC,WAAW,EACpC,QAAQ,EAAE,aAAa,CAAC,WAAW,EACnC,mBAAmB,EAAE,aAAa,CAAC,WAAW,EAC9C,SAAS,EAAE,aAAa,CAAC,WAAW,EACpC,uBAAuB,EAAE,aAAa,CAAC,WAAW,IAC/C,kCAAkC,CACtC,CAAC;iBACH;gBAED,IAAI,OAAO,aAAa,CAAC,WAAW,KAAK,QAAQ,EAAE;oBACjD,aAAa,CAAC,WAAW,yBACpB,aAAa,CAAC,WAAW,GACzB,kCAAkC,CACtC,CAAC;iBACH;aACF;YAED,+EAA+E;YAC/E,aAAa,CAAC,eAAe,GAAG,aAAa,CAAC,WAAW,CAAC;SAC3D;QAED,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,4CAA4C,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;KACjH;IAAC,OAAO,CAAC,EAAE;QACV,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,yDAAyD,EAAE,CAAC,CAAC,CAAC;KAClG;AACH,CAAC","sourcesContent":["import {\n AutocaptureOptions,\n type ElementInteractionsOptions,\n BrowserConfig,\n RemoteConfig,\n} from '@amplitude/analytics-core';\n\nexport interface AutocaptureOptionsRemoteConfig extends AutocaptureOptions {\n elementInteractions?: boolean | ElementInteractionsOptionsRemoteConfig;\n}\nexport interface ElementInteractionsOptionsRemoteConfig extends ElementInteractionsOptions {\n /**\n * Related to pageUrlAllowlist but holds regex strings which will be initialized and appended to pageUrlAllowlist\n */\n pageUrlAllowlistRegex?: string[];\n}\n\n// Type alias for the remote config structure we expect (this is what comes from the filtered browserSDK config)\ntype RemoteConfigBrowserSDK = {\n autocapture?: AutocaptureOptionsRemoteConfig | boolean;\n};\n\n/**\n * Updates the browser config in place by applying remote configuration settings.\n * Primarily merges autocapture settings from the remote config into the browser config.\n *\n * @param remoteConfig - The remote configuration to apply, or null if none available\n * @param browserConfig - The browser config object to update (modified in place)\n */\nexport function updateBrowserConfigWithRemoteConfig(\n remoteConfig: RemoteConfig | null,\n browserConfig: BrowserConfig,\n): void {\n if (!remoteConfig) {\n return;\n }\n\n try {\n browserConfig.loggerProvider.debug(\n 'Update browser config with remote configuration:',\n JSON.stringify(remoteConfig),\n );\n\n // type cast error will be thrown if remoteConfig is not a valid RemoteConfigBrowserSDK\n // and it will be caught by the try-catch block\n const typedRemoteConfig = remoteConfig as RemoteConfigBrowserSDK;\n\n // merge remoteConfig.autocapture and browserConfig.autocapture\n // if a field is in remoteConfig.autocapture, use that value\n // if a field is not in remoteConfig.autocapture, use the value from browserConfig.autocapture\n if (typedRemoteConfig && 'autocapture' in typedRemoteConfig) {\n if (typeof typedRemoteConfig.autocapture === 'boolean') {\n browserConfig.autocapture = typedRemoteConfig.autocapture;\n }\n\n if (typeof typedRemoteConfig.autocapture === 'object' && typedRemoteConfig.autocapture !== null) {\n const transformedAutocaptureRemoteConfig = { ...typedRemoteConfig.autocapture };\n\n if (browserConfig.autocapture === undefined) {\n browserConfig.autocapture = typedRemoteConfig.autocapture;\n }\n\n // Handle Element Interactions config initialization\n if (\n typeof typedRemoteConfig.autocapture.elementInteractions === 'object' &&\n typedRemoteConfig.autocapture.elementInteractions !== null &&\n typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex?.length\n ) {\n transformedAutocaptureRemoteConfig.elementInteractions = {\n ...typedRemoteConfig.autocapture.elementInteractions,\n };\n const transformedRcElementInteractions = transformedAutocaptureRemoteConfig.elementInteractions;\n\n const exactAllowList = transformedRcElementInteractions.pageUrlAllowlist ?? [];\n // Convert string patterns to RegExp objects, warn on invalid patterns and skip them\n const regexList = [];\n for (const pattern of typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex) {\n try {\n regexList.push(new RegExp(pattern));\n } catch (regexError) {\n browserConfig.loggerProvider.warn(`Invalid regex pattern: ${pattern}`, regexError);\n }\n }\n\n const combinedPageUrlAllowlist = exactAllowList.concat(regexList);\n\n transformedRcElementInteractions.pageUrlAllowlist = combinedPageUrlAllowlist;\n delete transformedRcElementInteractions.pageUrlAllowlistRegex;\n }\n\n if (typeof browserConfig.autocapture === 'boolean') {\n browserConfig.autocapture = {\n attribution: browserConfig.autocapture,\n fileDownloads: browserConfig.autocapture,\n formInteractions: browserConfig.autocapture,\n pageViews: browserConfig.autocapture,\n sessions: browserConfig.autocapture,\n elementInteractions: browserConfig.autocapture,\n webVitals: browserConfig.autocapture,\n frustrationInteractions: browserConfig.autocapture,\n ...transformedAutocaptureRemoteConfig,\n };\n }\n\n if (typeof browserConfig.autocapture === 'object') {\n browserConfig.autocapture = {\n ...browserConfig.autocapture,\n ...transformedAutocaptureRemoteConfig,\n };\n }\n }\n\n // Override default tracking options if autocapture is updated by remote config\n browserConfig.defaultTracking = browserConfig.autocapture;\n }\n\n browserConfig.loggerProvider.debug('Browser config after remote config update:', JSON.stringify(browserConfig));\n } catch (e) {\n browserConfig.loggerProvider.error('Failed to apply remote configuration because of error: ', e);\n }\n}\n"]}
1
+ {"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";AAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,4BAA4B,CAAC,MAA4B;;IACvE,iFAAiF;IACjF,0DAA0D;IAC1D;;;KAGC;IACD,IAAI,OAAO,MAAM,KAAK,Q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","sourcesContent":["import {\n AutocaptureOptions,\n type ElementInteractionsOptions,\n BrowserConfig,\n RemoteConfig,\n} from '@amplitude/analytics-core';\n\nexport interface AutocaptureOptionsRemoteConfig extends AutocaptureOptions {\n elementInteractions?: boolean | ElementInteractionsOptionsRemoteConfig;\n}\nexport interface ElementInteractionsOptionsRemoteConfig extends ElementInteractionsOptions {\n /**\n * Related to pageUrlAllowlist but holds regex strings which will be initialized and appended to pageUrlAllowlist\n */\n pageUrlAllowlistRegex?: string[];\n}\n\n// Type alias for the remote config structure we expect (this is what comes from the filtered browserSDK config)\ntype RemoteConfigBrowserSDK = {\n autocapture?: AutocaptureOptionsRemoteConfig | boolean;\n};\n\n/**\n * Performs a deep transformation of a remote config object so that\n * it matches the expected schema of the local config.\n *\n * Specifically, it normalizes nested `enabled` flags into concise union types.\n *\n * ### Transformation Rules:\n * - If an object has `enabled: true`, it is replaced by the same object without the `enabled` field.\n * - If it has only `enabled: true`, it is replaced with `true`.\n * - If it has `enabled: false`, it is replaced with `false` regardless of other fields.\n *\n * ### Examples:\n * Input: { prop: { enabled: true, hello: 'world' }}\n * Output: { prop: { hello: 'world' } }\n *\n * Input: { prop: { enabled: true }}\n * Output: { prop: true }\n *\n * Input: { prop: { enabled: false, hello: 'world' }}\n * Output: { prop: false }\n *\n * Input: { prop: { hello: 'world' }}\n * Output: { prop: { hello: 'world' } } // No change\n *\n * @param config Remote config object to be transformed\n * @returns Transformed config object compatible with local schema\n */\nexport function translateRemoteConfigToLocal(config?: Record<string, any>) {\n // Disabling type checking rules because remote config comes from a remote source\n // and this function needs to handle any unexpected values\n /* eslint-disable @typescript-eslint/no-unsafe-member-access,\n @typescript-eslint/no-unsafe-assignment,\n @typescript-eslint/no-unsafe-argument\n */\n if (typeof config !== 'object' || config === null) {\n return;\n }\n\n // translations are not applied on array properties\n if (Array.isArray(config)) {\n return;\n }\n\n const propertyNames = Object.keys(config);\n for (const propertyName of propertyNames) {\n try {\n const value = config[propertyName];\n // transform objects with { enabled } property to boolean | object\n if (typeof value?.enabled === 'boolean') {\n if (value.enabled) {\n // if enabled is true, set the value to the rest of the object\n // or true if the object has no other properties\n delete value.enabled;\n if (Object.keys(value).length === 0) {\n (config as any)[propertyName] = true;\n }\n } else {\n // If enabled is false, set the value to false\n (config as any)[propertyName] = false;\n }\n }\n\n // recursively translate properties of the value\n translateRemoteConfigToLocal(value as Record<string, any>);\n } catch (e) {\n // a failure here means that an accessor threw an error\n // so don't translate it\n // TODO(diagnostics): add a diagnostic event for this\n }\n }\n}\n\n/**\n * Updates the browser config in place by applying remote configuration settings.\n * Primarily merges autocapture settings from the remote config into the browser config.\n *\n * @param remoteConfig - The remote configuration to apply, or null if none available\n * @param browserConfig - The browser config object to update (modified in place)\n */\nexport function updateBrowserConfigWithRemoteConfig(\n remoteConfig: RemoteConfig | null,\n browserConfig: BrowserConfig,\n): void {\n if (!remoteConfig) {\n return;\n }\n\n // translate remote config to local compatible format\n translateRemoteConfigToLocal(remoteConfig);\n\n try {\n browserConfig.loggerProvider.debug(\n 'Update browser config with remote configuration:',\n JSON.stringify(remoteConfig),\n );\n\n // type cast error will be thrown if remoteConfig is not a valid RemoteConfigBrowserSDK\n // and it will be caught by the try-catch block\n const typedRemoteConfig = remoteConfig as RemoteConfigBrowserSDK;\n\n // merge remoteConfig.autocapture and browserConfig.autocapture\n // if a field is in remoteConfig.autocapture, use that value\n // if a field is not in remoteConfig.autocapture, use the value from browserConfig.autocapture\n if (typedRemoteConfig && 'autocapture' in typedRemoteConfig) {\n if (typeof typedRemoteConfig.autocapture === 'boolean') {\n browserConfig.autocapture = typedRemoteConfig.autocapture;\n }\n\n if (typeof typedRemoteConfig.autocapture === 'object' && typedRemoteConfig.autocapture !== null) {\n const transformedAutocaptureRemoteConfig = { ...typedRemoteConfig.autocapture };\n\n if (browserConfig.autocapture === undefined) {\n browserConfig.autocapture = typedRemoteConfig.autocapture;\n }\n\n // Handle Element Interactions config initialization\n if (\n typeof typedRemoteConfig.autocapture.elementInteractions === 'object' &&\n typedRemoteConfig.autocapture.elementInteractions !== null &&\n typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex?.length\n ) {\n transformedAutocaptureRemoteConfig.elementInteractions = {\n ...typedRemoteConfig.autocapture.elementInteractions,\n };\n const transformedRcElementInteractions = transformedAutocaptureRemoteConfig.elementInteractions;\n\n const exactAllowList = transformedRcElementInteractions.pageUrlAllowlist ?? [];\n // Convert string patterns to RegExp objects, warn on invalid patterns and skip them\n const regexList = [];\n for (const pattern of typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex) {\n try {\n regexList.push(new RegExp(pattern));\n } catch (regexError) {\n browserConfig.loggerProvider.warn(`Invalid regex pattern: ${pattern}`, regexError);\n }\n }\n\n const combinedPageUrlAllowlist = exactAllowList.concat(regexList);\n\n transformedRcElementInteractions.pageUrlAllowlist = combinedPageUrlAllowlist;\n delete transformedRcElementInteractions.pageUrlAllowlistRegex;\n }\n\n if (typeof browserConfig.autocapture === 'boolean') {\n browserConfig.autocapture = {\n attribution: browserConfig.autocapture,\n fileDownloads: browserConfig.autocapture,\n formInteractions: browserConfig.autocapture,\n pageViews: browserConfig.autocapture,\n sessions: browserConfig.autocapture,\n elementInteractions: browserConfig.autocapture,\n webVitals: browserConfig.autocapture,\n frustrationInteractions: browserConfig.autocapture,\n ...transformedAutocaptureRemoteConfig,\n };\n }\n\n if (typeof browserConfig.autocapture === 'object') {\n browserConfig.autocapture = {\n ...browserConfig.autocapture,\n ...transformedAutocaptureRemoteConfig,\n };\n }\n }\n\n // Override default tracking options if autocapture is updated by remote config\n browserConfig.defaultTracking = browserConfig.autocapture;\n }\n\n browserConfig.loggerProvider.debug('Browser config after remote config update:', JSON.stringify(browserConfig));\n } catch (e) {\n browserConfig.loggerProvider.error('Failed to apply remote configuration because of error: ', e);\n }\n}\n"]}
@@ -31,7 +31,7 @@ export declare class BrowserConfig extends Config implements IBrowserConfig {
31
31
  useBatch: boolean;
32
32
  fetchRemoteConfig: boolean;
33
33
  networkTrackingOptions?: NetworkTrackingOptions | undefined;
34
- readonly version = "2.22.0";
34
+ readonly version = "2.22.1";
35
35
  protected _cookieStorage: Storage<UserSession>;
36
36
  protected _deviceId?: string;
37
37
  protected _lastEventId?: number;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.22.0";
1
+ export declare const VERSION = "2.22.1";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,2 +1,2 @@
1
- export var VERSION = '2.22.0';
1
+ export var VERSION = '2.22.1';
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '2.22.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '2.22.1';\n"]}
@@ -1 +1 @@
1
- !function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},i=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},o=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(i(e,t,Array.prototype.slice.call(arguments)))}}},s=function(e){for(var t=0;t<v.length;t++)o(e,v[t],!1);for(var r=0;r<y.length;r++)o(e,y[r],!0)};r.invoked=!0;var a=t.getElementsByTagName("script")[0],u=t.createElement("script");u.src="https://cdn.amplitude.com/libs/plugin-autocapture-browser-0.9.0-min.js.gz",u.async=!1,a.parentNode.insertBefore(u,a);var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-IUW8RjRN702gJvUVDSmYo1mlK5T6rvXQB7Naxm+l1aeYOyifGXytp09FVaoZPXhr",c.crossOrigin="anonymous",c.async=!1,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.22.0-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK"),e.amplitude.init("YOUR_API_KEY","YOUR_USER_ID",{instanceName:"amplitude-bookmarklet",serverZone:"YOUR_SERVER_ZONE",ingestionMetadata:{sourceName:"browser-typescript-bookmarklet",sourceVersion:"1.0.0"},optOut:!1}),amplitudeAutocapturePlugin&&amplitudeAutocapturePlugin.autocapturePlugin&&"function"==typeof amplitudeAutocapturePlugin.autocapturePlugin&&e.amplitude.add(amplitudeAutocapturePlugin.autocapturePlugin()),alert("Amplitude is now tracking events!")},a.parentNode.insertBefore(c,a);for(var p=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<l.length;d++)n(p,l[d]);r.Identify=p;for(var m=function(){return this._q=[],this},g=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setReceipt","setReceiptSig","setCurrency","setEventProperties"],f=0;f<g.length;f++)n(m,g[f]);r.Revenue=m;var v=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],y=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];s(r),r.createInstance=function(e){return r._iq[e]={_q:[]},s(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
1
+ !function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},i=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},o=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(i(e,t,Array.prototype.slice.call(arguments)))}}},s=function(e){for(var t=0;t<v.length;t++)o(e,v[t],!1);for(var r=0;r<y.length;r++)o(e,y[r],!0)};r.invoked=!0;var u=t.getElementsByTagName("script")[0],a=t.createElement("script");a.src="https://cdn.amplitude.com/libs/plugin-autocapture-browser-0.9.0-min.js.gz",a.async=!1,u.parentNode.insertBefore(a,u);var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-VDysG3y8O289yWNGGS5ESEU5j/t67M0RoQzTAd8C0RU6oep9uB64PVjIqHkX7O4N",c.crossOrigin="anonymous",c.async=!1,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.22.1-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK"),e.amplitude.init("YOUR_API_KEY","YOUR_USER_ID",{instanceName:"amplitude-bookmarklet",serverZone:"YOUR_SERVER_ZONE",ingestionMetadata:{sourceName:"browser-typescript-bookmarklet",sourceVersion:"1.0.0"},optOut:!1}),amplitudeAutocapturePlugin&&amplitudeAutocapturePlugin.autocapturePlugin&&"function"==typeof amplitudeAutocapturePlugin.autocapturePlugin&&e.amplitude.add(amplitudeAutocapturePlugin.autocapturePlugin()),alert("Amplitude is now tracking events!")},u.parentNode.insertBefore(c,u);for(var p=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<l.length;d++)n(p,l[d]);r.Identify=p;for(var m=function(){return this._q=[],this},g=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setReceipt","setReceiptSig","setCurrency","setEventProperties"],f=0;f<g.length;f++)n(m,g[f]);r.Revenue=m;var v=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],y=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];s(r),r.createInstance=function(e){return r._iq[e]={_q:[]},s(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
@@ -1 +1 @@
1
- javascript:!function()%7B%22use%20strict%22%3B!function(e%2Ct)%7Bvar%20r%3De.amplitude%7C%7C%7B_q%3A%5B%5D%2C_iq%3A%7B%7D%7D%3Bif(r.invoked)e.console%26%26console.error%26%26console.error(%22Amplitude%20snippet%20has%20been%20loaded.%22)%3Belse%7Bvar%20n%3Dfunction(e%2Ct)%7Be.prototype%5Bt%5D%3Dfunction()%7Breturn%20this._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(arguments%2C0)%7D)%2Cthis%7D%7D%2Ci%3Dfunction(e%2Ct%2Cr)%7Breturn%20function(n)%7Be._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(r%2C0)%2Cresolve%3An%7D)%7D%7D%2Co%3Dfunction(e%2Ct%2Cr)%7Be%5Bt%5D%3Dfunction()%7Bif(r)return%7Bpromise%3Anew%20Promise(i(e%2Ct%2CArray.prototype.slice.call(arguments)))%7D%7D%7D%2Cs%3Dfunction(e)%7Bfor(var%20t%3D0%3Bt%3Cv.length%3Bt%2B%2B)o(e%2Cv%5Bt%5D%2C!1)%3Bfor(var%20r%3D0%3Br%3Cy.length%3Br%2B%2B)o(e%2Cy%5Br%5D%2C!0)%7D%3Br.invoked%3D!0%3Bvar%20a%3Dt.getElementsByTagName(%22script%22)%5B0%5D%2Cu%3Dt.createElement(%22script%22)%3Bu.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fplugin-autocapture-browser-0.9.0-min.js.gz%22%2Cu.async%3D!1%2Ca.parentNode.insertBefore(u%2Ca)%3Bvar%20c%3Dt.createElement(%22script%22)%3Bc.type%3D%22text%2Fjavascript%22%2Cc.integrity%3D%22sha384-IUW8RjRN702gJvUVDSmYo1mlK5T6rvXQB7Naxm%2Bl1aeYOyifGXytp09FVaoZPXhr%22%2Cc.crossOrigin%3D%22anonymous%22%2Cc.async%3D!1%2Cc.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fanalytics-browser-2.22.0-min.js.gz%22%2Cc.onload%3Dfunction()%7Be.amplitude.runQueuedFunctions%7C%7Cconsole.log(%22%5BAmplitude%5D%20Error%3A%20could%20not%20load%20SDK%22)%2Ce.amplitude.init(%22YOUR_API_KEY%22%2C%22YOUR_USER_ID%22%2C%7BinstanceName%3A%22amplitude-bookmarklet%22%2CserverZone%3A%22YOUR_SERVER_ZONE%22%2CingestionMetadata%3A%7BsourceName%3A%22browser-typescript-bookmarklet%22%2CsourceVersion%3A%221.0.0%22%7D%2CoptOut%3A!1%7D)%2CamplitudeAutocapturePlugin%26%26amplitudeAutocapturePlugin.autocapturePlugin%26%26%22function%22%3D%3Dtypeof%20amplitudeAutocapturePlugin.autocapturePlugin%26%26e.amplitude.add(amplitudeAutocapturePlugin.autocapturePlugin())%2Calert(%22Amplitude%20is%20now%20tracking%20events!%22)%7D%2Ca.parentNode.insertBefore(c%2Ca)%3Bfor(var%20p%3Dfunction()%7Breturn%20this._q%3D%5B%5D%2Cthis%7D%2Cl%3D%5B%22add%22%2C%22append%22%2C%22clearAll%22%2C%22prepend%22%2C%22set%22%2C%22setOnce%22%2C%22unset%22%2C%22preInsert%22%2C%22postInsert%22%2C%22remove%22%2C%22getUserProperties%22%5D%2Cd%3D0%3Bd%3Cl.length%3Bd%2B%2B)n(p%2Cl%5Bd%5D)%3Br.Identify%3Dp%3Bfor(var%20m%3Dfunction()%7Breturn%20this._q%3D%5B%5D%2Cthis%7D%2Cg%3D%5B%22getEventProperties%22%2C%22setProductId%22%2C%22setQuantity%22%2C%22setPrice%22%2C%22setRevenue%22%2C%22setRevenueType%22%2C%22setReceipt%22%2C%22setReceiptSig%22%2C%22setCurrency%22%2C%22setEventProperties%22%5D%2Cf%3D0%3Bf%3Cg.length%3Bf%2B%2B)n(m%2Cg%5Bf%5D)%3Br.Revenue%3Dm%3Bvar%20v%3D%5B%22getDeviceId%22%2C%22setDeviceId%22%2C%22getSessionId%22%2C%22setSessionId%22%2C%22getUserId%22%2C%22setUserId%22%2C%22setOptOut%22%2C%22setTransport%22%2C%22reset%22%2C%22extendSession%22%5D%2Cy%3D%5B%22init%22%2C%22add%22%2C%22remove%22%2C%22track%22%2C%22logEvent%22%2C%22identify%22%2C%22groupIdentify%22%2C%22setGroup%22%2C%22revenue%22%2C%22flush%22%5D%3Bs(r)%2Cr.createInstance%3Dfunction(e)%7Breturn%20r._iq%5Be%5D%3D%7B_q%3A%5B%5D%7D%2Cs(r._iq%5Be%5D)%2Cr._iq%5Be%5D%7D%2Ce.amplitude%3Dr%7D%7D(window%2Cdocument)%7D()%3B%0A
1
+ javascript:!function()%7B%22use%20strict%22%3B!function(e%2Ct)%7Bvar%20r%3De.amplitude%7C%7C%7B_q%3A%5B%5D%2C_iq%3A%7B%7D%7D%3Bif(r.invoked)e.console%26%26console.error%26%26console.error(%22Amplitude%20snippet%20has%20been%20loaded.%22)%3Belse%7Bvar%20n%3Dfunction(e%2Ct)%7Be.prototype%5Bt%5D%3Dfunction()%7Breturn%20this._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(arguments%2C0)%7D)%2Cthis%7D%7D%2Ci%3Dfunction(e%2Ct%2Cr)%7Breturn%20function(n)%7Be._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(r%2C0)%2Cresolve%3An%7D)%7D%7D%2Co%3Dfunction(e%2Ct%2Cr)%7Be%5Bt%5D%3Dfunction()%7Bif(r)return%7Bpromise%3Anew%20Promise(i(e%2Ct%2CArray.prototype.slice.call(arguments)))%7D%7D%7D%2Cs%3Dfunction(e)%7Bfor(var%20t%3D0%3Bt%3Cv.length%3Bt%2B%2B)o(e%2Cv%5Bt%5D%2C!1)%3Bfor(var%20r%3D0%3Br%3Cy.length%3Br%2B%2B)o(e%2Cy%5Br%5D%2C!0)%7D%3Br.invoked%3D!0%3Bvar%20u%3Dt.getElementsByTagName(%22script%22)%5B0%5D%2Ca%3Dt.createElement(%22script%22)%3Ba.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fplugin-autocapture-browser-0.9.0-min.js.gz%22%2Ca.async%3D!1%2Cu.parentNode.insertBefore(a%2Cu)%3Bvar%20c%3Dt.createElement(%22script%22)%3Bc.type%3D%22text%2Fjavascript%22%2Cc.integrity%3D%22sha384-VDysG3y8O289yWNGGS5ESEU5j%2Ft67M0RoQzTAd8C0RU6oep9uB64PVjIqHkX7O4N%22%2Cc.crossOrigin%3D%22anonymous%22%2Cc.async%3D!1%2Cc.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fanalytics-browser-2.22.1-min.js.gz%22%2Cc.onload%3Dfunction()%7Be.amplitude.runQueuedFunctions%7C%7Cconsole.log(%22%5BAmplitude%5D%20Error%3A%20could%20not%20load%20SDK%22)%2Ce.amplitude.init(%22YOUR_API_KEY%22%2C%22YOUR_USER_ID%22%2C%7BinstanceName%3A%22amplitude-bookmarklet%22%2CserverZone%3A%22YOUR_SERVER_ZONE%22%2CingestionMetadata%3A%7BsourceName%3A%22browser-typescript-bookmarklet%22%2CsourceVersion%3A%221.0.0%22%7D%2CoptOut%3A!1%7D)%2CamplitudeAutocapturePlugin%26%26amplitudeAutocapturePlugin.autocapturePlugin%26%26%22function%22%3D%3Dtypeof%20amplitudeAutocapturePlugin.autocapturePlugin%26%26e.amplitude.add(amplitudeAutocapturePlugin.autocapturePlugin())%2Calert(%22Amplitude%20is%20now%20tracking%20events!%22)%7D%2Cu.parentNode.insertBefore(c%2Cu)%3Bfor(var%20p%3Dfunction()%7Breturn%20this._q%3D%5B%5D%2Cthis%7D%2Cl%3D%5B%22add%22%2C%22append%22%2C%22clearAll%22%2C%22prepend%22%2C%22set%22%2C%22setOnce%22%2C%22unset%22%2C%22preInsert%22%2C%22postInsert%22%2C%22remove%22%2C%22getUserProperties%22%5D%2Cd%3D0%3Bd%3Cl.length%3Bd%2B%2B)n(p%2Cl%5Bd%5D)%3Br.Identify%3Dp%3Bfor(var%20m%3Dfunction()%7Breturn%20this._q%3D%5B%5D%2Cthis%7D%2Cg%3D%5B%22getEventProperties%22%2C%22setProductId%22%2C%22setQuantity%22%2C%22setPrice%22%2C%22setRevenue%22%2C%22setRevenueType%22%2C%22setReceipt%22%2C%22setReceiptSig%22%2C%22setCurrency%22%2C%22setEventProperties%22%5D%2Cf%3D0%3Bf%3Cg.length%3Bf%2B%2B)n(m%2Cg%5Bf%5D)%3Br.Revenue%3Dm%3Bvar%20v%3D%5B%22getDeviceId%22%2C%22setDeviceId%22%2C%22getSessionId%22%2C%22setSessionId%22%2C%22getUserId%22%2C%22setUserId%22%2C%22setOptOut%22%2C%22setTransport%22%2C%22reset%22%2C%22extendSession%22%5D%2Cy%3D%5B%22init%22%2C%22add%22%2C%22remove%22%2C%22track%22%2C%22logEvent%22%2C%22identify%22%2C%22groupIdentify%22%2C%22setGroup%22%2C%22revenue%22%2C%22flush%22%5D%3Bs(r)%2Cr.createInstance%3Dfunction(e)%7Breturn%20r._iq%5Be%5D%3D%7B_q%3A%5B%5D%7D%2Cs(r._iq%5Be%5D)%2Cr._iq%5Be%5D%7D%2Ce.amplitude%3Dr%7D%7D(window%2Cdocument)%7D()%3B%0A