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