@statsig/session-replay 0.0.1-beta.30 → 0.0.1-beta.32
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 +4 -8
- package/package.json +2 -2
- package/src/SessionReplay.d.ts +5 -4
- package/src/SessionReplay.js +38 -38
- package/src/SessionReplayClient.js +2 -1
package/README.md
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Statsig Session Replay
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
Session Replay allows you to record users using your website or product, and play back those recorded sessions. This allows you to better understand how users use your service or website, diagnose problems, and uncover insights that help improve conversion and the overall user experience.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Getting Started
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Running unit tests
|
|
10
|
-
|
|
11
|
-
Run `nx test session-replay` to execute the unit tests via [Jest](https://jestjs.io).
|
|
7
|
+
Read through the [Documentation](https://docs.statsig.com/session-replay/overview) or check out the [Samples](https://github.com/statsig-io/js-client-monorepo/tree/main/samples).
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/session-replay",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.32",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"rrweb": "2.0.0-alpha.12",
|
|
6
|
-
"@statsig/client-core": "0.0.1-beta.
|
|
6
|
+
"@statsig/client-core": "0.0.1-beta.32"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@rrweb/types": "2.0.0-alpha.12"
|
package/src/SessionReplay.d.ts
CHANGED
|
@@ -6,13 +6,14 @@ export declare class SessionReplay {
|
|
|
6
6
|
private _replayer;
|
|
7
7
|
private _sessionData;
|
|
8
8
|
private _events;
|
|
9
|
-
private
|
|
9
|
+
private _currentSessionID;
|
|
10
10
|
constructor(_client: PrecomputedEvaluationsInterface);
|
|
11
11
|
private _onVisibilityChanged;
|
|
12
12
|
private _onRecordingEvent;
|
|
13
13
|
private _attemptToStartRecording;
|
|
14
14
|
private _shutdown;
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
private
|
|
15
|
+
private _logRecording;
|
|
16
|
+
private _logRecordingWithSessionID;
|
|
17
|
+
private _bumpSessionIdleTimerAndLogRecording;
|
|
18
|
+
private _getSessionIdFromClient;
|
|
18
19
|
}
|
package/src/SessionReplay.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.SessionReplay = exports.runStatsigSessionReplay = void 0;
|
|
4
13
|
const client_core_1 = require("@statsig/client-core");
|
|
@@ -13,44 +22,31 @@ class SessionReplay {
|
|
|
13
22
|
this._client = _client;
|
|
14
23
|
this._sessionData = null;
|
|
15
24
|
this._events = [];
|
|
16
|
-
this._sessionID = '';
|
|
17
25
|
const { sdkKey } = _client.getContext();
|
|
18
26
|
this._errorBoundary = new client_core_1.ErrorBoundary(sdkKey);
|
|
19
27
|
(0, client_core_1.monitorClass)(this._errorBoundary, this);
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
if ((0, client_core_1._isBrowserEnv)()) {
|
|
29
|
+
const statsigGlobal = (0, client_core_1._getStatsigGlobal)();
|
|
30
|
+
statsigGlobal.srInstances = Object.assign(Object.assign({}, statsigGlobal.srInstances), { [sdkKey]: this });
|
|
31
|
+
}
|
|
32
|
+
this._currentSessionID = this._getSessionIdFromClient();
|
|
22
33
|
this._replayer = new SessionReplayClient_1.SessionReplayClient();
|
|
23
34
|
this._client.__on('pre_shutdown', () => this._shutdown());
|
|
24
35
|
this._client.__on('values_updated', () => this._attemptToStartRecording());
|
|
25
|
-
|
|
36
|
+
_client.on('session_expired', () => {
|
|
26
37
|
this._replayer.stop();
|
|
27
38
|
client_core_1.StatsigMetadataProvider.add({ isRecordingSession: 'false' });
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
.getAsyncContext()
|
|
31
|
-
.then((context) => {
|
|
32
|
-
this._sessionID = context.sessionID;
|
|
33
|
-
})
|
|
34
|
-
.catch((err) => {
|
|
35
|
-
client_core_1.Log.error(err);
|
|
36
|
-
});
|
|
39
|
+
this._logRecording();
|
|
40
|
+
this._currentSessionID = this._getSessionIdFromClient();
|
|
37
41
|
});
|
|
38
42
|
(0, client_core_1._subscribeToVisiblityChanged)(this._onVisibilityChanged.bind(this));
|
|
39
|
-
this.
|
|
40
|
-
.getAsyncContext()
|
|
41
|
-
.then((context) => {
|
|
42
|
-
this._sessionID = context.sessionID;
|
|
43
|
-
this._attemptToStartRecording();
|
|
44
|
-
})
|
|
45
|
-
.catch((err) => {
|
|
46
|
-
client_core_1.Log.error(err);
|
|
47
|
-
});
|
|
43
|
+
this._attemptToStartRecording();
|
|
48
44
|
}
|
|
49
45
|
_onVisibilityChanged(visibility) {
|
|
50
46
|
if (visibility === 'background') {
|
|
51
|
-
this.
|
|
47
|
+
this._logRecording();
|
|
52
48
|
this._client.flush().catch((e) => {
|
|
53
|
-
|
|
49
|
+
this._errorBoundary.logError('SR::visibility', e);
|
|
54
50
|
});
|
|
55
51
|
}
|
|
56
52
|
}
|
|
@@ -60,10 +56,10 @@ class SessionReplay {
|
|
|
60
56
|
const payload = JSON.stringify(this._events);
|
|
61
57
|
if (payload.length > MAX_REPLAY_PAYLOAD_BYTES) {
|
|
62
58
|
if ((0, client_core_1._isCurrentlyVisible)()) {
|
|
63
|
-
this.
|
|
59
|
+
this._bumpSessionIdleTimerAndLogRecording();
|
|
64
60
|
}
|
|
65
61
|
else {
|
|
66
|
-
this.
|
|
62
|
+
this._logRecording();
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
65
|
}
|
|
@@ -85,15 +81,19 @@ class SessionReplay {
|
|
|
85
81
|
if (this._events.length === 0 || this._sessionData == null) {
|
|
86
82
|
return;
|
|
87
83
|
}
|
|
88
|
-
this.
|
|
84
|
+
this._bumpSessionIdleTimerAndLogRecording();
|
|
89
85
|
}
|
|
90
|
-
|
|
86
|
+
_logRecording() {
|
|
91
87
|
if (this._events.length === 0 || this._sessionData == null) {
|
|
92
88
|
return;
|
|
93
89
|
}
|
|
94
|
-
this.
|
|
90
|
+
this._currentSessionID
|
|
91
|
+
.then((sessionID) => this._logRecordingWithSessionID(sessionID))
|
|
92
|
+
.catch((err) => {
|
|
93
|
+
this._errorBoundary.logError('SR::flush', err);
|
|
94
|
+
});
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
_logRecordingWithSessionID(sessionID) {
|
|
97
97
|
const data = this._sessionData;
|
|
98
98
|
if (data === null || this._events.length === 0) {
|
|
99
99
|
return;
|
|
@@ -112,14 +112,14 @@ class SessionReplay {
|
|
|
112
112
|
});
|
|
113
113
|
this._events = [];
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
.
|
|
122
|
-
|
|
115
|
+
_bumpSessionIdleTimerAndLogRecording() {
|
|
116
|
+
this._currentSessionID = this._getSessionIdFromClient();
|
|
117
|
+
this._logRecording();
|
|
118
|
+
}
|
|
119
|
+
_getSessionIdFromClient() {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
const ctx = yield this._client.getAsyncContext();
|
|
122
|
+
return ctx.sessionID;
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SessionReplayClient = void 0;
|
|
4
4
|
const rrweb = require("rrweb");
|
|
5
|
+
const client_core_1 = require("@statsig/client-core");
|
|
5
6
|
const TIMEOUT_MS = 1000 * 60 * 60 * 4; // 4 hours
|
|
6
7
|
class SessionReplayClient {
|
|
7
8
|
constructor() {
|
|
@@ -10,7 +11,7 @@ class SessionReplayClient {
|
|
|
10
11
|
this._clickCount = 0;
|
|
11
12
|
}
|
|
12
13
|
record(callback, stopCallback) {
|
|
13
|
-
if (
|
|
14
|
+
if ((0, client_core_1._getDocumentSafe)() == null) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
17
|
// Always reset session id and tracking fields for a new recording
|