@amplitude/analytics-browser 2.36.2 → 2.36.4-SR-2728.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/cjs/attribution/helpers.d.ts +1 -0
- package/lib/cjs/attribution/helpers.d.ts.map +1 -1
- package/lib/cjs/attribution/helpers.js +22 -4
- package/lib/cjs/attribution/helpers.js.map +1 -1
- package/lib/cjs/browser-client.d.ts.map +1 -1
- package/lib/cjs/browser-client.js +40 -37
- package/lib/cjs/browser-client.js.map +1 -1
- package/lib/cjs/config.d.ts +1 -1
- package/lib/cjs/config.d.ts.map +1 -1
- package/lib/cjs/config.js +58 -32
- package/lib/cjs/config.js.map +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.d.ts.map +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/attribution/helpers.d.ts +1 -0
- package/lib/esm/attribution/helpers.d.ts.map +1 -1
- package/lib/esm/attribution/helpers.js +20 -2
- package/lib/esm/attribution/helpers.js.map +1 -1
- package/lib/esm/browser-client.d.ts.map +1 -1
- package/lib/esm/browser-client.js +41 -38
- package/lib/esm/browser-client.js.map +1 -1
- package/lib/esm/config.d.ts +1 -1
- package/lib/esm/config.d.ts.map +1 -1
- package/lib/esm/config.js +59 -33
- package/lib/esm/config.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.d.ts.map +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/amplitude-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/attribution/helpers.d.ts +1 -0
- package/lib/scripts/attribution/helpers.d.ts.map +1 -1
- package/lib/scripts/browser-client.d.ts.map +1 -1
- package/lib/scripts/config.d.ts +4 -4
- package/lib/scripts/config.d.ts.map +1 -1
- package/lib/scripts/constants.d.ts +12 -12
- package/lib/scripts/constants.d.ts.map +1 -1
- package/lib/scripts/cookie-migration/index.d.ts.map +1 -1
- package/lib/scripts/default-tracking.d.ts.map +1 -1
- package/lib/scripts/det-notification.d.ts.map +1 -1
- package/lib/scripts/index.d.ts +4 -4
- package/lib/scripts/index.d.ts.map +1 -1
- package/lib/scripts/plugins/context.d.ts.map +1 -1
- package/lib/scripts/plugins/form-interaction-tracking.d.ts.map +1 -1
- package/lib/scripts/utils/snippet-helper.d.ts.map +1 -1
- package/lib/scripts/version.d.ts +1 -1
- package/lib/scripts/version.d.ts.map +1 -1
- package/package.json +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<g.length;r++)o(e,g[r],!0)};r.invoked=!0;var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-
|
|
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<g.length;r++)o(e,g[r],!0)};r.invoked=!0;var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-JfhwI3LvG9R8dV0zcveg4VJTykiaRPE5UlbHkGmqj9IJqfhCy+BYkGw8wNjmXrB2",c.crossOrigin="anonymous",c.async=!0,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.36.4-SR-2728.0-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},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"],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>
|
|
@@ -12,5 +12,6 @@ export declare const isExcludedReferrer: (excludeReferrers?: (string | RegExp)[]
|
|
|
12
12
|
export declare const isSubdomainOf: (subDomain: string, domain: string) => boolean;
|
|
13
13
|
export declare const createCampaignEvent: (campaign: Campaign, options: Options) => import("@amplitude/analytics-core").IdentifyEvent;
|
|
14
14
|
export declare const getDefaultExcludedReferrers: (cookieDomain: string | undefined) => RegExp[];
|
|
15
|
+
export declare const KNOWN_2LDS: string[];
|
|
15
16
|
export declare const getDomain: (hostnameParam?: string) => string;
|
|
16
17
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/attribution/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,OAAO,EACP,QAAQ,EAGT,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,+BAA+B,EAAyC,MAAM,UAAU,CAAC;AAElG,MAAM,WAAW,OAAO;IACtB,gBAAgB,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IACvC,wBAAwB,CAAC,EAAE,IAAI,GAAG,KAAK,GAAG,+BAA+B,CAAC;IAC1E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAsBD,eAAO,MAAM,aAAa,YACf,QAAQ,YACP,QAAQ,GAAG,SAAS,WACrB,OAAO,UACR,OAAO,2CAEE,MAAM,YAiDxB,CAAC;AAEF,eAAO,MAAM,kBAAkB,sBAAsB,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 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDomain = exports.getDefaultExcludedReferrers = exports.createCampaignEvent = exports.isSubdomainOf = exports.isExcludedReferrer = exports.isNewCampaign = void 0;
|
|
3
|
+
exports.getDomain = exports.KNOWN_2LDS = exports.getDefaultExcludedReferrers = exports.createCampaignEvent = exports.isSubdomainOf = exports.isExcludedReferrer = exports.isNewCampaign = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
6
6
|
var types_1 = require("../types");
|
|
@@ -142,10 +142,12 @@ function debugLogInternalReferrerExclude(condition, referringDomain, logger) {
|
|
|
142
142
|
logger.debug("".concat(baseMessage, " with empty campaign parameters"));
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
// list of domains that are known ccTLDs
|
|
146
|
-
|
|
145
|
+
// list of domains that are known ccTLDs that are commonly used
|
|
146
|
+
// and are in the Public Suffix List (https://publicsuffix.org/)
|
|
147
|
+
exports.KNOWN_2LDS = [
|
|
147
148
|
'ac.in',
|
|
148
149
|
'ac.jp',
|
|
150
|
+
'ac.kr',
|
|
149
151
|
'ac.th',
|
|
150
152
|
'ac.uk',
|
|
151
153
|
'ac.za',
|
|
@@ -153,6 +155,8 @@ var KNOWN_2LDS = [
|
|
|
153
155
|
'asn.au',
|
|
154
156
|
'azurewebsites.net',
|
|
155
157
|
'cloudfront.net',
|
|
158
|
+
'myshopify.com',
|
|
159
|
+
'blogspot.com',
|
|
156
160
|
'co.ca',
|
|
157
161
|
'co.in',
|
|
158
162
|
'co.jp',
|
|
@@ -176,25 +180,33 @@ var KNOWN_2LDS = [
|
|
|
176
180
|
'com.tw',
|
|
177
181
|
'ed.jp',
|
|
178
182
|
'edu.au',
|
|
183
|
+
'edu.br',
|
|
184
|
+
'edu.cn',
|
|
179
185
|
'edu.hk',
|
|
180
186
|
'edu.sg',
|
|
181
187
|
'edu.th',
|
|
182
188
|
'edu.tr',
|
|
183
189
|
'edu.tw',
|
|
184
190
|
'firebaseapp.com',
|
|
191
|
+
'fly.dev',
|
|
185
192
|
'gc.ca',
|
|
186
193
|
'geek.nz',
|
|
187
194
|
'github.io',
|
|
188
195
|
'gitlab.io',
|
|
196
|
+
'go.jp',
|
|
189
197
|
'go.kr',
|
|
190
198
|
'go.th',
|
|
191
199
|
'gob.ar',
|
|
200
|
+
'gob.mx',
|
|
192
201
|
'gov.au',
|
|
202
|
+
'gov.br',
|
|
203
|
+
'gov.cn',
|
|
193
204
|
'gov.hk',
|
|
194
205
|
'gov.in',
|
|
195
206
|
'gov.pl',
|
|
196
207
|
'gov.sg',
|
|
197
208
|
'gov.tr',
|
|
209
|
+
'gov.tw',
|
|
198
210
|
'gov.uk',
|
|
199
211
|
'gov.za',
|
|
200
212
|
'govt.nz',
|
|
@@ -221,6 +233,7 @@ var KNOWN_2LDS = [
|
|
|
221
233
|
'net.tr',
|
|
222
234
|
'net.tw',
|
|
223
235
|
'net.za',
|
|
236
|
+
'onrender.com',
|
|
224
237
|
'or.jp',
|
|
225
238
|
'or.kr',
|
|
226
239
|
'or.th',
|
|
@@ -230,17 +243,22 @@ var KNOWN_2LDS = [
|
|
|
230
243
|
'org.cn',
|
|
231
244
|
'org.hk',
|
|
232
245
|
'org.in',
|
|
246
|
+
'org.mx',
|
|
233
247
|
'org.nz',
|
|
234
248
|
'org.pl',
|
|
235
249
|
'org.sg',
|
|
236
250
|
'org.tw',
|
|
237
251
|
'org.uk',
|
|
238
252
|
'org.za',
|
|
253
|
+
'pages.dev',
|
|
239
254
|
'pe.kr',
|
|
240
255
|
'plc.uk',
|
|
241
256
|
're.kr',
|
|
242
257
|
'res.in',
|
|
243
258
|
'sch.uk',
|
|
259
|
+
'vercel.app',
|
|
260
|
+
'netlify.app',
|
|
261
|
+
'workers.dev',
|
|
244
262
|
];
|
|
245
263
|
var getDomain = function (hostnameParam) {
|
|
246
264
|
var _a, _b;
|
|
@@ -252,7 +270,7 @@ var getDomain = function (hostnameParam) {
|
|
|
252
270
|
var parts = hostname.split('.');
|
|
253
271
|
var tld = parts[parts.length - 1];
|
|
254
272
|
var name = parts[parts.length - 2];
|
|
255
|
-
if (KNOWN_2LDS.find(function (tld) { return hostname.endsWith(".".concat(tld)); })) {
|
|
273
|
+
if (exports.KNOWN_2LDS.find(function (tld) { return hostname.endsWith(".".concat(tld)); })) {
|
|
256
274
|
tld = parts[parts.length - 2] + '.' + parts[parts.length - 1];
|
|
257
275
|
name = parts[parts.length - 3];
|
|
258
276
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/attribution/helpers.ts"],"names":[],"mappings":";;;;AAAA,4DAOmC;AAEnC,kCAAkG;AAUlG,IAAM,sBAAsB,GAAG,UAAC,MAAc;IAC5C,IAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEhC,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE;QACrB,OAAO,MAAM,CAAC;KACf;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,kIAAkI;AAClI,IAAM,eAAe,GAAG,UAAC,OAAiB;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,UAAC,KAAK,IAAK,OAAA,CAAC,KAAK,EAAN,CAAM,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,IAAM,eAAe,GAAG,UAAC,QAAkB;IACzC,IAAM,uBAAuB,yCAAQ,QAAQ,KAAE,gBAAgB,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAE,CAAC;IAClG,OAAO,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,KAAK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AC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACjG,OAAO,IAAA,qBAAa,EAAC,eAAe,EAAE,cAAc,CAAC,CAAC;AACxD,CAAC,CAAC","sourcesContent":["import {\n createIdentifyEvent,\n Identify,\n ILogger,\n Campaign,\n BASE_CAMPAIGN,\n getGlobalScope,\n} from '@amplitude/analytics-core';\n\nimport { ExcludeInternalReferrersOptions, EXCLUDE_INTERNAL_REFERRERS_CONDITIONS } from '../types';\n\nexport interface Options {\n excludeReferrers?: (string | RegExp)[];\n excludeInternalReferrers?: true | false | ExcludeInternalReferrersOptions;\n initialEmptyValue?: string;\n resetSessionOnNewCampaign?: boolean;\n optOut?: boolean;\n}\n\nconst domainWithoutSubdomain = (domain: string) => {\n const parts = domain.split('.');\n\n if (parts.length <= 2) {\n return domain;\n }\n\n return parts.slice(parts.length - 2, parts.length).join('.');\n};\n\n//Direct traffic mean no external referral, no UTMs, no click-ids, and no other customer identified marketing campaign url params.\nconst isDirectTraffic = (current: Campaign) => {\n return Object.values(current).every((value) => !value);\n};\n\nconst isEmptyCampaign = (campaign: Campaign) => {\n const campaignWithoutReferrer = { ...campaign, referring_domain: undefined, referrer: undefined };\n return Object.values(campaignWithoutReferrer).every((value) => !value);\n};\n\nexport const isNewCampaign = (\n current: Campaign,\n previous: Campaign | undefined,\n options: Options,\n logger: ILogger,\n isNewSession = true,\n topLevelDomain?: string,\n) => {\n const { referrer, referring_domain, ...currentCampaign } = current;\n const { referrer: _previous_referrer, referring_domain: prevReferringDomain, ...previousCampaign } = previous || {};\n\n const { excludeInternalReferrers } = options;\n\n if (excludeInternalReferrers) {\n const condition = getExcludeInternalReferrersCondition(excludeInternalReferrers, logger);\n if (\n !(condition instanceof TypeError) &&\n current.referring_domain &&\n isInternalReferrer(current.referring_domain, topLevelDomain)\n ) {\n if (condition === 'always') {\n debugLogInternalReferrerExclude(condition, current.referring_domain, logger);\n return false;\n } else if (condition === 'ifEmptyCampaign' && isEmptyCampaign(current)) {\n debugLogInternalReferrerExclude(condition, current.referring_domain, logger);\n return false;\n }\n }\n }\n\n if (isExcludedReferrer(options.excludeReferrers, current.referring_domain)) {\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n logger.debug(`This is not a new campaign because ${current.referring_domain} is in the exclude referrer list.`);\n return false;\n }\n\n //In the same session, direct traffic should not override or unset any persisting query params\n if (!isNewSession && isDirectTraffic(current) && previous) {\n logger.debug('This is not a new campaign because this is a direct traffic in the same session.');\n return false;\n }\n\n const hasNewCampaign = JSON.stringify(currentCampaign) !== JSON.stringify(previousCampaign);\n const hasNewDomain =\n domainWithoutSubdomain(referring_domain || '') !== domainWithoutSubdomain(prevReferringDomain || '');\n\n const result = !previous || hasNewCampaign || hasNewDomain;\n\n if (!result) {\n logger.debug(\"This is not a new campaign because it's the same as the previous one.\");\n } else {\n logger.debug(`This is a new campaign. An $identify event will be sent.`);\n }\n\n return result;\n};\n\nexport const isExcludedReferrer = (excludeReferrers: (string | RegExp)[] = [], referringDomain = '') => {\n return excludeReferrers.some((value) =>\n value instanceof RegExp ? value.test(referringDomain) : value === referringDomain,\n );\n};\n\nexport const isSubdomainOf = (subDomain: string, domain: string) => {\n const cookieDomainWithLeadingDot = domain.startsWith('.') ? domain : `.${domain}`;\n const subDomainWithLeadingDot = subDomain.startsWith('.') ? subDomain : `.${subDomain}`;\n if (subDomainWithLeadingDot.endsWith(cookieDomainWithLeadingDot)) return true;\n return false;\n};\n\nexport const createCampaignEvent = (campaign: Campaign, options: Options) => {\n const campaignParameters: Campaign = {\n // This object definition allows undefined keys to be iterated on\n // in .reduce() to build indentify object\n ...BASE_CAMPAIGN,\n ...campaign,\n };\n const identifyEvent = Object.entries(campaignParameters).reduce((identify, [key, value]) => {\n identify.setOnce(`initial_${key}`, value ?? options.initialEmptyValue ?? 'EMPTY');\n if (value) {\n return identify.set(key, value);\n }\n return identify.unset(key);\n }, new Identify());\n\n return createIdentifyEvent(identifyEvent);\n};\n\nexport const getDefaultExcludedReferrers = (cookieDomain: string | undefined) => {\n let domain = cookieDomain;\n if (domain) {\n if (domain.startsWith('.')) {\n domain = domain.substring(1);\n }\n return [new RegExp(`${domain.replace('.', '\\\\.')}$`)];\n }\n return [];\n};\n\n/**\n * Parses the excludeInternalReferrers configuration to determine the condition on which to\n * exclude internal referrers for campaign attribution.\n *\n * If the config is invalid type, log and return a TypeError.\n *\n * (this does explicit type checking so don't have to rely on TS compiler to catch invalid types)\n *\n * @param excludeInternalReferrers - attribution.excludeInternalReferrers configuration\n * @param logger - logger instance to log error when TypeError\n * @returns The condition if the config is valid, TypeError if the config is invalid.\n */\nconst getExcludeInternalReferrersCondition = (\n excludeInternalReferrers: ExcludeInternalReferrersOptions | boolean,\n logger: ILogger,\n): ExcludeInternalReferrersOptions['condition'] | TypeError => {\n if (excludeInternalReferrers === true) {\n return EXCLUDE_INTERNAL_REFERRERS_CONDITIONS.always;\n }\n if (typeof excludeInternalReferrers === 'object') {\n const { condition } = excludeInternalReferrers;\n if (typeof condition === 'string' && Object.keys(EXCLUDE_INTERNAL_REFERRERS_CONDITIONS).includes(condition)) {\n return condition;\n } else if (typeof condition === 'undefined') {\n return EXCLUDE_INTERNAL_REFERRERS_CONDITIONS.always;\n }\n }\n const errorMessage = `Invalid configuration provided for attribution.excludeInternalReferrers: ${JSON.stringify(\n excludeInternalReferrers,\n )}`;\n logger.error(errorMessage);\n return new TypeError(errorMessage);\n};\n\n// helper function to log debug message when internal referrer is excluded\n// (added this to prevent code duplication and improve readability)\nfunction debugLogInternalReferrerExclude(\n condition: ExcludeInternalReferrersOptions['condition'],\n referringDomain: string,\n logger: ILogger,\n) {\n const baseMessage = `This is not a new campaign because referring_domain=${referringDomain} is on the same domain as the current page and it is configured to exclude internal referrers`;\n if (condition === 'always') {\n logger.debug(baseMessage);\n } else if (condition === 'ifEmptyCampaign') {\n logger.debug(`${baseMessage} with empty campaign parameters`);\n }\n}\n\n// list of domains that are known ccTLDs or domains that are commonly subtenanted\nconst KNOWN_2LDS = [\n 'ac.in',\n 'ac.jp',\n 'ac.th',\n 'ac.uk',\n 'ac.za',\n 'appspot.com',\n 'asn.au',\n 'azurewebsites.net',\n 'cloudfront.net',\n 'co.ca',\n 'co.in',\n 'co.jp',\n 'co.kr',\n 'co.nz',\n 'co.th',\n 'co.uk',\n 'co.za',\n 'com.ar',\n 'com.au',\n 'com.br',\n 'com.cn',\n 'com.hk',\n 'com.in',\n 'com.jp',\n 'com.kr',\n 'com.mx',\n 'com.pl',\n 'com.sg',\n 'com.tr',\n 'com.tw',\n 'ed.jp',\n 'edu.au',\n 'edu.hk',\n 'edu.sg',\n 'edu.th',\n 'edu.tr',\n 'edu.tw',\n 'firebaseapp.com',\n 'gc.ca',\n 'geek.nz',\n 'github.io',\n 'gitlab.io',\n 'go.kr',\n 'go.th',\n 'gob.ar',\n 'gov.au',\n 'gov.hk',\n 'gov.in',\n 'gov.pl',\n 'gov.sg',\n 'gov.tr',\n 'gov.uk',\n 'gov.za',\n 'govt.nz',\n 'gr.jp',\n 'herokuapp.com',\n 'id.au',\n 'idv.hk',\n 'iwi.nz',\n 'lg.jp',\n 'ltd.uk',\n 'maori.nz',\n 'me.uk',\n 'mil.kr',\n 'ne.jp',\n 'ne.kr',\n 'net.au',\n 'net.br',\n 'net.cn',\n 'net.hk',\n 'net.in',\n 'net.nz',\n 'net.pl',\n 'net.sg',\n 'net.tr',\n 'net.tw',\n 'net.za',\n 'or.jp',\n 'or.kr',\n 'or.th',\n 'org.ar',\n 'org.au',\n 'org.br',\n 'org.cn',\n 'org.hk',\n 'org.in',\n 'org.nz',\n 'org.pl',\n 'org.sg',\n 'org.tw',\n 'org.uk',\n 'org.za',\n 'pe.kr',\n 'plc.uk',\n 're.kr',\n 'res.in',\n 'sch.uk',\n];\n\nexport const getDomain = (hostnameParam?: string) => {\n /* istanbul ignore next */\n const hostname = hostnameParam || getGlobalScope()?.location?.hostname;\n if (!hostname) {\n return '';\n }\n const parts = hostname.split('.');\n let tld = parts[parts.length - 1];\n let name = parts[parts.length - 2];\n if (KNOWN_2LDS.find((tld) => hostname.endsWith(`.${tld}`))) {\n tld = parts[parts.length - 2] + '.' + parts[parts.length - 1];\n name = parts[parts.length - 3];\n }\n\n if (!name) return tld;\n\n return `${name}.${tld}`;\n};\n\nconst isInternalReferrer = (referringDomain: string, topLevelDomain?: string) => {\n const globalScope = getGlobalScope();\n /* istanbul ignore if */\n if (!globalScope) return false;\n // if referring domain is subdomain of config.cookieDomain, return true\n const internalDomain = (topLevelDomain || '').trim() || getDomain(globalScope.location.hostname);\n return isSubdomainOf(referringDomain, internalDomain);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/attribution/helpers.ts"],"names":[],"mappings":";;;;AAAA,4DAOmC;AAEnC,kCAAkG;AAUlG,IAAM,sBAAsB,GAAG,UAAC,MAAc;IAC5C,IAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEhC,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE;QACrB,OAAO,MAAM,CAAC;KACf;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,kIAAkI;AAClI,IAAM,eAAe,GAAG,UAAC,OAAiB;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,UAAC,KAAK,IAAK,OAAA,CAAC,KAAK,EAAN,CAAM,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,IAAM,eAAe,GAAG,UAAC,QAAkB;IACzC,IAAM,uBAAuB,yCAAQ,QAAQ,KAAE,gBAAgB,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAE,CAAC;IAClG,OAAO,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,KAAK,CAAC,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GAAG,IAAA,+BAAc,GAAE,CAAC;IACrC,wBAAwB;IACxB,IAAI,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IAC/B,uEAAuE;IACvE,IAAM,cAAc,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,IAAA,iBAAS,EAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACjG,OAAO,IAAA,qBAAa,EAAC,eAAe,EAAE,cAAc,CAAC,CAAC;AACxD,CAAC,CAAC","sourcesContent":["import {\n createIdentifyEvent,\n Identify,\n ILogger,\n Campaign,\n BASE_CAMPAIGN,\n getGlobalScope,\n} from '@amplitude/analytics-core';\n\nimport { ExcludeInternalReferrersOptions, EXCLUDE_INTERNAL_REFERRERS_CONDITIONS } from '../types';\n\nexport interface Options {\n excludeReferrers?: (string | RegExp)[];\n excludeInternalReferrers?: true | false | ExcludeInternalReferrersOptions;\n initialEmptyValue?: string;\n resetSessionOnNewCampaign?: boolean;\n optOut?: boolean;\n}\n\nconst domainWithoutSubdomain = (domain: string) => {\n const parts = domain.split('.');\n\n if (parts.length <= 2) {\n return domain;\n }\n\n return parts.slice(parts.length - 2, parts.length).join('.');\n};\n\n//Direct traffic mean no external referral, no UTMs, no click-ids, and no other customer identified marketing campaign url params.\nconst isDirectTraffic = (current: Campaign) => {\n return Object.values(current).every((value) => !value);\n};\n\nconst isEmptyCampaign = (campaign: Campaign) => {\n const campaignWithoutReferrer = { ...campaign, referring_domain: undefined, referrer: undefined };\n return Object.values(campaignWithoutReferrer).every((value) => !value);\n};\n\nexport const isNewCampaign = (\n current: Campaign,\n previous: Campaign | undefined,\n options: Options,\n logger: ILogger,\n isNewSession = true,\n topLevelDomain?: string,\n) => {\n const { referrer, referring_domain, ...currentCampaign } = current;\n const { referrer: _previous_referrer, referring_domain: prevReferringDomain, ...previousCampaign } = previous || {};\n\n const { excludeInternalReferrers } = options;\n\n if (excludeInternalReferrers) {\n const condition = getExcludeInternalReferrersCondition(excludeInternalReferrers, logger);\n if (\n !(condition instanceof TypeError) &&\n current.referring_domain &&\n isInternalReferrer(current.referring_domain, topLevelDomain)\n ) {\n if (condition === 'always') {\n debugLogInternalReferrerExclude(condition, current.referring_domain, logger);\n return false;\n } else if (condition === 'ifEmptyCampaign' && isEmptyCampaign(current)) {\n debugLogInternalReferrerExclude(condition, current.referring_domain, logger);\n return false;\n }\n }\n }\n\n if (isExcludedReferrer(options.excludeReferrers, current.referring_domain)) {\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n logger.debug(`This is not a new campaign because ${current.referring_domain} is in the exclude referrer list.`);\n return false;\n }\n\n //In the same session, direct traffic should not override or unset any persisting query params\n if (!isNewSession && isDirectTraffic(current) && previous) {\n logger.debug('This is not a new campaign because this is a direct traffic in the same session.');\n return false;\n }\n\n const hasNewCampaign = JSON.stringify(currentCampaign) !== JSON.stringify(previousCampaign);\n const hasNewDomain =\n domainWithoutSubdomain(referring_domain || '') !== domainWithoutSubdomain(prevReferringDomain || '');\n\n const result = !previous || hasNewCampaign || hasNewDomain;\n\n if (!result) {\n logger.debug(\"This is not a new campaign because it's the same as the previous one.\");\n } else {\n logger.debug(`This is a new campaign. An $identify event will be sent.`);\n }\n\n return result;\n};\n\nexport const isExcludedReferrer = (excludeReferrers: (string | RegExp)[] = [], referringDomain = '') => {\n return excludeReferrers.some((value) =>\n value instanceof RegExp ? value.test(referringDomain) : value === referringDomain,\n );\n};\n\nexport const isSubdomainOf = (subDomain: string, domain: string) => {\n const cookieDomainWithLeadingDot = domain.startsWith('.') ? domain : `.${domain}`;\n const subDomainWithLeadingDot = subDomain.startsWith('.') ? subDomain : `.${subDomain}`;\n if (subDomainWithLeadingDot.endsWith(cookieDomainWithLeadingDot)) return true;\n return false;\n};\n\nexport const createCampaignEvent = (campaign: Campaign, options: Options) => {\n const campaignParameters: Campaign = {\n // This object definition allows undefined keys to be iterated on\n // in .reduce() to build indentify object\n ...BASE_CAMPAIGN,\n ...campaign,\n };\n const identifyEvent = Object.entries(campaignParameters).reduce((identify, [key, value]) => {\n identify.setOnce(`initial_${key}`, value ?? options.initialEmptyValue ?? 'EMPTY');\n if (value) {\n return identify.set(key, value);\n }\n return identify.unset(key);\n }, new Identify());\n\n return createIdentifyEvent(identifyEvent);\n};\n\nexport const getDefaultExcludedReferrers = (cookieDomain: string | undefined) => {\n let domain = cookieDomain;\n if (domain) {\n if (domain.startsWith('.')) {\n domain = domain.substring(1);\n }\n return [new RegExp(`${domain.replace('.', '\\\\.')}$`)];\n }\n return [];\n};\n\n/**\n * Parses the excludeInternalReferrers configuration to determine the condition on which to\n * exclude internal referrers for campaign attribution.\n *\n * If the config is invalid type, log and return a TypeError.\n *\n * (this does explicit type checking so don't have to rely on TS compiler to catch invalid types)\n *\n * @param excludeInternalReferrers - attribution.excludeInternalReferrers configuration\n * @param logger - logger instance to log error when TypeError\n * @returns The condition if the config is valid, TypeError if the config is invalid.\n */\nconst getExcludeInternalReferrersCondition = (\n excludeInternalReferrers: ExcludeInternalReferrersOptions | boolean,\n logger: ILogger,\n): ExcludeInternalReferrersOptions['condition'] | TypeError => {\n if (excludeInternalReferrers === true) {\n return EXCLUDE_INTERNAL_REFERRERS_CONDITIONS.always;\n }\n if (typeof excludeInternalReferrers === 'object') {\n const { condition } = excludeInternalReferrers;\n if (typeof condition === 'string' && Object.keys(EXCLUDE_INTERNAL_REFERRERS_CONDITIONS).includes(condition)) {\n return condition;\n } else if (typeof condition === 'undefined') {\n return EXCLUDE_INTERNAL_REFERRERS_CONDITIONS.always;\n }\n }\n const errorMessage = `Invalid configuration provided for attribution.excludeInternalReferrers: ${JSON.stringify(\n excludeInternalReferrers,\n )}`;\n logger.error(errorMessage);\n return new TypeError(errorMessage);\n};\n\n// helper function to log debug message when internal referrer is excluded\n// (added this to prevent code duplication and improve readability)\nfunction debugLogInternalReferrerExclude(\n condition: ExcludeInternalReferrersOptions['condition'],\n referringDomain: string,\n logger: ILogger,\n) {\n const baseMessage = `This is not a new campaign because referring_domain=${referringDomain} is on the same domain as the current page and it is configured to exclude internal referrers`;\n if (condition === 'always') {\n logger.debug(baseMessage);\n } else if (condition === 'ifEmptyCampaign') {\n logger.debug(`${baseMessage} with empty campaign parameters`);\n }\n}\n\n// list of domains that are known ccTLDs that are commonly used\n// and are in the Public Suffix List (https://publicsuffix.org/)\nexport const KNOWN_2LDS = [\n 'ac.in',\n 'ac.jp',\n 'ac.kr',\n 'ac.th',\n 'ac.uk',\n 'ac.za',\n 'appspot.com',\n 'asn.au',\n 'azurewebsites.net',\n 'cloudfront.net',\n 'myshopify.com',\n 'blogspot.com',\n 'co.ca',\n 'co.in',\n 'co.jp',\n 'co.kr',\n 'co.nz',\n 'co.th',\n 'co.uk',\n 'co.za',\n 'com.ar',\n 'com.au',\n 'com.br',\n 'com.cn',\n 'com.hk',\n 'com.in',\n 'com.jp',\n 'com.kr',\n 'com.mx',\n 'com.pl',\n 'com.sg',\n 'com.tr',\n 'com.tw',\n 'ed.jp',\n 'edu.au',\n 'edu.br',\n 'edu.cn',\n 'edu.hk',\n 'edu.sg',\n 'edu.th',\n 'edu.tr',\n 'edu.tw',\n 'firebaseapp.com',\n 'fly.dev',\n 'gc.ca',\n 'geek.nz',\n 'github.io',\n 'gitlab.io',\n 'go.jp',\n 'go.kr',\n 'go.th',\n 'gob.ar',\n 'gob.mx',\n 'gov.au',\n 'gov.br',\n 'gov.cn',\n 'gov.hk',\n 'gov.in',\n 'gov.pl',\n 'gov.sg',\n 'gov.tr',\n 'gov.tw',\n 'gov.uk',\n 'gov.za',\n 'govt.nz',\n 'gr.jp',\n 'herokuapp.com',\n 'id.au',\n 'idv.hk',\n 'iwi.nz',\n 'lg.jp',\n 'ltd.uk',\n 'maori.nz',\n 'me.uk',\n 'mil.kr',\n 'ne.jp',\n 'ne.kr',\n 'net.au',\n 'net.br',\n 'net.cn',\n 'net.hk',\n 'net.in',\n 'net.nz',\n 'net.pl',\n 'net.sg',\n 'net.tr',\n 'net.tw',\n 'net.za',\n 'onrender.com',\n 'or.jp',\n 'or.kr',\n 'or.th',\n 'org.ar',\n 'org.au',\n 'org.br',\n 'org.cn',\n 'org.hk',\n 'org.in',\n 'org.mx',\n 'org.nz',\n 'org.pl',\n 'org.sg',\n 'org.tw',\n 'org.uk',\n 'org.za',\n 'pages.dev',\n 'pe.kr',\n 'plc.uk',\n 're.kr',\n 'res.in',\n 'sch.uk',\n 'vercel.app',\n 'netlify.app',\n 'workers.dev',\n];\n\nexport const getDomain = (hostnameParam?: string) => {\n /* istanbul ignore next */\n const hostname = hostnameParam || getGlobalScope()?.location?.hostname;\n if (!hostname) {\n return '';\n }\n const parts = hostname.split('.');\n let tld = parts[parts.length - 1];\n let name = parts[parts.length - 2];\n if (KNOWN_2LDS.find((tld) => hostname.endsWith(`.${tld}`))) {\n tld = parts[parts.length - 2] + '.' + parts[parts.length - 1];\n name = parts[parts.length - 3];\n }\n\n if (!name) return tld;\n\n return `${name}.${tld}`;\n};\n\nconst isInternalReferrer = (referringDomain: string, topLevelDomain?: string) => {\n const globalScope = getGlobalScope();\n /* istanbul ignore if */\n if (!globalScope) return false;\n // if referring domain is subdomain of config.cookieDomain, return true\n const internalDomain = (topLevelDomain || '').trim() || getDomain(globalScope.location.hostname);\n return isSubdomainOf(referringDomain, internalDomain);\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-client.d.ts","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAYb,KAAK,EACL,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,sBAAsB,EAEtB,MAAM,EACN,cAAc,EACd,aAAa,EACb,aAAa,EACb,eAAe,EACf,iBAAiB,
|
|
1
|
+
{"version":3,"file":"browser-client.d.ts","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAYb,KAAK,EACL,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,sBAAsB,E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EAAE,YAAY;IAStD,OAAO,CAAC,0BAA0B;IAe5B,OAAO,CAAC,KAAK,EAAE,KAAK;IA0B1B,OAAO,CAAC,iBAAiB;IAgBzB;;;;;;;OAOG;IACH,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAWnD;;;;OAIG;IACH,yCAAyC,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;CAOlE"}
|
|
@@ -59,12 +59,12 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
59
59
|
return (0, analytics_core_1.returnWrapper)(this._init(tslib_1.__assign(tslib_1.__assign({}, options), { userId: userId, apiKey: apiKey })));
|
|
60
60
|
};
|
|
61
61
|
AmplitudeBrowser.prototype._init = function (options) {
|
|
62
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
63
63
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
64
64
|
var fetchRemoteConfig, loggerProvider, serverZone, remoteConfigClient, diagnosticsSampleRate, enableDiagnostics, diagnosticsClient, browserOptions, attributionTrackingOptions, queryParams, ampTimestamp, isWithinTimeLimit, querySessionId, deferredSessionId, connector;
|
|
65
65
|
var _this = this;
|
|
66
|
-
return tslib_1.__generator(this, function (
|
|
67
|
-
switch (
|
|
66
|
+
return tslib_1.__generator(this, function (_j) {
|
|
67
|
+
switch (_j.label) {
|
|
68
68
|
case 0:
|
|
69
69
|
// Step 1: Block concurrent initialization
|
|
70
70
|
if (this.initializing) {
|
|
@@ -73,12 +73,15 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
73
73
|
this.initializing = true;
|
|
74
74
|
fetchRemoteConfig = (0, config_1.shouldFetchRemoteConfig)(options);
|
|
75
75
|
loggerProvider = (_a = options.loggerProvider) !== null && _a !== void 0 ? _a : new analytics_core_1.Logger();
|
|
76
|
-
|
|
76
|
+
if (!options.loggerProvider) {
|
|
77
|
+
loggerProvider.enable((_b = options.logLevel) !== null && _b !== void 0 ? _b : analytics_core_1.LogLevel.Warn);
|
|
78
|
+
}
|
|
79
|
+
serverZone = (_c = options.serverZone) !== null && _c !== void 0 ? _c : constants_1.DEFAULT_SERVER_ZONE;
|
|
77
80
|
diagnosticsSampleRate = this._diagnosticsSampleRate;
|
|
78
|
-
enableDiagnostics = (
|
|
81
|
+
enableDiagnostics = (_d = options.enableDiagnostics) !== null && _d !== void 0 ? _d : true;
|
|
79
82
|
if (!fetchRemoteConfig) return [3 /*break*/, 2];
|
|
80
83
|
remoteConfigClient = new analytics_core_1.RemoteConfigClient(options.apiKey, loggerProvider, serverZone,
|
|
81
|
-
/* istanbul ignore next */ (
|
|
84
|
+
/* istanbul ignore next */ (_e = options.remoteConfig) === null || _e === void 0 ? void 0 : _e.serverUrl);
|
|
82
85
|
// Fetch diagnostics config first to get sample rate
|
|
83
86
|
return [4 /*yield*/, new Promise(function (resolve) {
|
|
84
87
|
// Disable coverage for this line because remote config client will always be defined in this case.
|
|
@@ -106,8 +109,8 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
106
109
|
})];
|
|
107
110
|
case 1:
|
|
108
111
|
// Fetch diagnostics config first to get sample rate
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
_j.sent();
|
|
113
|
+
_j.label = 2;
|
|
111
114
|
case 2:
|
|
112
115
|
diagnosticsClient = new analytics_core_1.DiagnosticsClient(options.apiKey, loggerProvider, serverZone, {
|
|
113
116
|
enabled: enableDiagnostics,
|
|
@@ -124,7 +127,7 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
124
127
|
diagnosticsSampleRate: diagnosticsSampleRate,
|
|
125
128
|
})];
|
|
126
129
|
case 3:
|
|
127
|
-
browserOptions =
|
|
130
|
+
browserOptions = _j.sent();
|
|
128
131
|
if (!(fetchRemoteConfig && remoteConfigClient)) return [3 /*break*/, 5];
|
|
129
132
|
return [4 /*yield*/, new Promise(function (resolve) {
|
|
130
133
|
// Disable coverage for this line because remote config client will always be defined in this case.
|
|
@@ -143,11 +146,11 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
143
146
|
});
|
|
144
147
|
})];
|
|
145
148
|
case 4:
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
_j.sent();
|
|
150
|
+
_j.label = 5;
|
|
148
151
|
case 5: return [4 /*yield*/, _super.prototype._init.call(this, browserOptions)];
|
|
149
152
|
case 6:
|
|
150
|
-
|
|
153
|
+
_j.sent();
|
|
151
154
|
this.logBrowserOptions(browserOptions);
|
|
152
155
|
this.config.remoteConfigClient = remoteConfigClient;
|
|
153
156
|
if (!(0, default_tracking_1.isAttributionTrackingEnabled)(this.config.defaultTracking)) return [3 /*break*/, 8];
|
|
@@ -175,8 +178,8 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
175
178
|
return [4 /*yield*/, this.webAttribution.init()];
|
|
176
179
|
case 7:
|
|
177
180
|
// Fetch the current campaign, check if need to track web attribution later
|
|
178
|
-
|
|
179
|
-
|
|
181
|
+
_j.sent();
|
|
182
|
+
_j.label = 8;
|
|
180
183
|
case 8:
|
|
181
184
|
queryParams = (0, analytics_core_1.getQueryParams)();
|
|
182
185
|
ampTimestamp = queryParams.ampTimestamp ? Number(queryParams.ampTimestamp) : undefined;
|
|
@@ -188,7 +191,7 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
188
191
|
if (deferredSessionId === UNSPECIFIED_SESSION_ID && !this.config.optOut) {
|
|
189
192
|
deferredSessionId = Date.now();
|
|
190
193
|
}
|
|
191
|
-
this.setSessionId((
|
|
194
|
+
this.setSessionId((_h = (_g = (_f = options.sessionId) !== null && _f !== void 0 ? _f : querySessionId) !== null && _g !== void 0 ? _g : deferredSessionId) !== null && _h !== void 0 ? _h : this.config.sessionId);
|
|
192
195
|
if (this.config.optOut) {
|
|
193
196
|
this.timeline.addOptOutListener(function (optOut) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
194
197
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -212,39 +215,39 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
212
215
|
if (!(this.config.offline !== analytics_core_1.OfflineDisabled)) return [3 /*break*/, 10];
|
|
213
216
|
return [4 /*yield*/, this.add((0, network_connectivity_checker_1.networkConnectivityCheckerPlugin)()).promise];
|
|
214
217
|
case 9:
|
|
215
|
-
|
|
216
|
-
|
|
218
|
+
_j.sent();
|
|
219
|
+
_j.label = 10;
|
|
217
220
|
case 10: return [4 /*yield*/, this.add(new analytics_core_1.Destination({ diagnosticsClient: diagnosticsClient })).promise];
|
|
218
221
|
case 11:
|
|
219
|
-
|
|
222
|
+
_j.sent();
|
|
220
223
|
return [4 /*yield*/, this.add(new context_1.Context()).promise];
|
|
221
224
|
case 12:
|
|
222
|
-
|
|
225
|
+
_j.sent();
|
|
223
226
|
return [4 /*yield*/, this.add(new analytics_core_1.IdentityEventSender()).promise];
|
|
224
227
|
case 13:
|
|
225
|
-
|
|
228
|
+
_j.sent();
|
|
226
229
|
// Notify if DET is enabled
|
|
227
230
|
(0, det_notification_1.detNotify)(this.config);
|
|
228
231
|
if (!(0, default_tracking_1.isFileDownloadTrackingEnabled)(this.config.defaultTracking)) return [3 /*break*/, 15];
|
|
229
232
|
this.config.loggerProvider.debug('Adding file download tracking plugin');
|
|
230
233
|
return [4 /*yield*/, this.add((0, file_download_tracking_1.fileDownloadTracking)()).promise];
|
|
231
234
|
case 14:
|
|
232
|
-
|
|
233
|
-
|
|
235
|
+
_j.sent();
|
|
236
|
+
_j.label = 15;
|
|
234
237
|
case 15:
|
|
235
238
|
if (!(0, default_tracking_1.isFormInteractionTrackingEnabled)(this.config.defaultTracking)) return [3 /*break*/, 17];
|
|
236
239
|
this.config.loggerProvider.debug('Adding form interaction plugin');
|
|
237
240
|
return [4 /*yield*/, this.add((0, form_interaction_tracking_1.formInteractionTracking)()).promise];
|
|
238
241
|
case 16:
|
|
239
|
-
|
|
240
|
-
|
|
242
|
+
_j.sent();
|
|
243
|
+
_j.label = 17;
|
|
241
244
|
case 17:
|
|
242
245
|
if (!(0, default_tracking_1.isPageViewTrackingEnabled)(this.config.defaultTracking)) return [3 /*break*/, 20];
|
|
243
246
|
if (!!this.config.optOut) return [3 /*break*/, 19];
|
|
244
247
|
this.config.loggerProvider.debug('Adding page view tracking plugin');
|
|
245
248
|
return [4 /*yield*/, this.add((0, plugin_page_view_tracking_browser_1.pageViewTrackingPlugin)((0, default_tracking_1.getPageViewTrackingConfig)(this.config))).promise];
|
|
246
249
|
case 18:
|
|
247
|
-
|
|
250
|
+
_j.sent();
|
|
248
251
|
return [3 /*break*/, 20];
|
|
249
252
|
case 19:
|
|
250
253
|
this.timeline.addOptOutListener(function (optOut) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
@@ -263,49 +266,49 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
263
266
|
}
|
|
264
267
|
});
|
|
265
268
|
}); });
|
|
266
|
-
|
|
269
|
+
_j.label = 20;
|
|
267
270
|
case 20:
|
|
268
271
|
if (!(0, default_tracking_1.isElementInteractionsEnabled)(this.config.autocapture)) return [3 /*break*/, 22];
|
|
269
272
|
this.config.loggerProvider.debug('Adding user interactions plugin (autocapture plugin)');
|
|
270
273
|
return [4 /*yield*/, this.add((0, plugin_autocapture_browser_1.autocapturePlugin)((0, default_tracking_1.getElementInteractionsConfig)(this.config), { diagnosticsClient: diagnosticsClient })).promise];
|
|
271
274
|
case 21:
|
|
272
|
-
|
|
273
|
-
|
|
275
|
+
_j.sent();
|
|
276
|
+
_j.label = 22;
|
|
274
277
|
case 22:
|
|
275
278
|
if (!(0, default_tracking_1.isFrustrationInteractionsEnabled)(this.config.autocapture)) return [3 /*break*/, 24];
|
|
276
279
|
this.config.loggerProvider.debug('Adding frustration interactions plugin');
|
|
277
280
|
return [4 /*yield*/, this.add((0, plugin_autocapture_browser_1.frustrationPlugin)((0, default_tracking_1.getFrustrationInteractionsConfig)(this.config))).promise];
|
|
278
281
|
case 23:
|
|
279
|
-
|
|
280
|
-
|
|
282
|
+
_j.sent();
|
|
283
|
+
_j.label = 24;
|
|
281
284
|
case 24:
|
|
282
285
|
if (!(0, default_tracking_1.isNetworkTrackingEnabled)(this.config.autocapture)) return [3 /*break*/, 26];
|
|
283
286
|
this.config.loggerProvider.debug('Adding network tracking plugin');
|
|
284
287
|
return [4 /*yield*/, this.add((0, plugin_network_capture_browser_1.plugin)((0, default_tracking_1.getNetworkTrackingConfig)(this.config))).promise];
|
|
285
288
|
case 25:
|
|
286
|
-
|
|
287
|
-
|
|
289
|
+
_j.sent();
|
|
290
|
+
_j.label = 26;
|
|
288
291
|
case 26:
|
|
289
292
|
if (!(0, default_tracking_1.isWebVitalsEnabled)(this.config.autocapture)) return [3 /*break*/, 28];
|
|
290
293
|
this.config.loggerProvider.debug('Adding web vitals plugin');
|
|
291
294
|
return [4 /*yield*/, this.add((0, plugin_web_vitals_browser_1.webVitalsPlugin)()).promise];
|
|
292
295
|
case 27:
|
|
293
|
-
|
|
294
|
-
|
|
296
|
+
_j.sent();
|
|
297
|
+
_j.label = 28;
|
|
295
298
|
case 28:
|
|
296
299
|
if (!(0, default_tracking_1.isPageUrlEnrichmentEnabled)(this.config.autocapture)) return [3 /*break*/, 30];
|
|
297
300
|
this.config.loggerProvider.debug('Adding referrer page url plugin');
|
|
298
301
|
return [4 /*yield*/, this.add((0, plugin_page_url_enrichment_browser_1.pageUrlEnrichmentPlugin)()).promise];
|
|
299
302
|
case 29:
|
|
300
|
-
|
|
301
|
-
|
|
303
|
+
_j.sent();
|
|
304
|
+
_j.label = 30;
|
|
302
305
|
case 30:
|
|
303
306
|
this.initializing = false;
|
|
304
307
|
// Step 6: Run queued dispatch functions
|
|
305
308
|
return [4 /*yield*/, this.runQueuedFunctions('dispatchQ')];
|
|
306
309
|
case 31:
|
|
307
310
|
// Step 6: Run queued dispatch functions
|
|
308
|
-
|
|
311
|
+
_j.sent();
|
|
309
312
|
// Step 7: Add the event receiver after running remaining queued functions.
|
|
310
313
|
connector.eventBridge.setEventReceiver(function (event) {
|
|
311
314
|
var _a = event.eventProperties || {}, time = _a.time, cleanEventProperties = tslib_1.__rest(_a, ["time"]);
|