@statsig/web-analytics 0.0.1-beta.35 → 0.0.1-beta.37
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 +1 -2
- package/src/AutoCapture.js +19 -16
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/web-analytics",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.37",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "0.0.1-beta.
|
|
6
|
-
"@statsig/js-client": "0.0.1-beta.
|
|
5
|
+
"@statsig/client-core": "0.0.1-beta.37",
|
|
6
|
+
"@statsig/js-client": "0.0.1-beta.37"
|
|
7
7
|
},
|
|
8
8
|
"jsdelivr": "./build/statsig-web-analytics.min.js",
|
|
9
9
|
"type": "commonjs",
|
package/src/AutoCapture.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export declare class AutoCapture {
|
|
|
14
14
|
private _logPerformance;
|
|
15
15
|
private _pageUnloadHandler;
|
|
16
16
|
private _enqueueAutoCapture;
|
|
17
|
-
private _logAutoCaptureImmediately;
|
|
18
17
|
private _scrollEventHandler;
|
|
19
|
-
private
|
|
18
|
+
private _getSessionFromClient;
|
|
20
19
|
}
|
package/src/AutoCapture.js
CHANGED
|
@@ -104,10 +104,10 @@ class AutoCapture {
|
|
|
104
104
|
setTimeout(() => {
|
|
105
105
|
var _a;
|
|
106
106
|
const url = (0, Utils_1._getSafeUrl)();
|
|
107
|
-
this.
|
|
107
|
+
this._enqueueAutoCapture('page_view', (0, Utils_1._getSanitizedPageUrl)(), {
|
|
108
108
|
title: (_a = (0, client_core_1._getDocumentSafe)()) === null || _a === void 0 ? void 0 : _a.title,
|
|
109
109
|
queryParams: Object.fromEntries(url.searchParams),
|
|
110
|
-
});
|
|
110
|
+
}, { flushImmediately: true, addNewSessionMetadata: true });
|
|
111
111
|
}, 1);
|
|
112
112
|
}
|
|
113
113
|
_logPerformance() {
|
|
@@ -140,32 +140,35 @@ class AutoCapture {
|
|
|
140
140
|
}, 1);
|
|
141
141
|
}
|
|
142
142
|
_pageUnloadHandler() {
|
|
143
|
-
this.
|
|
143
|
+
this._enqueueAutoCapture('page_view_end', (0, Utils_1._getSanitizedPageUrl)(), {
|
|
144
144
|
scrollDepth: this._deepestScroll,
|
|
145
145
|
pageViewLength: Date.now() - this._startTime,
|
|
146
|
-
});
|
|
146
|
+
}, { flushImmediately: true });
|
|
147
147
|
}
|
|
148
|
-
_enqueueAutoCapture(name, value, metadata) {
|
|
149
|
-
this.
|
|
150
|
-
.then((
|
|
148
|
+
_enqueueAutoCapture(name, value, metadata, options) {
|
|
149
|
+
this._getSessionFromClient()
|
|
150
|
+
.then((session) => {
|
|
151
151
|
var _a, _b, _c;
|
|
152
|
+
const logMetadata = Object.assign({ sessionID: session.data.sessionID, page_url: (_c = (_b = (_a = (0, client_core_1._getWindowSafe)()) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.href) !== null && _c !== void 0 ? _c : '' }, metadata);
|
|
153
|
+
if (options === null || options === void 0 ? void 0 : options.addNewSessionMetadata) {
|
|
154
|
+
logMetadata['isNewSession'] = String(Math.abs(session.data.startTime - Date.now()) < 1000);
|
|
155
|
+
}
|
|
152
156
|
const event = {
|
|
153
157
|
eventName: `auto_capture::${name}`,
|
|
154
158
|
value,
|
|
155
|
-
metadata:
|
|
159
|
+
metadata: logMetadata,
|
|
156
160
|
};
|
|
157
161
|
this._client.logEvent(event);
|
|
162
|
+
if (options === null || options === void 0 ? void 0 : options.flushImmediately) {
|
|
163
|
+
this._client.flush().catch((e) => {
|
|
164
|
+
client_core_1.Log.error(e);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
158
167
|
})
|
|
159
168
|
.catch((err) => {
|
|
160
169
|
this._errorBoundary.logError('AC::enqueue', err);
|
|
161
170
|
});
|
|
162
171
|
}
|
|
163
|
-
_logAutoCaptureImmediately(name, value, metadata) {
|
|
164
|
-
this._enqueueAutoCapture(name, value, metadata);
|
|
165
|
-
this._client.flush().catch((e) => {
|
|
166
|
-
client_core_1.Log.error(e);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
172
|
_scrollEventHandler() {
|
|
170
173
|
var _a, _b, _c, _d;
|
|
171
174
|
const scrollHeight = (_b = (_a = (0, client_core_1._getDocumentSafe)()) === null || _a === void 0 ? void 0 : _a.body.scrollHeight) !== null && _b !== void 0 ? _b : 1;
|
|
@@ -174,10 +177,10 @@ class AutoCapture {
|
|
|
174
177
|
const innerHeight = (_d = win === null || win === void 0 ? void 0 : win.innerHeight) !== null && _d !== void 0 ? _d : 1;
|
|
175
178
|
this._deepestScroll = Math.max(this._deepestScroll, Math.min(100, Math.round(((scrollY + innerHeight) / scrollHeight) * 100)));
|
|
176
179
|
}
|
|
177
|
-
|
|
180
|
+
_getSessionFromClient() {
|
|
178
181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
182
|
const x = yield this._client.getAsyncContext();
|
|
180
|
-
return x.
|
|
183
|
+
return x.session;
|
|
181
184
|
});
|
|
182
185
|
}
|
|
183
186
|
}
|