@amplitude/analytics-browser 2.24.0 → 2.24.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/cjs/config/joined-config.d.ts.map +1 -1
- package/lib/cjs/config/joined-config.js +52 -7
- package/lib/cjs/config/joined-config.js.map +1 -1
- package/lib/cjs/config.d.ts +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/config/joined-config.d.ts.map +1 -1
- package/lib/esm/config/joined-config.js +53 -8
- package/lib/esm/config/joined-config.js.map +1 -1
- package/lib/esm/config.d.ts +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/amplitude-bookmarklet-snippet-min.js +1 -1
- package/lib/scripts/amplitude-bookmarklet.html +1 -1
- package/lib/scripts/amplitude-gtm-min.js +1 -1
- package/lib/scripts/amplitude-gtm-min.js.gz +0 -0
- package/lib/scripts/amplitude-gtm-min.js.map +1 -1
- package/lib/scripts/amplitude-gtm-snippet-min.js +1 -1
- package/lib/scripts/amplitude-min.js +1 -1
- package/lib/scripts/amplitude-min.js.gz +0 -0
- package/lib/scripts/amplitude-min.js.map +1 -1
- package/lib/scripts/amplitude-min.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/amplitude-snippet-instructions.html +1 -1
- package/lib/scripts/amplitude-snippet-min.js +1 -1
- package/lib/scripts/config/joined-config.d.ts.map +1 -1
- package/lib/scripts/config.d.ts +1 -1
- package/lib/scripts/version.d.ts +1 -1
- 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})}},
|
|
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})}},i=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))}},o=function(e){for(var t=0;t<v.length;t++)i(e,v[t],!1);for(var r=0;r<g.length;r++)i(e,g[r],!0)};r.invoked=!0;var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-yZgkX3BTOI6qmBCIQ4XyWMnm/b1L0Qh2jnFdufiihbdCtPftQRPshyvrPxRQQRj3",c.crossOrigin="anonymous",c.async=!0,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.24.2-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},f=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setReceipt","setReceiptSig","setCurrency","setEventProperties"],y=0;y<f.length;y++)n(d,f[y]);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"];o(r),r.createInstance=function(e){return r._iq[e]={_q:[]},o(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
|
|
57
57
|
|
|
58
58
|
amplitude.init("<YOUR_API_KEY>");
|
|
59
59
|
</script>
|
|
@@ -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,EACZ,sBAAsB,EACtB,kBAAkB,
|
|
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,EACZ,sBAAsB,EACtB,kBAAkB,EAEnB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,8BAA+B,SAAQ,kBAAkB;IACxE,mBAAmB,CAAC,EAAE,OAAO,GAAG,sCAAsC,CAAC;IACvE,eAAe,CAAC,EAAE,OAAO,GAAG,kCAAkC,CAAC;CAChE;AACD,MAAM,WAAW,sCAAuC,SAAQ,0BAA0B;IACxF;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,8BAA+B,SAAQ,kBAAkB;IACxE;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,kCAAmC,SAAQ,sBAAsB;IAChF;;OAEG;IACH,YAAY,CAAC,EAAE,8BAA8B,EAAE,CAAC;CACjD;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAkExE;AAgBD;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CACjD,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,aAAa,EAAE,aAAa,GAC3B,IAAI,CAqGN"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateBrowserConfigWithRemoteConfig = exports.translateRemoteConfigToLocal = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
5
6
|
/**
|
|
6
7
|
* Performs a deep transformation of a remote config object so that
|
|
7
8
|
* it matches the expected schema of the local config.
|
|
@@ -30,7 +31,8 @@ var tslib_1 = require("tslib");
|
|
|
30
31
|
* @returns Transformed config object compatible with local schema
|
|
31
32
|
*/
|
|
32
33
|
function translateRemoteConfigToLocal(config) {
|
|
33
|
-
var e_1, _a;
|
|
34
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
35
|
+
var _d, _e, _f, _g;
|
|
34
36
|
// Disabling type checking rules because remote config comes from a remote source
|
|
35
37
|
// and this function needs to handle any unexpected values
|
|
36
38
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access,
|
|
@@ -82,10 +84,53 @@ function translateRemoteConfigToLocal(config) {
|
|
|
82
84
|
}
|
|
83
85
|
finally { if (e_1) throw e_1.error; }
|
|
84
86
|
}
|
|
87
|
+
// translate remote responseHeaders and requestHeaders to local responseHeaders and requestHeaders
|
|
88
|
+
try {
|
|
89
|
+
if ((_f = (_e = (_d = config.autocapture) === null || _d === void 0 ? void 0 : _d.networkTracking) === null || _e === void 0 ? void 0 : _e.captureRules) === null || _f === void 0 ? void 0 : _f.length) {
|
|
90
|
+
try {
|
|
91
|
+
for (var _h = tslib_1.__values(config.autocapture.networkTracking.captureRules), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
92
|
+
var rule = _j.value;
|
|
93
|
+
try {
|
|
94
|
+
for (var _k = (e_3 = void 0, tslib_1.__values(['responseHeaders', 'requestHeaders'])), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
95
|
+
var header = _l.value;
|
|
96
|
+
var _m = (_g = rule[header]) !== null && _g !== void 0 ? _g : {}, captureSafeHeaders = _m.captureSafeHeaders, allowlist = _m.allowlist;
|
|
97
|
+
if (!captureSafeHeaders && !allowlist) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
// if allowlist is not an array, remote config contract is violated, remove it
|
|
101
|
+
if (allowlist !== undefined && !Array.isArray(allowlist)) {
|
|
102
|
+
delete rule[header];
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
rule[header] = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read((captureSafeHeaders ? analytics_core_1.SAFE_HEADERS : [])), false), tslib_1.__read((allowlist !== null && allowlist !== void 0 ? allowlist : [])), false);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
109
|
+
finally {
|
|
110
|
+
try {
|
|
111
|
+
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
112
|
+
}
|
|
113
|
+
finally { if (e_3) throw e_3.error; }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
118
|
+
finally {
|
|
119
|
+
try {
|
|
120
|
+
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
121
|
+
}
|
|
122
|
+
finally { if (e_2) throw e_2.error; }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
/* istanbul ignore next */
|
|
128
|
+
// surprise exception, so don't translate it
|
|
129
|
+
}
|
|
85
130
|
}
|
|
86
131
|
exports.translateRemoteConfigToLocal = translateRemoteConfigToLocal;
|
|
87
132
|
function mergeUrls(urlsExact, urlsRegex, browserConfig) {
|
|
88
|
-
var
|
|
133
|
+
var e_4, _a;
|
|
89
134
|
// Convert string patterns to RegExp objects, warn on invalid patterns and skip them
|
|
90
135
|
var regexList = [];
|
|
91
136
|
try {
|
|
@@ -99,12 +144,12 @@ function mergeUrls(urlsExact, urlsRegex, browserConfig) {
|
|
|
99
144
|
}
|
|
100
145
|
}
|
|
101
146
|
}
|
|
102
|
-
catch (
|
|
147
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
103
148
|
finally {
|
|
104
149
|
try {
|
|
105
150
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
106
151
|
}
|
|
107
|
-
finally { if (
|
|
152
|
+
finally { if (e_4) throw e_4.error; }
|
|
108
153
|
}
|
|
109
154
|
return urlsExact.concat(regexList);
|
|
110
155
|
}
|
|
@@ -116,7 +161,7 @@ function mergeUrls(urlsExact, urlsRegex, browserConfig) {
|
|
|
116
161
|
* @param browserConfig - The browser config object to update (modified in place)
|
|
117
162
|
*/
|
|
118
163
|
function updateBrowserConfigWithRemoteConfig(remoteConfig, browserConfig) {
|
|
119
|
-
var
|
|
164
|
+
var e_5, _a;
|
|
120
165
|
var _b, _c, _d, _e, _f;
|
|
121
166
|
if (!remoteConfig) {
|
|
122
167
|
return;
|
|
@@ -168,12 +213,12 @@ function updateBrowserConfigWithRemoteConfig(remoteConfig, browserConfig) {
|
|
|
168
213
|
delete rule.urlsRegex;
|
|
169
214
|
}
|
|
170
215
|
}
|
|
171
|
-
catch (
|
|
216
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
172
217
|
finally {
|
|
173
218
|
try {
|
|
174
219
|
if (captureRules_1_1 && !captureRules_1_1.done && (_a = captureRules_1.return)) _a.call(captureRules_1);
|
|
175
220
|
}
|
|
176
|
-
finally { if (
|
|
221
|
+
finally { if (e_5) throw e_5.error; }
|
|
177
222
|
}
|
|
178
223
|
}
|
|
179
224
|
if (typeof browserConfig.autocapture === 'boolean') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";;;;AAuCA;;;;;;;;;;;;;;;;;;;;;;;;;;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,4BAA4B,CAAC,KAA4B,CAAC,CAAC;aAC5D;YAAC,OAAO,CAAC,EAAE;gBACV,uDAAuD;gBACvD,wBAAwB;gBACxB,qDAAqD;aACtD;SACF;;;;;;;;;AACH,CAAC;AA3CD,oEA2CC;AAED,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serConfig,\n RemoteConfig,\n NetworkTrackingOptions,\n NetworkCaptureRule,\n} from '@amplitude/analytics-core';\n\nexport interface AutocaptureOptionsRemoteConfig extends AutocaptureOptions {\n elementInteractions?: boolean | ElementInteractionsOptionsRemoteConfig;\n networkTracking?: boolean | NetworkTrackingOptionsRemoteConfig;\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\nexport interface NetworkCaptureRuleRemoteConfig extends NetworkCaptureRule {\n /**\n * Related to urls but holds regex strings which will be initialized and appended to urls\n */\n urlsRegex?: string[];\n}\n\nexport interface NetworkTrackingOptionsRemoteConfig extends NetworkTrackingOptions {\n /**\n * Related to pageUrlAllowlist but holds regex strings which will be initialized and appended to pageUrlAllowlist\n */\n captureRules?: NetworkCaptureRuleRemoteConfig[];\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\nfunction mergeUrls(urlsExact: (string | RegExp)[], urlsRegex: string[] | undefined, browserConfig: BrowserConfig) {\n // Convert string patterns to RegExp objects, warn on invalid patterns and skip them\n const regexList = [];\n for (const pattern of urlsRegex ?? []) {\n try {\n regexList.push(new RegExp(pattern));\n } catch (regexError) {\n browserConfig.loggerProvider.warn(`Invalid regex pattern: ${pattern}`, regexError);\n }\n }\n\n return urlsExact.concat(regexList);\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 // combine exact allow list and regex allow list into just 'pageUrlAllowlist'\n const exactAllowList = transformedRcElementInteractions.pageUrlAllowlist ?? [];\n const urlsRegex = typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex;\n transformedRcElementInteractions.pageUrlAllowlist = mergeUrls(exactAllowList, urlsRegex, browserConfig);\n\n // clean up the regex allow list\n delete transformedRcElementInteractions.pageUrlAllowlistRegex;\n }\n\n // Handle Network Tracking config initialization\n if (\n typeof typedRemoteConfig.autocapture.networkTracking === 'object' &&\n typedRemoteConfig.autocapture.networkTracking !== null &&\n typedRemoteConfig.autocapture.networkTracking.captureRules?.length\n ) {\n transformedAutocaptureRemoteConfig.networkTracking = {\n ...typedRemoteConfig.autocapture.networkTracking,\n };\n const transformedRcNetworkTracking = transformedAutocaptureRemoteConfig.networkTracking;\n /* istanbul ignore next */\n const captureRules = transformedRcNetworkTracking.captureRules ?? [];\n for (const rule of captureRules) {\n rule.urls = mergeUrls(rule.urls ?? [], rule.urlsRegex, browserConfig);\n delete rule.urlsRegex;\n }\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":";;;;AAAA,4DAQmC;AAgCnC;;;;;;;;;;;;;;;;;;;;;;;;;;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,4C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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;AAxGD,kFAwGC","sourcesContent":["import {\n AutocaptureOptions,\n type ElementInteractionsOptions,\n BrowserConfig,\n RemoteConfig,\n NetworkTrackingOptions,\n NetworkCaptureRule,\n SAFE_HEADERS,\n} from '@amplitude/analytics-core';\n\nexport interface AutocaptureOptionsRemoteConfig extends AutocaptureOptions {\n elementInteractions?: boolean | ElementInteractionsOptionsRemoteConfig;\n networkTracking?: boolean | NetworkTrackingOptionsRemoteConfig;\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\nexport interface NetworkCaptureRuleRemoteConfig extends NetworkCaptureRule {\n /**\n * Related to urls but holds regex strings which will be initialized and appended to urls\n */\n urlsRegex?: string[];\n}\n\nexport interface NetworkTrackingOptionsRemoteConfig extends NetworkTrackingOptions {\n /**\n * Related to pageUrlAllowlist but holds regex strings which will be initialized and appended to pageUrlAllowlist\n */\n captureRules?: NetworkCaptureRuleRemoteConfig[];\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 // translate remote responseHeaders and requestHeaders to local responseHeaders and requestHeaders\n try {\n if (config.autocapture?.networkTracking?.captureRules?.length) {\n for (const rule of config.autocapture.networkTracking.captureRules) {\n for (const header of ['responseHeaders', 'requestHeaders']) {\n const { captureSafeHeaders, allowlist } = rule[header] ?? {};\n if (!captureSafeHeaders && !allowlist) {\n continue;\n }\n // if allowlist is not an array, remote config contract is violated, remove it\n if (allowlist !== undefined && !Array.isArray(allowlist)) {\n delete rule[header];\n continue;\n }\n rule[header] = [...(captureSafeHeaders ? SAFE_HEADERS : []), ...(allowlist ?? [])];\n }\n }\n }\n } catch (e) {\n /* istanbul ignore next */\n // surprise exception, so don't translate it\n }\n}\n\nfunction mergeUrls(urlsExact: (string | RegExp)[], urlsRegex: string[] | undefined, browserConfig: BrowserConfig) {\n // Convert string patterns to RegExp objects, warn on invalid patterns and skip them\n const regexList = [];\n for (const pattern of urlsRegex ?? []) {\n try {\n regexList.push(new RegExp(pattern));\n } catch (regexError) {\n browserConfig.loggerProvider.warn(`Invalid regex pattern: ${pattern}`, regexError);\n }\n }\n\n return urlsExact.concat(regexList);\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 // combine exact allow list and regex allow list into just 'pageUrlAllowlist'\n const exactAllowList = transformedRcElementInteractions.pageUrlAllowlist ?? [];\n const urlsRegex = typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex;\n transformedRcElementInteractions.pageUrlAllowlist = mergeUrls(exactAllowList, urlsRegex, browserConfig);\n\n // clean up the regex allow list\n delete transformedRcElementInteractions.pageUrlAllowlistRegex;\n }\n\n // Handle Network Tracking config initialization\n if (\n typeof typedRemoteConfig.autocapture.networkTracking === 'object' &&\n typedRemoteConfig.autocapture.networkTracking !== null &&\n typedRemoteConfig.autocapture.networkTracking.captureRules?.length\n ) {\n transformedAutocaptureRemoteConfig.networkTracking = {\n ...typedRemoteConfig.autocapture.networkTracking,\n };\n const transformedRcNetworkTracking = transformedAutocaptureRemoteConfig.networkTracking;\n /* istanbul ignore next */\n const captureRules = transformedRcNetworkTracking.captureRules ?? [];\n for (const rule of captureRules) {\n rule.urls = mergeUrls(rule.urls ?? [], rule.urlsRegex, browserConfig);\n delete rule.urlsRegex;\n }\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"]}
|
package/lib/cjs/config.d.ts
CHANGED
|
@@ -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.24.
|
|
34
|
+
readonly version = "2.24.2";
|
|
35
35
|
protected _cookieStorage: Storage<UserSession>;
|
|
36
36
|
protected _deviceId?: string;
|
|
37
37
|
protected _lastEventId?: number;
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.24.
|
|
1
|
+
export declare const VERSION = "2.24.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/cjs/version.js
CHANGED
package/lib/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '2.24.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '2.24.2';\n"]}
|
|
@@ -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,EACZ,sBAAsB,EACtB,kBAAkB,
|
|
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,EACZ,sBAAsB,EACtB,kBAAkB,EAEnB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,8BAA+B,SAAQ,kBAAkB;IACxE,mBAAmB,CAAC,EAAE,OAAO,GAAG,sCAAsC,CAAC;IACvE,eAAe,CAAC,EAAE,OAAO,GAAG,kCAAkC,CAAC;CAChE;AACD,MAAM,WAAW,sCAAuC,SAAQ,0BAA0B;IACxF;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,8BAA+B,SAAQ,kBAAkB;IACxE;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,kCAAmC,SAAQ,sBAAsB;IAChF;;OAEG;IACH,YAAY,CAAC,EAAE,8BAA8B,EAAE,CAAC;CACjD;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAkExE;AAgBD;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CACjD,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,aAAa,EAAE,aAAa,GAC3B,IAAI,CAqGN"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { __assign, __values } from "tslib";
|
|
1
|
+
import { __assign, __read, __spreadArray, __values } from "tslib";
|
|
2
|
+
import { SAFE_HEADERS, } from '@amplitude/analytics-core';
|
|
2
3
|
/**
|
|
3
4
|
* Performs a deep transformation of a remote config object so that
|
|
4
5
|
* it matches the expected schema of the local config.
|
|
@@ -27,7 +28,8 @@ import { __assign, __values } from "tslib";
|
|
|
27
28
|
* @returns Transformed config object compatible with local schema
|
|
28
29
|
*/
|
|
29
30
|
export function translateRemoteConfigToLocal(config) {
|
|
30
|
-
var e_1, _a;
|
|
31
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
32
|
+
var _d, _e, _f, _g;
|
|
31
33
|
// Disabling type checking rules because remote config comes from a remote source
|
|
32
34
|
// and this function needs to handle any unexpected values
|
|
33
35
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access,
|
|
@@ -79,9 +81,52 @@ export function translateRemoteConfigToLocal(config) {
|
|
|
79
81
|
}
|
|
80
82
|
finally { if (e_1) throw e_1.error; }
|
|
81
83
|
}
|
|
84
|
+
// translate remote responseHeaders and requestHeaders to local responseHeaders and requestHeaders
|
|
85
|
+
try {
|
|
86
|
+
if ((_f = (_e = (_d = config.autocapture) === null || _d === void 0 ? void 0 : _d.networkTracking) === null || _e === void 0 ? void 0 : _e.captureRules) === null || _f === void 0 ? void 0 : _f.length) {
|
|
87
|
+
try {
|
|
88
|
+
for (var _h = __values(config.autocapture.networkTracking.captureRules), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
89
|
+
var rule = _j.value;
|
|
90
|
+
try {
|
|
91
|
+
for (var _k = (e_3 = void 0, __values(['responseHeaders', 'requestHeaders'])), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
92
|
+
var header = _l.value;
|
|
93
|
+
var _m = (_g = rule[header]) !== null && _g !== void 0 ? _g : {}, captureSafeHeaders = _m.captureSafeHeaders, allowlist = _m.allowlist;
|
|
94
|
+
if (!captureSafeHeaders && !allowlist) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
// if allowlist is not an array, remote config contract is violated, remove it
|
|
98
|
+
if (allowlist !== undefined && !Array.isArray(allowlist)) {
|
|
99
|
+
delete rule[header];
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
rule[header] = __spreadArray(__spreadArray([], __read((captureSafeHeaders ? SAFE_HEADERS : [])), false), __read((allowlist !== null && allowlist !== void 0 ? allowlist : [])), false);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
106
|
+
finally {
|
|
107
|
+
try {
|
|
108
|
+
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
109
|
+
}
|
|
110
|
+
finally { if (e_3) throw e_3.error; }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
115
|
+
finally {
|
|
116
|
+
try {
|
|
117
|
+
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
118
|
+
}
|
|
119
|
+
finally { if (e_2) throw e_2.error; }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
/* istanbul ignore next */
|
|
125
|
+
// surprise exception, so don't translate it
|
|
126
|
+
}
|
|
82
127
|
}
|
|
83
128
|
function mergeUrls(urlsExact, urlsRegex, browserConfig) {
|
|
84
|
-
var
|
|
129
|
+
var e_4, _a;
|
|
85
130
|
// Convert string patterns to RegExp objects, warn on invalid patterns and skip them
|
|
86
131
|
var regexList = [];
|
|
87
132
|
try {
|
|
@@ -95,12 +140,12 @@ function mergeUrls(urlsExact, urlsRegex, browserConfig) {
|
|
|
95
140
|
}
|
|
96
141
|
}
|
|
97
142
|
}
|
|
98
|
-
catch (
|
|
143
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
99
144
|
finally {
|
|
100
145
|
try {
|
|
101
146
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
102
147
|
}
|
|
103
|
-
finally { if (
|
|
148
|
+
finally { if (e_4) throw e_4.error; }
|
|
104
149
|
}
|
|
105
150
|
return urlsExact.concat(regexList);
|
|
106
151
|
}
|
|
@@ -112,7 +157,7 @@ function mergeUrls(urlsExact, urlsRegex, browserConfig) {
|
|
|
112
157
|
* @param browserConfig - The browser config object to update (modified in place)
|
|
113
158
|
*/
|
|
114
159
|
export function updateBrowserConfigWithRemoteConfig(remoteConfig, browserConfig) {
|
|
115
|
-
var
|
|
160
|
+
var e_5, _a;
|
|
116
161
|
var _b, _c, _d, _e, _f;
|
|
117
162
|
if (!remoteConfig) {
|
|
118
163
|
return;
|
|
@@ -164,12 +209,12 @@ export function updateBrowserConfigWithRemoteConfig(remoteConfig, browserConfig)
|
|
|
164
209
|
delete rule.urlsRegex;
|
|
165
210
|
}
|
|
166
211
|
}
|
|
167
|
-
catch (
|
|
212
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
168
213
|
finally {
|
|
169
214
|
try {
|
|
170
215
|
if (captureRules_1_1 && !captureRules_1_1.done && (_a = captureRules_1.return)) _a.call(captureRules_1);
|
|
171
216
|
}
|
|
172
|
-
finally { if (
|
|
217
|
+
finally { if (e_5) throw e_5.error; }
|
|
173
218
|
}
|
|
174
219
|
}
|
|
175
220
|
if (typeof browserConfig.autocapture === 'boolean') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";AAuCA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,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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E,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 NetworkTrackingOptions,\n NetworkCaptureRule,\n} from '@amplitude/analytics-core';\n\nexport interface AutocaptureOptionsRemoteConfig extends AutocaptureOptions {\n elementInteractions?: boolean | ElementInteractionsOptionsRemoteConfig;\n networkTracking?: boolean | NetworkTrackingOptionsRemoteConfig;\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\nexport interface NetworkCaptureRuleRemoteConfig extends NetworkCaptureRule {\n /**\n * Related to urls but holds regex strings which will be initialized and appended to urls\n */\n urlsRegex?: string[];\n}\n\nexport interface NetworkTrackingOptionsRemoteConfig extends NetworkTrackingOptions {\n /**\n * Related to pageUrlAllowlist but holds regex strings which will be initialized and appended to pageUrlAllowlist\n */\n captureRules?: NetworkCaptureRuleRemoteConfig[];\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\nfunction mergeUrls(urlsExact: (string | RegExp)[], urlsRegex: string[] | undefined, browserConfig: BrowserConfig) {\n // Convert string patterns to RegExp objects, warn on invalid patterns and skip them\n const regexList = [];\n for (const pattern of urlsRegex ?? []) {\n try {\n regexList.push(new RegExp(pattern));\n } catch (regexError) {\n browserConfig.loggerProvider.warn(`Invalid regex pattern: ${pattern}`, regexError);\n }\n }\n\n return urlsExact.concat(regexList);\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 // combine exact allow list and regex allow list into just 'pageUrlAllowlist'\n const exactAllowList = transformedRcElementInteractions.pageUrlAllowlist ?? [];\n const urlsRegex = typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex;\n transformedRcElementInteractions.pageUrlAllowlist = mergeUrls(exactAllowList, urlsRegex, browserConfig);\n\n // clean up the regex allow list\n delete transformedRcElementInteractions.pageUrlAllowlistRegex;\n }\n\n // Handle Network Tracking config initialization\n if (\n typeof typedRemoteConfig.autocapture.networkTracking === 'object' &&\n typedRemoteConfig.autocapture.networkTracking !== null &&\n typedRemoteConfig.autocapture.networkTracking.captureRules?.length\n ) {\n transformedAutocaptureRemoteConfig.networkTracking = {\n ...typedRemoteConfig.autocapture.networkTracking,\n };\n const transformedRcNetworkTracking = transformedAutocaptureRemoteConfig.networkTracking;\n /* istanbul ignore next */\n const captureRules = transformedRcNetworkTracking.captureRules ?? [];\n for (const rule of captureRules) {\n rule.urls = mergeUrls(rule.urls ?? [], rule.urlsRegex, browserConfig);\n delete rule.urlsRegex;\n }\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":";AAAA,OAAO,EAOL,YAAY,GACb,MAAM,2BAA2B,CAAC;AAgCnC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,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,SAAA,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,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AAC;KAClG;AACH,CAAC","sourcesContent":["import {\n AutocaptureOptions,\n type ElementInteractionsOptions,\n BrowserConfig,\n RemoteConfig,\n NetworkTrackingOptions,\n NetworkCaptureRule,\n SAFE_HEADERS,\n} from '@amplitude/analytics-core';\n\nexport interface AutocaptureOptionsRemoteConfig extends AutocaptureOptions {\n elementInteractions?: boolean | ElementInteractionsOptionsRemoteConfig;\n networkTracking?: boolean | NetworkTrackingOptionsRemoteConfig;\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\nexport interface NetworkCaptureRuleRemoteConfig extends NetworkCaptureRule {\n /**\n * Related to urls but holds regex strings which will be initialized and appended to urls\n */\n urlsRegex?: string[];\n}\n\nexport interface NetworkTrackingOptionsRemoteConfig extends NetworkTrackingOptions {\n /**\n * Related to pageUrlAllowlist but holds regex strings which will be initialized and appended to pageUrlAllowlist\n */\n captureRules?: NetworkCaptureRuleRemoteConfig[];\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 // translate remote responseHeaders and requestHeaders to local responseHeaders and requestHeaders\n try {\n if (config.autocapture?.networkTracking?.captureRules?.length) {\n for (const rule of config.autocapture.networkTracking.captureRules) {\n for (const header of ['responseHeaders', 'requestHeaders']) {\n const { captureSafeHeaders, allowlist } = rule[header] ?? {};\n if (!captureSafeHeaders && !allowlist) {\n continue;\n }\n // if allowlist is not an array, remote config contract is violated, remove it\n if (allowlist !== undefined && !Array.isArray(allowlist)) {\n delete rule[header];\n continue;\n }\n rule[header] = [...(captureSafeHeaders ? SAFE_HEADERS : []), ...(allowlist ?? [])];\n }\n }\n }\n } catch (e) {\n /* istanbul ignore next */\n // surprise exception, so don't translate it\n }\n}\n\nfunction mergeUrls(urlsExact: (string | RegExp)[], urlsRegex: string[] | undefined, browserConfig: BrowserConfig) {\n // Convert string patterns to RegExp objects, warn on invalid patterns and skip them\n const regexList = [];\n for (const pattern of urlsRegex ?? []) {\n try {\n regexList.push(new RegExp(pattern));\n } catch (regexError) {\n browserConfig.loggerProvider.warn(`Invalid regex pattern: ${pattern}`, regexError);\n }\n }\n\n return urlsExact.concat(regexList);\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 // combine exact allow list and regex allow list into just 'pageUrlAllowlist'\n const exactAllowList = transformedRcElementInteractions.pageUrlAllowlist ?? [];\n const urlsRegex = typedRemoteConfig.autocapture.elementInteractions.pageUrlAllowlistRegex;\n transformedRcElementInteractions.pageUrlAllowlist = mergeUrls(exactAllowList, urlsRegex, browserConfig);\n\n // clean up the regex allow list\n delete transformedRcElementInteractions.pageUrlAllowlistRegex;\n }\n\n // Handle Network Tracking config initialization\n if (\n typeof typedRemoteConfig.autocapture.networkTracking === 'object' &&\n typedRemoteConfig.autocapture.networkTracking !== null &&\n typedRemoteConfig.autocapture.networkTracking.captureRules?.length\n ) {\n transformedAutocaptureRemoteConfig.networkTracking = {\n ...typedRemoteConfig.autocapture.networkTracking,\n };\n const transformedRcNetworkTracking = transformedAutocaptureRemoteConfig.networkTracking;\n /* istanbul ignore next */\n const captureRules = transformedRcNetworkTracking.captureRules ?? [];\n for (const rule of captureRules) {\n rule.urls = mergeUrls(rule.urls ?? [], rule.urlsRegex, browserConfig);\n delete rule.urlsRegex;\n }\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"]}
|
package/lib/esm/config.d.ts
CHANGED
|
@@ -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.24.
|
|
34
|
+
readonly version = "2.24.2";
|
|
35
35
|
protected _cookieStorage: Storage<UserSession>;
|
|
36
36
|
protected _deviceId?: string;
|
|
37
37
|
protected _lastEventId?: number;
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.24.
|
|
1
|
+
export declare const VERSION = "2.24.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export var VERSION = '2.24.
|
|
1
|
+
export var VERSION = '2.24.2';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/lib/esm/version.js.map
CHANGED
|
@@ -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.24.
|
|
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.24.2';\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 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-
|
|
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-yZgkX3BTOI6qmBCIQ4XyWMnm/b1L0Qh2jnFdufiihbdCtPftQRPshyvrPxRQQRj3",c.crossOrigin="anonymous",c.async=!1,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.24.2-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&&litudeAutocapturePlugin.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%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-
|
|
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-yZgkX3BTOI6qmBCIQ4XyWMnm%2Fb1L0Qh2jnFdufiihbdCtPftQRPshyvrPxRQQRj3%22%2Cc.crossOrigin%3D%22anonymous%22%2Cc.async%3D!1%2Cc.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fanalytics-browser-2.24.2-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
|