@statsig/web-analytics 3.9.1 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/AutoCapture.d.ts +2 -0
- package/src/AutoCapture.js +25 -5
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/web-analytics",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "3.
|
|
6
|
-
"@statsig/js-client": "3.
|
|
5
|
+
"@statsig/client-core": "3.11.0",
|
|
6
|
+
"@statsig/js-client": "3.11.0"
|
|
7
7
|
},
|
|
8
8
|
"jsdelivr": "./build/statsig-web-analytics.min.js",
|
|
9
9
|
"type": "commonjs",
|
package/src/AutoCapture.d.ts
CHANGED
|
@@ -19,10 +19,12 @@ export declare class AutoCapture {
|
|
|
19
19
|
private _previousLoggedPageViewUrl;
|
|
20
20
|
private _eventFilterFunc?;
|
|
21
21
|
private _hasLoggedPageViewEnd;
|
|
22
|
+
private _inactiveTimer;
|
|
22
23
|
constructor(_client: PrecomputedEvaluationsInterface, options?: AutoCaptureOptions);
|
|
23
24
|
private _addEventHandlers;
|
|
24
25
|
private _addPageViewTracking;
|
|
25
26
|
private _autoLogEvent;
|
|
27
|
+
private _bumpInactiveTimer;
|
|
26
28
|
private _initialize;
|
|
27
29
|
private _logError;
|
|
28
30
|
private _logSessionStart;
|
package/src/AutoCapture.js
CHANGED
|
@@ -5,6 +5,7 @@ const client_core_1 = require("@statsig/client-core");
|
|
|
5
5
|
const AutoCaptureEvent_1 = require("./AutoCaptureEvent");
|
|
6
6
|
const Utils_1 = require("./Utils");
|
|
7
7
|
const payloadUtils_1 = require("./payloadUtils");
|
|
8
|
+
const PAGE_INACTIVE_TIMEOUT = 600000;
|
|
8
9
|
const AUTO_EVENT_MAPPING = {
|
|
9
10
|
submit: AutoCaptureEvent_1.AutoCaptureEventName.FORM_SUBMIT,
|
|
10
11
|
click: AutoCaptureEvent_1.AutoCaptureEventName.CLICK,
|
|
@@ -32,6 +33,7 @@ class AutoCapture {
|
|
|
32
33
|
this._disabledEvents = {};
|
|
33
34
|
this._previousLoggedPageViewUrl = null;
|
|
34
35
|
this._hasLoggedPageViewEnd = false;
|
|
36
|
+
this._inactiveTimer = null;
|
|
35
37
|
const { sdkKey, errorBoundary, values } = _client.getContext();
|
|
36
38
|
this._disabledEvents = (_b = (_a = values === null || values === void 0 ? void 0 : values.auto_capture_settings) === null || _a === void 0 ? void 0 : _a.disabled_events) !== null && _b !== void 0 ? _b : {};
|
|
37
39
|
this._errorBoundary = errorBoundary;
|
|
@@ -56,12 +58,15 @@ class AutoCapture {
|
|
|
56
58
|
if (!win || !doc) {
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
|
-
const eventHandler = (event) => {
|
|
61
|
+
const eventHandler = (event, userAction = true) => {
|
|
60
62
|
this._autoLogEvent(event || win.event);
|
|
63
|
+
if (userAction) {
|
|
64
|
+
this._bumpInactiveTimer();
|
|
65
|
+
}
|
|
61
66
|
};
|
|
62
|
-
(0, Utils_1._registerEventHandler)(doc, 'click', eventHandler);
|
|
63
|
-
(0, Utils_1._registerEventHandler)(doc, 'submit', eventHandler);
|
|
64
|
-
(0, Utils_1._registerEventHandler)(win, 'error', eventHandler);
|
|
67
|
+
(0, Utils_1._registerEventHandler)(doc, 'click', (e) => eventHandler(e));
|
|
68
|
+
(0, Utils_1._registerEventHandler)(doc, 'submit', (e) => eventHandler(e));
|
|
69
|
+
(0, Utils_1._registerEventHandler)(win, 'error', (e) => eventHandler(e, false));
|
|
65
70
|
(0, Utils_1._registerEventHandler)(win, 'pagehide', () => this._tryLogPageViewEnd());
|
|
66
71
|
(0, Utils_1._registerEventHandler)(win, 'beforeunload', () => this._tryLogPageViewEnd());
|
|
67
72
|
(0, Utils_1._registerEventHandler)(win, 'scroll', () => this._scrollEventHandler());
|
|
@@ -102,6 +107,18 @@ class AutoCapture {
|
|
|
102
107
|
const { value, metadata } = (0, Utils_1._gatherEventData)(target);
|
|
103
108
|
this._enqueueAutoCapture(eventName, value, metadata);
|
|
104
109
|
}
|
|
110
|
+
_bumpInactiveTimer() {
|
|
111
|
+
const win = (0, client_core_1._getWindowSafe)();
|
|
112
|
+
if (!win) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (this._inactiveTimer) {
|
|
116
|
+
clearTimeout(this._inactiveTimer);
|
|
117
|
+
}
|
|
118
|
+
this._inactiveTimer = win.setTimeout(() => {
|
|
119
|
+
this._tryLogPageViewEnd(true);
|
|
120
|
+
}, PAGE_INACTIVE_TIMEOUT);
|
|
121
|
+
}
|
|
105
122
|
_initialize() {
|
|
106
123
|
this._addEventHandlers();
|
|
107
124
|
this._addPageViewTracking();
|
|
@@ -155,8 +172,9 @@ class AutoCapture {
|
|
|
155
172
|
flushImmediately: true,
|
|
156
173
|
addNewSessionMetadata: true,
|
|
157
174
|
});
|
|
175
|
+
this._bumpInactiveTimer();
|
|
158
176
|
}
|
|
159
|
-
_tryLogPageViewEnd() {
|
|
177
|
+
_tryLogPageViewEnd(dueToInactivity = false) {
|
|
160
178
|
if (this._hasLoggedPageViewEnd) {
|
|
161
179
|
return;
|
|
162
180
|
}
|
|
@@ -164,6 +182,7 @@ class AutoCapture {
|
|
|
164
182
|
this._enqueueAutoCapture(AutoCaptureEvent_1.AutoCaptureEventName.PAGE_VIEW_END, (0, Utils_1._getSanitizedPageUrl)(), {
|
|
165
183
|
scrollDepth: this._deepestScroll,
|
|
166
184
|
pageViewLength: Date.now() - this._startTime,
|
|
185
|
+
dueToInactivity,
|
|
167
186
|
}, { flushImmediately: true });
|
|
168
187
|
}
|
|
169
188
|
_logPerformance() {
|
|
@@ -240,6 +259,7 @@ class AutoCapture {
|
|
|
240
259
|
const scrollY = (_c = win === null || win === void 0 ? void 0 : win.scrollY) !== null && _c !== void 0 ? _c : 1;
|
|
241
260
|
const innerHeight = (_d = win === null || win === void 0 ? void 0 : win.innerHeight) !== null && _d !== void 0 ? _d : 1;
|
|
242
261
|
this._deepestScroll = Math.max(this._deepestScroll, Math.min(100, Math.round(((scrollY + innerHeight) / scrollHeight) * 100)));
|
|
262
|
+
this._bumpInactiveTimer();
|
|
243
263
|
}
|
|
244
264
|
_isNewSession(session) {
|
|
245
265
|
// within the last second
|