@statsig/web-analytics 3.0.0 → 3.1.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 +3 -1
- package/src/AutoCapture.js +30 -10
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/web-analytics",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "3.
|
|
6
|
-
"@statsig/js-client": "3.
|
|
5
|
+
"@statsig/client-core": "3.1.0",
|
|
6
|
+
"@statsig/js-client": "3.1.0"
|
|
7
7
|
},
|
|
8
8
|
"jsdelivr": "./build/statsig-web-analytics.min.js",
|
|
9
9
|
"type": "commonjs",
|
package/src/AutoCapture.d.ts
CHANGED
|
@@ -6,13 +6,15 @@ export declare class AutoCapture {
|
|
|
6
6
|
private _startTime;
|
|
7
7
|
private _deepestScroll;
|
|
8
8
|
private _disabledEvents;
|
|
9
|
+
private _previousLoggedPageViewUrl;
|
|
9
10
|
constructor(_client: PrecomputedEvaluationsInterface);
|
|
10
11
|
private _addEventHandlers;
|
|
12
|
+
private _addPageViewTracking;
|
|
11
13
|
private _autoLogEvent;
|
|
12
14
|
private _initialize;
|
|
13
15
|
private _logError;
|
|
14
16
|
private _logSessionStart;
|
|
15
|
-
private
|
|
17
|
+
private _tryLogPageView;
|
|
16
18
|
private _logPerformance;
|
|
17
19
|
private _pageUnloadHandler;
|
|
18
20
|
private _enqueueAutoCapture;
|
package/src/AutoCapture.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AutoCapture = exports.runStatsigAutoCapture = void 0;
|
|
4
|
+
/* eslint-disable no-console */
|
|
4
5
|
const client_core_1 = require("@statsig/client-core");
|
|
5
6
|
const Utils_1 = require("./Utils");
|
|
6
7
|
const payloadUtils_1 = require("./payloadUtils");
|
|
@@ -15,6 +16,7 @@ class AutoCapture {
|
|
|
15
16
|
this._startTime = Date.now();
|
|
16
17
|
this._deepestScroll = 0;
|
|
17
18
|
this._disabledEvents = {};
|
|
19
|
+
this._previousLoggedPageViewUrl = null;
|
|
18
20
|
const { sdkKey, errorBoundary, values } = _client.getContext();
|
|
19
21
|
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 : {};
|
|
20
22
|
this._errorBoundary = errorBoundary;
|
|
@@ -47,6 +49,21 @@ class AutoCapture {
|
|
|
47
49
|
(0, Utils_1._registerEventHandler)(win, 'beforeunload', () => this._pageUnloadHandler());
|
|
48
50
|
(0, Utils_1._registerEventHandler)(win, 'scroll', () => this._scrollEventHandler());
|
|
49
51
|
}
|
|
52
|
+
_addPageViewTracking() {
|
|
53
|
+
const win = (0, client_core_1._getWindowSafe)();
|
|
54
|
+
const doc = (0, client_core_1._getDocumentSafe)();
|
|
55
|
+
if (!win || !doc) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
(0, Utils_1._registerEventHandler)(win, 'popstate', () => this._tryLogPageView());
|
|
59
|
+
window.history.pushState = new Proxy(window.history.pushState, {
|
|
60
|
+
apply: (target, thisArg, [state, unused, url]) => {
|
|
61
|
+
target.apply(thisArg, [state, unused, url]);
|
|
62
|
+
this._tryLogPageView();
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
this._tryLogPageView();
|
|
66
|
+
}
|
|
50
67
|
_autoLogEvent(event) {
|
|
51
68
|
var _a;
|
|
52
69
|
let eventType = (_a = event.type) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
@@ -69,8 +86,8 @@ class AutoCapture {
|
|
|
69
86
|
}
|
|
70
87
|
_initialize() {
|
|
71
88
|
this._addEventHandlers();
|
|
89
|
+
this._addPageViewTracking();
|
|
72
90
|
this._logSessionStart();
|
|
73
|
-
this._logPageView();
|
|
74
91
|
this._logPerformance();
|
|
75
92
|
}
|
|
76
93
|
_logError(event) {
|
|
@@ -107,15 +124,18 @@ class AutoCapture {
|
|
|
107
124
|
this._errorBoundary.logError('AC::logSession', err);
|
|
108
125
|
}
|
|
109
126
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
127
|
+
_tryLogPageView() {
|
|
128
|
+
const url = (0, Utils_1._getSafeUrl)();
|
|
129
|
+
const last = this._previousLoggedPageViewUrl;
|
|
130
|
+
if (last && url.href === last.href) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this._previousLoggedPageViewUrl = url;
|
|
134
|
+
const payload = (0, payloadUtils_1._gatherPageViewPayload)(url);
|
|
135
|
+
this._enqueueAutoCapture('page_view', (0, Utils_1._getSanitizedPageUrl)(), payload, {
|
|
136
|
+
flushImmediately: true,
|
|
137
|
+
addNewSessionMetadata: true,
|
|
138
|
+
});
|
|
119
139
|
}
|
|
120
140
|
_logPerformance() {
|
|
121
141
|
const win = (0, client_core_1._getWindowSafe)();
|