@statsig/web-analytics 1.1.1 → 1.3.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 +18 -1
- package/src/Utils.js +5 -4
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/web-analytics",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "1.
|
|
6
|
-
"@statsig/js-client": "1.
|
|
5
|
+
"@statsig/client-core": "1.3.0",
|
|
6
|
+
"@statsig/js-client": "1.3.0"
|
|
7
7
|
},
|
|
8
8
|
"jsdelivr": "./build/statsig-web-analytics.min.js",
|
|
9
9
|
"type": "commonjs",
|
package/src/AutoCapture.d.ts
CHANGED
|
@@ -10,10 +10,12 @@ export declare class AutoCapture {
|
|
|
10
10
|
private _autoLogEvent;
|
|
11
11
|
private _initialize;
|
|
12
12
|
private _logError;
|
|
13
|
+
private _logSessionStart;
|
|
13
14
|
private _logPageView;
|
|
14
15
|
private _logPerformance;
|
|
15
16
|
private _pageUnloadHandler;
|
|
16
17
|
private _enqueueAutoCapture;
|
|
17
18
|
private _scrollEventHandler;
|
|
19
|
+
private _isNewSession;
|
|
18
20
|
private _getSessionFromClient;
|
|
19
21
|
}
|
package/src/AutoCapture.js
CHANGED
|
@@ -76,6 +76,7 @@ class AutoCapture {
|
|
|
76
76
|
}
|
|
77
77
|
_initialize() {
|
|
78
78
|
this._addEventHandlers();
|
|
79
|
+
this._logSessionStart();
|
|
79
80
|
this._logPageView();
|
|
80
81
|
this._logPerformance();
|
|
81
82
|
}
|
|
@@ -101,6 +102,18 @@ class AutoCapture {
|
|
|
101
102
|
error_str: errorStr,
|
|
102
103
|
});
|
|
103
104
|
}
|
|
105
|
+
_logSessionStart() {
|
|
106
|
+
this._getSessionFromClient()
|
|
107
|
+
.then((session) => {
|
|
108
|
+
if (!this._isNewSession(session)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this._enqueueAutoCapture('session_start', (0, Utils_1._getSanitizedPageUrl)(), { sessionID: session.data.sessionID }, { flushImmediately: true });
|
|
112
|
+
})
|
|
113
|
+
.catch((err) => {
|
|
114
|
+
this._errorBoundary.logError('AC::logSession', err);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
104
117
|
_logPageView() {
|
|
105
118
|
setTimeout(() => {
|
|
106
119
|
const url = (0, Utils_1._getSafeUrl)();
|
|
@@ -152,7 +165,7 @@ class AutoCapture {
|
|
|
152
165
|
var _a, _b, _c;
|
|
153
166
|
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);
|
|
154
167
|
if (options === null || options === void 0 ? void 0 : options.addNewSessionMetadata) {
|
|
155
|
-
logMetadata['isNewSession'] = String(
|
|
168
|
+
logMetadata['isNewSession'] = String(this._isNewSession(session));
|
|
156
169
|
}
|
|
157
170
|
const event = {
|
|
158
171
|
eventName: `auto_capture::${name}`,
|
|
@@ -178,6 +191,10 @@ class AutoCapture {
|
|
|
178
191
|
const innerHeight = (_d = win === null || win === void 0 ? void 0 : win.innerHeight) !== null && _d !== void 0 ? _d : 1;
|
|
179
192
|
this._deepestScroll = Math.max(this._deepestScroll, Math.min(100, Math.round(((scrollY + innerHeight) / scrollHeight) * 100)));
|
|
180
193
|
}
|
|
194
|
+
_isNewSession(session) {
|
|
195
|
+
// within the last second
|
|
196
|
+
return Math.abs(session.data.startTime - Date.now()) < 1000;
|
|
197
|
+
}
|
|
181
198
|
_getSessionFromClient() {
|
|
182
199
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
200
|
const x = yield this._client.getAsyncContext();
|
package/src/Utils.js
CHANGED
|
@@ -6,7 +6,8 @@ function _gatherEventData(target) {
|
|
|
6
6
|
var _a;
|
|
7
7
|
const tagName = target.tagName.toLowerCase();
|
|
8
8
|
const metadata = {};
|
|
9
|
-
const value =
|
|
9
|
+
const value = (0, client_core_1._getCurrentPageUrlSafe)() || '';
|
|
10
|
+
metadata['tagName'] = tagName;
|
|
10
11
|
if (tagName === 'form') {
|
|
11
12
|
metadata['action'] = target.getAttribute('action');
|
|
12
13
|
metadata['method'] = (_a = target.getAttribute('method')) !== null && _a !== void 0 ? _a : 'GET';
|
|
@@ -18,13 +19,13 @@ function _gatherEventData(target) {
|
|
|
18
19
|
metadata['content'] = target.value;
|
|
19
20
|
metadata['inputName'] = target.getAttribute('name');
|
|
20
21
|
}
|
|
21
|
-
if (tagName === 'button') {
|
|
22
|
-
metadata['content'] = (target.textContent || '').trim();
|
|
23
|
-
}
|
|
24
22
|
const anchor = _getAnchorNodeInHierarchy(target);
|
|
25
23
|
if (anchor) {
|
|
26
24
|
metadata['href'] = anchor.getAttribute('href');
|
|
27
25
|
}
|
|
26
|
+
if (tagName === 'button' || anchor) {
|
|
27
|
+
metadata['content'] = (target.textContent || '').trim();
|
|
28
|
+
}
|
|
28
29
|
return { value, metadata };
|
|
29
30
|
}
|
|
30
31
|
exports._gatherEventData = _gatherEventData;
|