@amplitude/analytics-browser 2.49.0-video-analytics-8.0 → 2.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/cjs/browser-client-lite-factory.d.ts +5 -0
- package/lib/cjs/browser-client-lite-factory.d.ts.map +1 -0
- package/lib/cjs/browser-client-lite-factory.js +37 -0
- package/lib/cjs/browser-client-lite-factory.js.map +1 -0
- package/lib/cjs/browser-client-lite.d.ts +68 -0
- package/lib/cjs/browser-client-lite.d.ts.map +1 -0
- package/lib/cjs/browser-client-lite.js +441 -0
- package/lib/cjs/browser-client-lite.js.map +1 -0
- package/lib/cjs/browser-client.d.ts +10 -40
- package/lib/cjs/browser-client.d.ts.map +1 -1
- package/lib/cjs/browser-client.js +244 -575
- package/lib/cjs/browser-client.js.map +1 -1
- package/lib/cjs/config.d.ts +4 -11
- package/lib/cjs/config.d.ts.map +1 -1
- package/lib/cjs/config.js +3 -29
- package/lib/cjs/config.js.map +1 -1
- package/lib/cjs/constants.d.ts +0 -2
- package/lib/cjs/constants.d.ts.map +1 -1
- package/lib/cjs/constants.js +1 -3
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/default-tracking.d.ts.map +1 -1
- package/lib/cjs/default-tracking.js +6 -6
- package/lib/cjs/default-tracking.js.map +1 -1
- package/lib/cjs/index-lite.d.ts +10 -0
- package/lib/cjs/index-lite.d.ts.map +1 -0
- package/lib/cjs/index-lite.js +21 -0
- package/lib/cjs/index-lite.js.map +1 -0
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +1 -1
- package/lib/cjs/types.d.ts.map +1 -1
- package/lib/cjs/types.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/cjs/video-capture/video-capture.d.ts +11 -48
- package/lib/cjs/video-capture/video-capture.d.ts.map +1 -1
- package/lib/cjs/video-capture/video-capture.js +16 -194
- package/lib/cjs/video-capture/video-capture.js.map +1 -1
- package/lib/esm/browser-client-lite-factory.d.ts +5 -0
- package/lib/esm/browser-client-lite-factory.d.ts.map +1 -0
- package/lib/esm/browser-client-lite-factory.js +33 -0
- package/lib/esm/browser-client-lite-factory.js.map +1 -0
- package/lib/esm/browser-client-lite.d.ts +68 -0
- package/lib/esm/browser-client-lite.d.ts.map +1 -0
- package/lib/esm/browser-client-lite.js +438 -0
- package/lib/esm/browser-client-lite.js.map +1 -0
- package/lib/esm/browser-client.d.ts +10 -40
- package/lib/esm/browser-client.d.ts.map +1 -1
- package/lib/esm/browser-client.js +248 -579
- package/lib/esm/browser-client.js.map +1 -1
- package/lib/esm/config.d.ts +4 -11
- package/lib/esm/config.d.ts.map +1 -1
- package/lib/esm/config.js +2 -27
- package/lib/esm/config.js.map +1 -1
- package/lib/esm/constants.d.ts +0 -2
- package/lib/esm/constants.d.ts.map +1 -1
- package/lib/esm/constants.js +0 -2
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/default-tracking.d.ts.map +1 -1
- package/lib/esm/default-tracking.js +6 -6
- package/lib/esm/default-tracking.js.map +1 -1
- package/lib/esm/index-lite.d.ts +10 -0
- package/lib/esm/index-lite.d.ts.map +1 -0
- package/lib/esm/index-lite.js +10 -0
- package/lib/esm/index-lite.js.map +1 -0
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +1 -1
- package/lib/esm/types.d.ts.map +1 -1
- package/lib/esm/types.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/esm/video-capture/video-capture.d.ts +11 -48
- package/lib/esm/video-capture/video-capture.d.ts.map +1 -1
- package/lib/esm/video-capture/video-capture.js +18 -196
- package/lib/esm/video-capture/video-capture.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/browser-client-lite-factory.d.ts +5 -0
- package/lib/scripts/browser-client-lite-factory.d.ts.map +1 -0
- package/lib/scripts/browser-client-lite.d.ts +68 -0
- package/lib/scripts/browser-client-lite.d.ts.map +1 -0
- package/lib/scripts/browser-client.d.ts +10 -40
- package/lib/scripts/browser-client.d.ts.map +1 -1
- package/lib/scripts/config.d.ts +4 -11
- package/lib/scripts/config.d.ts.map +1 -1
- package/lib/scripts/constants.d.ts +0 -2
- package/lib/scripts/constants.d.ts.map +1 -1
- package/lib/scripts/default-tracking.d.ts.map +1 -1
- package/lib/scripts/index-lite.d.ts +10 -0
- package/lib/scripts/index-lite.d.ts.map +1 -0
- package/lib/scripts/index.d.ts +1 -1
- package/lib/scripts/index.d.ts.map +1 -1
- package/lib/scripts/types.d.ts +1 -1
- package/lib/scripts/types.d.ts.map +1 -1
- package/lib/scripts/version.d.ts +1 -1
- package/lib/scripts/version.d.ts.map +1 -1
- package/lib/scripts/video-capture/video-capture.d.ts +11 -48
- package/lib/scripts/video-capture/video-capture.d.ts.map +1 -1
- package/package.json +29 -8
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';
|
|
1
|
+
import { __awaiter, __extends, __generator } from "tslib";
|
|
2
|
+
import { RemoteConfigClient, DiagnosticsClient, safeJsonStringify, } from '@amplitude/analytics-core';
|
|
3
|
+
import { getPageViewTrackingConfig, getElementInteractionsConfig, getNetworkTrackingConfig, isAttributionTrackingEnabled, isFileDownloadTrackingEnabled, isFormInteractionTrackingEnabled, isElementInteractionsEnabled, isPageViewTrackingEnabled, isNetworkTrackingEnabled, isWebVitalsEnabled, getWebVitalsConfig, isFrustrationInteractionsEnabled, getFrustrationInteractionsConfig, isPerformanceTrackingEnabled, getPerformanceTrackingConfig, isPageUrlEnrichmentEnabled, isCustomEnrichmentEnabled, } from './default-tracking';
|
|
5
4
|
import { getRuntimeEnvironment } from './utils/environment';
|
|
6
|
-
import { BROWSER_PLATFORM
|
|
7
|
-
import { useBrowserConfig, createTransport, shouldFetchRemoteConfig } from './config';
|
|
5
|
+
import { BROWSER_PLATFORM } from './plugins/context';
|
|
8
6
|
import { pageViewTrackingPlugin } from '@amplitude/plugin-page-view-tracking-browser';
|
|
9
7
|
import { formInteractionTracking } from './plugins/form-interaction-tracking';
|
|
10
8
|
import { fileDownloadTracking } from './plugins/file-download-tracking';
|
|
11
|
-
import { DEFAULT_SESSION_END_EVENT, DEFAULT_SESSION_START_EVENT, DEFAULT_SERVER_ZONE } from './constants';
|
|
12
|
-
import { detNotify } from './det-notification';
|
|
13
|
-
import { networkConnectivityCheckerPlugin } from './plugins/network-connectivity-checker';
|
|
14
9
|
import { updateBrowserConfigWithRemoteConfig } from './config/joined-config';
|
|
15
10
|
import { autocapturePlugin, frustrationPlugin, performancePlugin } from '@amplitude/plugin-autocapture-browser';
|
|
16
11
|
import { plugin as networkCapturePlugin } from '@amplitude/plugin-network-capture-browser';
|
|
@@ -22,118 +17,257 @@ import { VERSION } from './version';
|
|
|
22
17
|
import { pageUrlEnrichmentPlugin } from '@amplitude/plugin-page-url-enrichment-browser';
|
|
23
18
|
import { customEnrichmentPlugin } from '@amplitude/plugin-custom-enrichment-browser';
|
|
24
19
|
import { isEventPropertyAttributionEnabled, isUserPropertyAttributionEnabled } from './attribution/tracking-methods';
|
|
25
|
-
|
|
20
|
+
import { AmplitudeBrowserLite } from './browser-client-lite';
|
|
26
21
|
/**
|
|
27
22
|
* Exported for `@amplitude/unified` or integration with blade plugins.
|
|
28
23
|
* If you only use `@amplitude/analytics-browser`, use `amplitude.init()` or `amplitude.createInstance()` instead.
|
|
29
24
|
*/
|
|
30
25
|
var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
31
26
|
__extends(AmplitudeBrowser, _super);
|
|
27
|
+
// The ES5 helper for a class that extends another derived class includes an
|
|
28
|
+
// unreachable `|| this` branch. Ignore that generated constructor.
|
|
29
|
+
/* istanbul ignore next */
|
|
32
30
|
function AmplitudeBrowser() {
|
|
33
|
-
var _this = _super
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
_this.
|
|
31
|
+
var _this = _super.call(this) || this;
|
|
32
|
+
_this.diagnosticsSampleRate = 0;
|
|
33
|
+
_this.enableDiagnostics = true;
|
|
34
|
+
_this._autocaptureAdapter = null;
|
|
37
35
|
return _this;
|
|
38
36
|
}
|
|
39
|
-
AmplitudeBrowser.prototype.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (arguments.length > 2) {
|
|
44
|
-
userId = userIdOrOptions;
|
|
45
|
-
options = maybeOptions;
|
|
37
|
+
AmplitudeBrowser.prototype.autocaptureAdapter = function () {
|
|
38
|
+
var _this = this;
|
|
39
|
+
if (this._autocaptureAdapter) {
|
|
40
|
+
return this._autocaptureAdapter;
|
|
46
41
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
remoteConfig: remoteConfig,
|
|
90
|
-
source: source,
|
|
91
|
-
lastFetch: lastFetch,
|
|
92
|
-
}, null, 2));
|
|
93
|
-
if (remoteConfig) {
|
|
94
|
-
// Validate and set sampleRate (must be a valid number)
|
|
95
|
-
var sampleRate = remoteConfig.sampleRate;
|
|
96
|
-
if (typeof sampleRate === 'number' && !isNaN(sampleRate)) {
|
|
97
|
-
diagnosticsSampleRate = sampleRate;
|
|
98
|
-
}
|
|
99
|
-
// Validate and set enabled (must be a boolean)
|
|
100
|
-
var enabled = remoteConfig.enabled;
|
|
101
|
-
if (typeof enabled === 'boolean') {
|
|
102
|
-
enableDiagnostics = enabled;
|
|
103
|
-
}
|
|
42
|
+
this._autocaptureAdapter = {
|
|
43
|
+
addPlugins: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
44
|
+
var opts;
|
|
45
|
+
var _this = this;
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
switch (_a.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
if (!isFileDownloadTrackingEnabled(this.config.defaultTracking)) return [3 /*break*/, 2];
|
|
50
|
+
this.config.loggerProvider.debug('Adding file download tracking plugin');
|
|
51
|
+
return [4 /*yield*/, this.add(fileDownloadTracking()).promise];
|
|
52
|
+
case 1:
|
|
53
|
+
_a.sent();
|
|
54
|
+
_a.label = 2;
|
|
55
|
+
case 2:
|
|
56
|
+
if (!isFormInteractionTrackingEnabled(this.config.defaultTracking)) return [3 /*break*/, 4];
|
|
57
|
+
this.config.loggerProvider.debug('Adding form interaction plugin');
|
|
58
|
+
return [4 /*yield*/, this.add(formInteractionTracking()).promise];
|
|
59
|
+
case 3:
|
|
60
|
+
_a.sent();
|
|
61
|
+
_a.label = 4;
|
|
62
|
+
case 4:
|
|
63
|
+
if (!isPageViewTrackingEnabled(this.config.defaultTracking)) return [3 /*break*/, 7];
|
|
64
|
+
if (!!this.config.optOut) return [3 /*break*/, 6];
|
|
65
|
+
this.config.loggerProvider.debug('Adding page view tracking plugin');
|
|
66
|
+
return [4 /*yield*/, this.add(pageViewTrackingPlugin(getPageViewTrackingConfig(this.config))).promise];
|
|
67
|
+
case 5:
|
|
68
|
+
_a.sent();
|
|
69
|
+
return [3 /*break*/, 7];
|
|
70
|
+
case 6:
|
|
71
|
+
this.timeline.addOptOutListener(function (optOut) { return __awaiter(_this, void 0, void 0, function () {
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
switch (_a.label) {
|
|
74
|
+
case 0:
|
|
75
|
+
/* istanbul ignore if */
|
|
76
|
+
if (optOut) {
|
|
77
|
+
return [2 /*return*/];
|
|
78
|
+
}
|
|
79
|
+
this.config.loggerProvider.debug('Adding page view tracking plugin');
|
|
80
|
+
return [4 /*yield*/, this.add(pageViewTrackingPlugin(getPageViewTrackingConfig(this.config))).promise];
|
|
81
|
+
case 1:
|
|
82
|
+
_a.sent();
|
|
83
|
+
return [2 /*return*/];
|
|
104
84
|
}
|
|
105
|
-
resolve();
|
|
106
85
|
});
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
diagnosticsClient.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
86
|
+
}); });
|
|
87
|
+
_a.label = 7;
|
|
88
|
+
case 7:
|
|
89
|
+
if (!(this.attributionTrackingOptions &&
|
|
90
|
+
isAttributionTrackingEnabled(this.config.defaultTracking) &&
|
|
91
|
+
isEventPropertyAttributionEnabled(this.attributionTrackingOptions))) return [3 /*break*/, 9];
|
|
92
|
+
this.config.loggerProvider.debug('Adding event property attribution plugin');
|
|
93
|
+
return [4 /*yield*/, this.add(eventPropertyTrackingPlugin(this.attributionTrackingOptions)).promise];
|
|
94
|
+
case 8:
|
|
95
|
+
_a.sent();
|
|
96
|
+
_a.label = 9;
|
|
97
|
+
case 9:
|
|
98
|
+
if (!isElementInteractionsEnabled(this.config.autocapture)) return [3 /*break*/, 11];
|
|
99
|
+
this.config.loggerProvider.debug('Adding user interactions plugin (autocapture plugin)');
|
|
100
|
+
opts = this.diagnosticsClient ? { diagnosticsClient: this.diagnosticsClient } : undefined;
|
|
101
|
+
return [4 /*yield*/, this.add(autocapturePlugin(getElementInteractionsConfig(this.config), opts)).promise];
|
|
102
|
+
case 10:
|
|
103
|
+
_a.sent();
|
|
104
|
+
_a.label = 11;
|
|
105
|
+
case 11:
|
|
106
|
+
if (!isFrustrationInteractionsEnabled(this.config.autocapture)) return [3 /*break*/, 13];
|
|
107
|
+
this.config.loggerProvider.debug('Adding frustration interactions plugin');
|
|
108
|
+
return [4 /*yield*/, this.add(frustrationPlugin(getFrustrationInteractionsConfig(this.config))).promise];
|
|
109
|
+
case 12:
|
|
110
|
+
_a.sent();
|
|
111
|
+
_a.label = 13;
|
|
112
|
+
case 13:
|
|
113
|
+
if (!isNetworkTrackingEnabled(this.config.autocapture)) return [3 /*break*/, 15];
|
|
114
|
+
this.config.loggerProvider.debug('Adding network tracking plugin');
|
|
115
|
+
return [4 /*yield*/, this.add(networkCapturePlugin(getNetworkTrackingConfig(this.config))).promise];
|
|
116
|
+
case 14:
|
|
117
|
+
_a.sent();
|
|
118
|
+
_a.label = 15;
|
|
119
|
+
case 15:
|
|
120
|
+
if (!isWebVitalsEnabled(this.config.autocapture)) return [3 /*break*/, 17];
|
|
121
|
+
this.config.loggerProvider.debug('Adding web vitals plugin');
|
|
122
|
+
return [4 /*yield*/, this.add(webVitalsPlugin(getWebVitalsConfig(this.config))).promise];
|
|
123
|
+
case 16:
|
|
124
|
+
_a.sent();
|
|
125
|
+
_a.label = 17;
|
|
126
|
+
case 17:
|
|
127
|
+
if (!isPerformanceTrackingEnabled(this.config.autocapture)) return [3 /*break*/, 19];
|
|
128
|
+
this.config.loggerProvider.debug('Adding performance tracking plugin');
|
|
129
|
+
return [4 /*yield*/, this.add(performancePlugin(getPerformanceTrackingConfig(this.config))).promise];
|
|
130
|
+
case 18:
|
|
131
|
+
_a.sent();
|
|
132
|
+
_a.label = 19;
|
|
133
|
+
case 19:
|
|
134
|
+
if (!isPageUrlEnrichmentEnabled(this.config.autocapture)) return [3 /*break*/, 21];
|
|
135
|
+
this.config.loggerProvider.debug('Adding referrer page url plugin');
|
|
136
|
+
return [4 /*yield*/, this.add(pageUrlEnrichmentPlugin()).promise];
|
|
137
|
+
case 20:
|
|
138
|
+
_a.sent();
|
|
139
|
+
_a.label = 21;
|
|
140
|
+
case 21:
|
|
141
|
+
if (!isCustomEnrichmentEnabled(this.config.customEnrichment)) return [3 /*break*/, 23];
|
|
142
|
+
this.config.loggerProvider.debug('Adding custom enrichment plugin');
|
|
143
|
+
return [4 /*yield*/, this.add(customEnrichmentPlugin()).promise];
|
|
144
|
+
case 22:
|
|
145
|
+
_a.sent();
|
|
146
|
+
_a.label = 23;
|
|
147
|
+
case 23: return [2 /*return*/];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}); },
|
|
151
|
+
trackCampaignEventIfNeeded: function (lastEventId, promises) {
|
|
152
|
+
if (!_this.webAttribution ||
|
|
153
|
+
!_this.webAttribution.shouldTrackNewCampaign ||
|
|
154
|
+
!isUserPropertyAttributionEnabled(_this.webAttribution.options)) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
var campaignEvent = _this.webAttribution.generateCampaignEvent(lastEventId);
|
|
158
|
+
if (promises) {
|
|
159
|
+
promises.push(_this.track(campaignEvent).promise);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
_this.track(campaignEvent);
|
|
163
|
+
}
|
|
164
|
+
_this.config.loggerProvider.log('Tracking attribution.');
|
|
165
|
+
return true;
|
|
166
|
+
},
|
|
167
|
+
addAttributionTrackingPlugin: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
168
|
+
var attributionTrackingOptions_1;
|
|
169
|
+
var _this = this;
|
|
170
|
+
return __generator(this, function (_a) {
|
|
171
|
+
switch (_a.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
if (!(this.attributionTrackingOptions !== undefined &&
|
|
174
|
+
isAttributionTrackingEnabled(this.config.defaultTracking) &&
|
|
175
|
+
isUserPropertyAttributionEnabled(this.attributionTrackingOptions))) return [3 /*break*/, 2];
|
|
176
|
+
attributionTrackingOptions_1 = this.attributionTrackingOptions;
|
|
177
|
+
if (this.config.optOut) {
|
|
178
|
+
this.timeline.addOptOutListener(function (optOut) { return __awaiter(_this, void 0, void 0, function () {
|
|
179
|
+
return __generator(this, function (_a) {
|
|
180
|
+
switch (_a.label) {
|
|
181
|
+
case 0:
|
|
182
|
+
if (!!optOut) return [3 /*break*/, 2];
|
|
183
|
+
this.webAttribution = new WebAttribution(attributionTrackingOptions_1, this.config);
|
|
184
|
+
return [4 /*yield*/, this.webAttribution.init()];
|
|
185
|
+
case 1:
|
|
186
|
+
_a.sent();
|
|
187
|
+
_a.label = 2;
|
|
188
|
+
case 2: return [2 /*return*/];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}); });
|
|
192
|
+
}
|
|
193
|
+
this.webAttribution = new WebAttribution(attributionTrackingOptions_1, this.config);
|
|
194
|
+
// Fetch the current campaign, check if need to track web attribution later
|
|
195
|
+
return [4 /*yield*/, this.webAttribution.init()];
|
|
196
|
+
case 1:
|
|
197
|
+
// Fetch the current campaign, check if need to track web attribution later
|
|
198
|
+
_a.sent();
|
|
199
|
+
_a.label = 2;
|
|
200
|
+
case 2: return [2 /*return*/];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}); },
|
|
204
|
+
getDiagnosticsClient: function (options, loggerProvider, serverZone, enableDiagnostics, diagnosticsSampleRate) { return __awaiter(_this, void 0, void 0, function () {
|
|
205
|
+
var diagnosticsClient;
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
diagnosticsClient = new DiagnosticsClient(options.apiKey, loggerProvider, serverZone, {
|
|
208
|
+
enabled: enableDiagnostics,
|
|
209
|
+
sampleRate: diagnosticsSampleRate,
|
|
210
|
+
});
|
|
211
|
+
this.diagnosticsClient = diagnosticsClient;
|
|
212
|
+
diagnosticsClient.setTag('library', "".concat(LIBPREFIX, "/").concat(VERSION));
|
|
213
|
+
diagnosticsClient.setTag('platform', BROWSER_PLATFORM);
|
|
214
|
+
diagnosticsClient.setTag('web_environment', getRuntimeEnvironment());
|
|
215
|
+
if (typeof navigator !== 'undefined') {
|
|
216
|
+
diagnosticsClient.setTag('user_agent', navigator.userAgent);
|
|
217
|
+
}
|
|
218
|
+
return [2 /*return*/, diagnosticsClient];
|
|
219
|
+
});
|
|
220
|
+
}); },
|
|
221
|
+
getRemoteConfigClient: function (options, loggerProvider, serverZone) { return __awaiter(_this, void 0, void 0, function () {
|
|
222
|
+
var remoteConfigClient;
|
|
223
|
+
var _this = this;
|
|
224
|
+
var _a;
|
|
225
|
+
return __generator(this, function (_b) {
|
|
226
|
+
switch (_b.label) {
|
|
227
|
+
case 0:
|
|
228
|
+
remoteConfigClient = new RemoteConfigClient(options.apiKey, loggerProvider, serverZone,
|
|
229
|
+
/* istanbul ignore next */ (_a = options.remoteConfig) === null || _a === void 0 ? void 0 : _a.serverUrl);
|
|
230
|
+
// Fetch diagnostics config first to get sample rate
|
|
231
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
232
|
+
// Disable coverage for this line because remote config client will always be defined in this case.
|
|
233
|
+
// istanbul ignore next
|
|
234
|
+
remoteConfigClient === null || remoteConfigClient === void 0 ? void 0 : remoteConfigClient.subscribe('configs.diagnostics.browserSDK', 'all', function (remoteConfig, source, lastFetch) {
|
|
235
|
+
loggerProvider.debug('Diagnostics remote configuration received:', safeJsonStringify({
|
|
236
|
+
remoteConfig: remoteConfig,
|
|
237
|
+
source: source,
|
|
238
|
+
lastFetch: lastFetch,
|
|
239
|
+
}, null, 2));
|
|
240
|
+
if (remoteConfig) {
|
|
241
|
+
// Validate and set sampleRate (must be a valid number)
|
|
242
|
+
var sampleRate = remoteConfig.sampleRate;
|
|
243
|
+
if (typeof sampleRate === 'number' && !isNaN(sampleRate)) {
|
|
244
|
+
_this.diagnosticsSampleRate = sampleRate;
|
|
245
|
+
}
|
|
246
|
+
// Validate and set enabled (must be a boolean)
|
|
247
|
+
var enabled = remoteConfig.enabled;
|
|
248
|
+
if (typeof enabled === 'boolean') {
|
|
249
|
+
_this.enableDiagnostics = enabled;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
resolve();
|
|
253
|
+
});
|
|
254
|
+
})];
|
|
255
|
+
case 1:
|
|
256
|
+
// Fetch diagnostics config first to get sample rate
|
|
257
|
+
_b.sent();
|
|
258
|
+
return [2 /*return*/, remoteConfigClient];
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}); },
|
|
262
|
+
fetchRemoteConfig: function (remoteConfigClient, browserOptions) { return __awaiter(_this, void 0, void 0, function () {
|
|
263
|
+
return __generator(this, function (_a) {
|
|
264
|
+
switch (_a.label) {
|
|
265
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve) {
|
|
133
266
|
// Disable coverage for this line because remote config client will always be defined in this case.
|
|
134
267
|
// istanbul ignore next
|
|
135
268
|
remoteConfigClient === null || remoteConfigClient === void 0 ? void 0 : remoteConfigClient.subscribe('configs.analyticsSDK.browserSDK', 'all', function (remoteConfig, source, lastFetch) {
|
|
136
|
-
|
|
269
|
+
var _a;
|
|
270
|
+
(_a = browserOptions.loggerProvider) === null || _a === void 0 ? void 0 : _a.debug('Remote configuration received:', safeJsonStringify({
|
|
137
271
|
remoteConfig: remoteConfig,
|
|
138
272
|
source: source,
|
|
139
273
|
lastFetch: lastFetch,
|
|
@@ -145,481 +279,16 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
145
279
|
resolve();
|
|
146
280
|
});
|
|
147
281
|
})];
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
case 5: return [4 /*yield*/, _super.prototype._init.call(this, browserOptions)];
|
|
152
|
-
case 6:
|
|
153
|
-
_j.sent();
|
|
154
|
-
this.logBrowserOptions(browserOptions);
|
|
155
|
-
this.config.remoteConfigClient = remoteConfigClient;
|
|
156
|
-
attributionTrackingOptions = getAttributionTrackingConfig(this.config);
|
|
157
|
-
if (!(isAttributionTrackingEnabled(this.config.defaultTracking) &&
|
|
158
|
-
isUserPropertyAttributionEnabled(attributionTrackingOptions))) return [3 /*break*/, 8];
|
|
159
|
-
if (this.config.optOut) {
|
|
160
|
-
this.timeline.addOptOutListener(function (optOut) { return __awaiter(_this, void 0, void 0, function () {
|
|
161
|
-
return __generator(this, function (_a) {
|
|
162
|
-
switch (_a.label) {
|
|
163
|
-
case 0:
|
|
164
|
-
if (!!optOut) return [3 /*break*/, 2];
|
|
165
|
-
this.webAttribution = new WebAttribution(attributionTrackingOptions, this.config);
|
|
166
|
-
return [4 /*yield*/, this.webAttribution.init()];
|
|
167
|
-
case 1:
|
|
168
|
-
_a.sent();
|
|
169
|
-
_a.label = 2;
|
|
170
|
-
case 2: return [2 /*return*/];
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}); });
|
|
174
|
-
}
|
|
175
|
-
this.webAttribution = new WebAttribution(attributionTrackingOptions, this.config);
|
|
176
|
-
// Fetch the current campaign, check if need to track web attribution later
|
|
177
|
-
return [4 /*yield*/, this.webAttribution.init()];
|
|
178
|
-
case 7:
|
|
179
|
-
// Fetch the current campaign, check if need to track web attribution later
|
|
180
|
-
_j.sent();
|
|
181
|
-
_j.label = 8;
|
|
182
|
-
case 8:
|
|
183
|
-
queryParams = getQueryParams();
|
|
184
|
-
ampTimestamp = queryParams.ampTimestamp ? Number(queryParams.ampTimestamp) : undefined;
|
|
185
|
-
isWithinTimeLimit = ampTimestamp ? Date.now() < ampTimestamp : true;
|
|
186
|
-
querySessionId = isWithinTimeLimit && !Number.isNaN(Number(queryParams.ampSessionId))
|
|
187
|
-
? Number(queryParams.ampSessionId)
|
|
188
|
-
: undefined;
|
|
189
|
-
deferredSessionId = this.config.deferredSessionId;
|
|
190
|
-
if (deferredSessionId === UNSPECIFIED_SESSION_ID && !this.config.optOut) {
|
|
191
|
-
deferredSessionId = Date.now();
|
|
192
|
-
}
|
|
193
|
-
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);
|
|
194
|
-
if (this.config.optOut) {
|
|
195
|
-
this.timeline.addOptOutListener(function (optOut) { return __awaiter(_this, void 0, void 0, function () {
|
|
196
|
-
return __generator(this, function (_a) {
|
|
197
|
-
if (!optOut && this.config.deferredSessionId) {
|
|
198
|
-
if (this.config.deferredSessionId === UNSPECIFIED_SESSION_ID) {
|
|
199
|
-
this.setSessionId(undefined);
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
this.setSessionId(this.config.deferredSessionId);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return [2 /*return*/];
|
|
206
|
-
});
|
|
207
|
-
}); });
|
|
208
|
-
}
|
|
209
|
-
connector = getAnalyticsConnector(this.config.instanceName);
|
|
210
|
-
connector.identityStore.setIdentity({
|
|
211
|
-
userId: this.config.userId,
|
|
212
|
-
deviceId: this.config.deviceId,
|
|
213
|
-
});
|
|
214
|
-
if (!(this.config.offline !== OfflineDisabled)) return [3 /*break*/, 10];
|
|
215
|
-
return [4 /*yield*/, this.add(networkConnectivityCheckerPlugin()).promise];
|
|
216
|
-
case 9:
|
|
217
|
-
_j.sent();
|
|
218
|
-
_j.label = 10;
|
|
219
|
-
case 10: return [4 /*yield*/, this.add(new Destination({ diagnosticsClient: diagnosticsClient })).promise];
|
|
220
|
-
case 11:
|
|
221
|
-
_j.sent();
|
|
222
|
-
return [4 /*yield*/, this.add(new Context()).promise];
|
|
223
|
-
case 12:
|
|
224
|
-
_j.sent();
|
|
225
|
-
return [4 /*yield*/, this.add(new IdentityEventSender()).promise];
|
|
226
|
-
case 13:
|
|
227
|
-
_j.sent();
|
|
228
|
-
// Notify if DET is enabled
|
|
229
|
-
detNotify(this.config);
|
|
230
|
-
if (!isFileDownloadTrackingEnabled(this.config.defaultTracking)) return [3 /*break*/, 15];
|
|
231
|
-
this.config.loggerProvider.debug('Adding file download tracking plugin');
|
|
232
|
-
return [4 /*yield*/, this.add(fileDownloadTracking()).promise];
|
|
233
|
-
case 14:
|
|
234
|
-
_j.sent();
|
|
235
|
-
_j.label = 15;
|
|
236
|
-
case 15:
|
|
237
|
-
if (!isFormInteractionTrackingEnabled(this.config.defaultTracking)) return [3 /*break*/, 17];
|
|
238
|
-
this.config.loggerProvider.debug('Adding form interaction plugin');
|
|
239
|
-
return [4 /*yield*/, this.add(formInteractionTracking()).promise];
|
|
240
|
-
case 16:
|
|
241
|
-
_j.sent();
|
|
242
|
-
_j.label = 17;
|
|
243
|
-
case 17:
|
|
244
|
-
enrichBeforePageTracking = getPageViewTrackingConfig(this.config).trackOn === undefined;
|
|
245
|
-
if (!(enrichBeforePageTracking && isPageUrlEnrichmentEnabled(this.config.autocapture))) return [3 /*break*/, 19];
|
|
246
|
-
this.config.loggerProvider.debug('Adding referrer page url plugin');
|
|
247
|
-
return [4 /*yield*/, this.add(pageUrlEnrichmentPlugin()).promise];
|
|
248
|
-
case 18:
|
|
249
|
-
_j.sent();
|
|
250
|
-
_j.label = 19;
|
|
251
|
-
case 19:
|
|
252
|
-
if (!isPageViewTrackingEnabled(this.config.defaultTracking)) return [3 /*break*/, 22];
|
|
253
|
-
if (!!this.config.optOut) return [3 /*break*/, 21];
|
|
254
|
-
this.config.loggerProvider.debug('Adding page view tracking plugin');
|
|
255
|
-
return [4 /*yield*/, this.add(pageViewTrackingPlugin(getPageViewTrackingConfig(this.config))).promise];
|
|
256
|
-
case 20:
|
|
257
|
-
_j.sent();
|
|
258
|
-
return [3 /*break*/, 22];
|
|
259
|
-
case 21:
|
|
260
|
-
this.timeline.addOptOutListener(function (optOut) { return __awaiter(_this, void 0, void 0, function () {
|
|
261
|
-
return __generator(this, function (_a) {
|
|
262
|
-
switch (_a.label) {
|
|
263
|
-
case 0:
|
|
264
|
-
/* istanbul ignore if */
|
|
265
|
-
if (optOut) {
|
|
266
|
-
return [2 /*return*/];
|
|
267
|
-
}
|
|
268
|
-
this.config.loggerProvider.debug('Adding page view tracking plugin');
|
|
269
|
-
return [4 /*yield*/, this.add(pageViewTrackingPlugin(getPageViewTrackingConfig(this.config))).promise];
|
|
270
|
-
case 1:
|
|
271
|
-
_a.sent();
|
|
272
|
-
return [2 /*return*/];
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
}); });
|
|
276
|
-
_j.label = 22;
|
|
277
|
-
case 22:
|
|
278
|
-
if (!(isAttributionTrackingEnabled(this.config.defaultTracking) &&
|
|
279
|
-
isEventPropertyAttributionEnabled(attributionTrackingOptions))) return [3 /*break*/, 24];
|
|
280
|
-
this.config.loggerProvider.debug('Adding event property attribution plugin');
|
|
281
|
-
return [4 /*yield*/, this.add(eventPropertyTrackingPlugin(attributionTrackingOptions)).promise];
|
|
282
|
-
case 23:
|
|
283
|
-
_j.sent();
|
|
284
|
-
_j.label = 24;
|
|
285
|
-
case 24:
|
|
286
|
-
if (!isElementInteractionsEnabled(this.config.autocapture)) return [3 /*break*/, 26];
|
|
287
|
-
this.config.loggerProvider.debug('Adding user interactions plugin (autocapture plugin)');
|
|
288
|
-
return [4 /*yield*/, this.add(autocapturePlugin(getElementInteractionsConfig(this.config), { diagnosticsClient: diagnosticsClient })).promise];
|
|
289
|
-
case 25:
|
|
290
|
-
_j.sent();
|
|
291
|
-
_j.label = 26;
|
|
292
|
-
case 26:
|
|
293
|
-
if (!isFrustrationInteractionsEnabled(this.config.autocapture)) return [3 /*break*/, 28];
|
|
294
|
-
this.config.loggerProvider.debug('Adding frustration interactions plugin');
|
|
295
|
-
return [4 /*yield*/, this.add(frustrationPlugin(getFrustrationInteractionsConfig(this.config))).promise];
|
|
296
|
-
case 27:
|
|
297
|
-
_j.sent();
|
|
298
|
-
_j.label = 28;
|
|
299
|
-
case 28:
|
|
300
|
-
if (!isNetworkTrackingEnabled(this.config.autocapture)) return [3 /*break*/, 30];
|
|
301
|
-
this.config.loggerProvider.debug('Adding network tracking plugin');
|
|
302
|
-
return [4 /*yield*/, this.add(networkCapturePlugin(getNetworkTrackingConfig(this.config))).promise];
|
|
303
|
-
case 29:
|
|
304
|
-
_j.sent();
|
|
305
|
-
_j.label = 30;
|
|
306
|
-
case 30:
|
|
307
|
-
if (!isWebVitalsEnabled(this.config.autocapture)) return [3 /*break*/, 32];
|
|
308
|
-
this.config.loggerProvider.debug('Adding web vitals plugin');
|
|
309
|
-
return [4 /*yield*/, this.add(webVitalsPlugin(getWebVitalsConfig(this.config))).promise];
|
|
310
|
-
case 31:
|
|
311
|
-
_j.sent();
|
|
312
|
-
_j.label = 32;
|
|
313
|
-
case 32:
|
|
314
|
-
if (!isPerformanceTrackingEnabled(this.config.autocapture)) return [3 /*break*/, 34];
|
|
315
|
-
this.config.loggerProvider.debug('Adding performance tracking plugin');
|
|
316
|
-
return [4 /*yield*/, this.add(performancePlugin(getPerformanceTrackingConfig(this.config))).promise];
|
|
317
|
-
case 33:
|
|
318
|
-
_j.sent();
|
|
319
|
-
_j.label = 34;
|
|
320
|
-
case 34:
|
|
321
|
-
if (!(!enrichBeforePageTracking && isPageUrlEnrichmentEnabled(this.config.autocapture))) return [3 /*break*/, 36];
|
|
322
|
-
this.config.loggerProvider.debug('Adding referrer page url plugin');
|
|
323
|
-
return [4 /*yield*/, this.add(pageUrlEnrichmentPlugin()).promise];
|
|
324
|
-
case 35:
|
|
325
|
-
_j.sent();
|
|
326
|
-
_j.label = 36;
|
|
327
|
-
case 36:
|
|
328
|
-
if (!isCustomEnrichmentEnabled(this.config.customEnrichment)) return [3 /*break*/, 38];
|
|
329
|
-
this.config.loggerProvider.debug('Adding custom enrichment plugin');
|
|
330
|
-
return [4 /*yield*/, this.add(customEnrichmentPlugin()).promise];
|
|
331
|
-
case 37:
|
|
332
|
-
_j.sent();
|
|
333
|
-
_j.label = 38;
|
|
334
|
-
case 38:
|
|
335
|
-
this.initializing = false;
|
|
336
|
-
// Step 6: Run queued dispatch functions
|
|
337
|
-
return [4 /*yield*/, this.runQueuedFunctions('dispatchQ')];
|
|
338
|
-
case 39:
|
|
339
|
-
// Step 6: Run queued dispatch functions
|
|
340
|
-
_j.sent();
|
|
341
|
-
// Step 7: Add the event receiver after running remaining queued functions.
|
|
342
|
-
connector.eventBridge.setEventReceiver(function (event) {
|
|
343
|
-
var _a = event.eventProperties || {}, time = _a.time, cleanEventProperties = __rest(_a, ["time"]);
|
|
344
|
-
var eventOptions = __assign(__assign({}, (typeof time === 'number' && { time: time })), (event.groups && { groups: event.groups }));
|
|
345
|
-
void _this.track(event.eventType, cleanEventProperties, Object.keys(eventOptions).length ? eventOptions : undefined);
|
|
346
|
-
});
|
|
347
|
-
return [2 /*return*/];
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
AmplitudeBrowser.prototype.getUserId = function () {
|
|
353
|
-
var _a;
|
|
354
|
-
return (_a = this.config) === null || _a === void 0 ? void 0 : _a.userId;
|
|
355
|
-
};
|
|
356
|
-
AmplitudeBrowser.prototype.setUserId = function (userId) {
|
|
357
|
-
if (!this.config) {
|
|
358
|
-
this.q.push(this.setUserId.bind(this, userId));
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
this.config.loggerProvider.debug('function setUserId: ', userId);
|
|
362
|
-
if (userId !== this.config.userId || userId === undefined) {
|
|
363
|
-
this.config.userId = userId;
|
|
364
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
365
|
-
this.timeline.onIdentityChanged({ userId: userId });
|
|
366
|
-
setConnectorUserId(userId, this.config.instanceName);
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
AmplitudeBrowser.prototype.getDeviceId = function () {
|
|
370
|
-
var _a;
|
|
371
|
-
return (_a = this.config) === null || _a === void 0 ? void 0 : _a.deviceId;
|
|
372
|
-
};
|
|
373
|
-
AmplitudeBrowser.prototype.setDeviceId = function (deviceId) {
|
|
374
|
-
if (!this.config) {
|
|
375
|
-
this.q.push(this.setDeviceId.bind(this, deviceId));
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
this.config.loggerProvider.debug('function setDeviceId: ', deviceId);
|
|
379
|
-
if (deviceId !== this.config.deviceId) {
|
|
380
|
-
this.config.deviceId = deviceId;
|
|
381
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
382
|
-
this.timeline.onIdentityChanged({ deviceId: deviceId });
|
|
383
|
-
setConnectorDeviceId(deviceId, this.config.instanceName);
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
AmplitudeBrowser.prototype.reset = function () {
|
|
387
|
-
this.setDeviceId(UUID());
|
|
388
|
-
this.setUserId(undefined);
|
|
389
|
-
this.timeline.onReset();
|
|
390
|
-
};
|
|
391
|
-
AmplitudeBrowser.prototype.getIdentity = function () {
|
|
392
|
-
var _a, _b;
|
|
393
|
-
return {
|
|
394
|
-
deviceId: (_a = this.config) === null || _a === void 0 ? void 0 : _a.deviceId,
|
|
395
|
-
userId: (_b = this.config) === null || _b === void 0 ? void 0 : _b.userId,
|
|
396
|
-
userProperties: this.userProperties,
|
|
397
|
-
};
|
|
398
|
-
};
|
|
399
|
-
AmplitudeBrowser.prototype.setIdentity = function (identity) {
|
|
400
|
-
var e_1, _a;
|
|
401
|
-
var _b;
|
|
402
|
-
// Handle userId change
|
|
403
|
-
if ('userId' in identity) {
|
|
404
|
-
this.setUserId(identity.userId);
|
|
405
|
-
}
|
|
406
|
-
// Handle deviceId change
|
|
407
|
-
if ('deviceId' in identity && identity.deviceId) {
|
|
408
|
-
this.setDeviceId(identity.deviceId);
|
|
409
|
-
}
|
|
410
|
-
// Handle userProperties change - auto-send identify
|
|
411
|
-
if ('userProperties' in identity) {
|
|
412
|
-
this.userProperties = identity.userProperties;
|
|
413
|
-
// Auto-send identify event with $set operations
|
|
414
|
-
var identifyObj = new Identify();
|
|
415
|
-
// istanbul ignore next
|
|
416
|
-
var userProperties = (_b = identity.userProperties) !== null && _b !== void 0 ? _b : {};
|
|
417
|
-
try {
|
|
418
|
-
for (var _c = __values(Object.entries(userProperties)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
419
|
-
var _e = __read(_d.value, 2), key = _e[0], value = _e[1];
|
|
420
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
421
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
422
|
-
identifyObj.set(key, value);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
426
|
-
finally {
|
|
427
|
-
try {
|
|
428
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
429
|
-
}
|
|
430
|
-
finally { if (e_1) throw e_1.error; }
|
|
431
|
-
}
|
|
432
|
-
// The identify event processing in core-client already calls onIdentityChanged,
|
|
433
|
-
// so we don't need to call it explicitly here to avoid duplicate notifications.
|
|
434
|
-
this.identify(identifyObj);
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
AmplitudeBrowser.prototype.getOptOut = function () {
|
|
438
|
-
var _a;
|
|
439
|
-
return (_a = this.config) === null || _a === void 0 ? void 0 : _a.optOut;
|
|
440
|
-
};
|
|
441
|
-
AmplitudeBrowser.prototype.getSessionId = function () {
|
|
442
|
-
var _a;
|
|
443
|
-
return (_a = this.config) === null || _a === void 0 ? void 0 : _a.sessionId;
|
|
444
|
-
};
|
|
445
|
-
AmplitudeBrowser.prototype.setSessionId = function (sessionId) {
|
|
446
|
-
var _a;
|
|
447
|
-
var promises = [];
|
|
448
|
-
if (!this.config) {
|
|
449
|
-
this.q.push(this.setSessionId.bind(this, sessionId));
|
|
450
|
-
return returnWrapper(Promise.resolve());
|
|
451
|
-
}
|
|
452
|
-
// do not start a new session if optOut is true
|
|
453
|
-
if (this.config.optOut) {
|
|
454
|
-
// save the sessionId to storage to be used when optOut is false
|
|
455
|
-
this.config.deferredSessionId = sessionId !== null && sessionId !== void 0 ? sessionId : UNSPECIFIED_SESSION_ID;
|
|
456
|
-
return returnWrapper(Promise.resolve());
|
|
457
|
-
}
|
|
458
|
-
// default sessionId to current time
|
|
459
|
-
if (sessionId === undefined) {
|
|
460
|
-
sessionId = Date.now();
|
|
461
|
-
}
|
|
462
|
-
// Prevents starting a new session with the same session ID
|
|
463
|
-
if (sessionId === this.config.sessionId) {
|
|
464
|
-
return returnWrapper(Promise.resolve());
|
|
465
|
-
}
|
|
466
|
-
this.config.loggerProvider.debug('function setSessionId: ', sessionId);
|
|
467
|
-
var previousSessionId = this.getSessionId();
|
|
468
|
-
if (previousSessionId !== sessionId) {
|
|
469
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
470
|
-
this.timeline.onSessionIdChanged(sessionId);
|
|
471
|
-
}
|
|
472
|
-
var lastEventTime = this.config.lastEventTime;
|
|
473
|
-
var lastEventId = (_a = this.config.lastEventId) !== null && _a !== void 0 ? _a : -1;
|
|
474
|
-
this.config.sessionId = sessionId;
|
|
475
|
-
this.config.lastEventTime = undefined;
|
|
476
|
-
this.config.pageCounter = 0;
|
|
477
|
-
if (isSessionTrackingEnabled(this.config.defaultTracking)) {
|
|
478
|
-
if (previousSessionId && lastEventTime) {
|
|
479
|
-
promises.push(this.track(DEFAULT_SESSION_END_EVENT, undefined, {
|
|
480
|
-
device_id: this.previousSessionDeviceId,
|
|
481
|
-
event_id: ++lastEventId,
|
|
482
|
-
session_id: previousSessionId,
|
|
483
|
-
time: lastEventTime + 1,
|
|
484
|
-
user_id: this.previousSessionUserId,
|
|
485
|
-
}).promise);
|
|
486
|
-
}
|
|
487
|
-
this.config.lastEventTime = this.config.sessionId;
|
|
488
|
-
}
|
|
489
|
-
// Fire web attribution event when enable webAttribution tracking
|
|
490
|
-
// 1. has new campaign (call setSessionId from init function)
|
|
491
|
-
// 2. or shouldTrackNewCampaign (call setSessionId from async process(event) when there has new campaign and resetSessionOnNewCampaign = true )
|
|
492
|
-
var isCampaignEventTracked = this.trackCampaignEventIfNeeded(++lastEventId, promises);
|
|
493
|
-
// track the identify event if an Identify object is provided in the config
|
|
494
|
-
if (this.config.identify) {
|
|
495
|
-
promises.push(this.track(createIdentifyEvent(this.config.identify)).promise);
|
|
496
|
-
}
|
|
497
|
-
if (isSessionTrackingEnabled(this.config.defaultTracking)) {
|
|
498
|
-
promises.push(this.track(DEFAULT_SESSION_START_EVENT, undefined, {
|
|
499
|
-
event_id: isCampaignEventTracked ? ++lastEventId : lastEventId,
|
|
500
|
-
session_id: this.config.sessionId,
|
|
501
|
-
time: this.config.lastEventTime,
|
|
502
|
-
}).promise);
|
|
503
|
-
}
|
|
504
|
-
this.previousSessionDeviceId = this.config.deviceId;
|
|
505
|
-
this.previousSessionUserId = this.config.userId;
|
|
506
|
-
return returnWrapper(Promise.all(promises));
|
|
507
|
-
};
|
|
508
|
-
AmplitudeBrowser.prototype.extendSession = function () {
|
|
509
|
-
if (!this.config) {
|
|
510
|
-
this.q.push(this.extendSession.bind(this));
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
this.config.lastEventTime = Date.now();
|
|
514
|
-
};
|
|
515
|
-
AmplitudeBrowser.prototype.setTransport = function (transport) {
|
|
516
|
-
if (!this.config) {
|
|
517
|
-
this.q.push(this.setTransport.bind(this, transport));
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
this.config.transportProvider = createTransport(transport);
|
|
521
|
-
};
|
|
522
|
-
AmplitudeBrowser.prototype.identify = function (identify, eventOptions) {
|
|
523
|
-
if (isInstanceProxy(identify)) {
|
|
524
|
-
var queue = identify._q;
|
|
525
|
-
identify._q = [];
|
|
526
|
-
identify = convertProxyObjectToRealObject(new Identify(), queue);
|
|
527
|
-
}
|
|
528
|
-
if (eventOptions === null || eventOptions === void 0 ? void 0 : eventOptions.user_id) {
|
|
529
|
-
this.setUserId(eventOptions.user_id);
|
|
530
|
-
}
|
|
531
|
-
if (eventOptions === null || eventOptions === void 0 ? void 0 : eventOptions.device_id) {
|
|
532
|
-
this.setDeviceId(eventOptions.device_id);
|
|
533
|
-
}
|
|
534
|
-
return _super.prototype.identify.call(this, identify, eventOptions);
|
|
535
|
-
};
|
|
536
|
-
AmplitudeBrowser.prototype.groupIdentify = function (groupType, groupName, identify, eventOptions) {
|
|
537
|
-
if (isInstanceProxy(identify)) {
|
|
538
|
-
var queue = identify._q;
|
|
539
|
-
identify._q = [];
|
|
540
|
-
identify = convertProxyObjectToRealObject(new Identify(), queue);
|
|
541
|
-
}
|
|
542
|
-
return _super.prototype.groupIdentify.call(this, groupType, groupName, identify, eventOptions);
|
|
543
|
-
};
|
|
544
|
-
AmplitudeBrowser.prototype.revenue = function (revenue, eventOptions) {
|
|
545
|
-
if (isInstanceProxy(revenue)) {
|
|
546
|
-
var queue = revenue._q;
|
|
547
|
-
revenue._q = [];
|
|
548
|
-
revenue = convertProxyObjectToRealObject(new Revenue(), queue);
|
|
549
|
-
}
|
|
550
|
-
return _super.prototype.revenue.call(this, revenue, eventOptions);
|
|
551
|
-
};
|
|
552
|
-
AmplitudeBrowser.prototype.trackCampaignEventIfNeeded = function (lastEventId, promises) {
|
|
553
|
-
if (!this.webAttribution ||
|
|
554
|
-
!this.webAttribution.shouldTrackNewCampaign ||
|
|
555
|
-
!isUserPropertyAttributionEnabled(this.webAttribution.options)) {
|
|
556
|
-
return false;
|
|
557
|
-
}
|
|
558
|
-
var campaignEvent = this.webAttribution.generateCampaignEvent(lastEventId);
|
|
559
|
-
if (promises) {
|
|
560
|
-
promises.push(this.track(campaignEvent).promise);
|
|
561
|
-
}
|
|
562
|
-
else {
|
|
563
|
-
this.track(campaignEvent);
|
|
564
|
-
}
|
|
565
|
-
this.config.loggerProvider.log('Tracking attribution.');
|
|
566
|
-
return true;
|
|
567
|
-
};
|
|
568
|
-
AmplitudeBrowser.prototype.process = function (event) {
|
|
569
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
570
|
-
var currentTime, isEventInNewSession, shouldSetSessionIdOnNewCampaign;
|
|
571
|
-
return __generator(this, function (_a) {
|
|
572
|
-
currentTime = Date.now();
|
|
573
|
-
isEventInNewSession = isNewSession(this.config.sessionTimeout, this.config.lastEventTime);
|
|
574
|
-
shouldSetSessionIdOnNewCampaign = this.webAttribution && this.webAttribution.shouldSetSessionIdOnNewCampaign();
|
|
575
|
-
if (event.event_type !== DEFAULT_SESSION_START_EVENT &&
|
|
576
|
-
event.event_type !== DEFAULT_SESSION_END_EVENT &&
|
|
577
|
-
(!event.session_id || event.session_id === this.getSessionId())) {
|
|
578
|
-
if (isEventInNewSession || shouldSetSessionIdOnNewCampaign) {
|
|
579
|
-
this.setSessionId(currentTime);
|
|
580
|
-
if (shouldSetSessionIdOnNewCampaign) {
|
|
581
|
-
this.config.loggerProvider.log('Created a new session for new campaign.');
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
else if (!isEventInNewSession) {
|
|
585
|
-
// Web attribution should be tracked during the middle of a session
|
|
586
|
-
// if there has been a chance in the campaign information.
|
|
587
|
-
this.trackCampaignEventIfNeeded();
|
|
282
|
+
case 1:
|
|
283
|
+
_a.sent();
|
|
284
|
+
return [2 /*return*/];
|
|
588
285
|
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
};
|
|
594
|
-
AmplitudeBrowser.prototype.logBrowserOptions = function (browserConfig) {
|
|
595
|
-
try {
|
|
596
|
-
var browserConfigCopy = __assign(__assign({}, browserConfig), { apiKey: browserConfig.apiKey.substring(0, 10) + '********' });
|
|
597
|
-
this.config.loggerProvider.debug('Initialized Amplitude with BrowserConfig:', safeJsonStringify(browserConfigCopy));
|
|
598
|
-
}
|
|
599
|
-
catch (e) {
|
|
600
|
-
/* istanbul ignore next */
|
|
601
|
-
this.config.loggerProvider.error('Error logging browser config', e);
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
/**
|
|
605
|
-
* @experimental
|
|
606
|
-
* WARNING: This method is for internal testing only and is not part of the public API.
|
|
607
|
-
* It may be changed or removed at any time without notice.
|
|
608
|
-
*
|
|
609
|
-
* Sets the diagnostics sample rate before amplitude.init()
|
|
610
|
-
* @param sampleRate - The sample rate to set
|
|
611
|
-
*/
|
|
612
|
-
AmplitudeBrowser.prototype._setDiagnosticsSampleRate = function (sampleRate) {
|
|
613
|
-
if (sampleRate > 1 || sampleRate < 0) {
|
|
614
|
-
return;
|
|
615
|
-
}
|
|
616
|
-
// Set diagnostics sample rate before initializing the config
|
|
617
|
-
if (!this.config) {
|
|
618
|
-
this._diagnosticsSampleRate = sampleRate;
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
286
|
+
});
|
|
287
|
+
}); },
|
|
288
|
+
};
|
|
289
|
+
return this._autocaptureAdapter;
|
|
621
290
|
};
|
|
622
291
|
return AmplitudeBrowser;
|
|
623
|
-
}(
|
|
292
|
+
}(AmplitudeBrowserLite));
|
|
624
293
|
export { AmplitudeBrowser };
|
|
625
294
|
//# sourceMappingURL=browser-client.js.map
|