@statsig/session-replay 0.0.1-beta.27 → 0.0.1-beta.28
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 +2 -2
- package/src/SessionReplay.d.ts +3 -2
- package/src/SessionReplay.js +23 -18
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.28",
|
|
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.28"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@rrweb/types": "2.0.0-alpha.12"
|
package/src/SessionReplay.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
|
|
1
|
+
import { PrecomputedEvaluationsInterface, Visibility } from '@statsig/client-core';
|
|
2
2
|
export declare function runStatsigSessionReplay(client: PrecomputedEvaluationsInterface): void;
|
|
3
3
|
export declare class SessionReplay {
|
|
4
4
|
private _client;
|
|
@@ -7,10 +7,11 @@ export declare class SessionReplay {
|
|
|
7
7
|
private _events;
|
|
8
8
|
private _sessionID;
|
|
9
9
|
constructor(_client: PrecomputedEvaluationsInterface);
|
|
10
|
+
onVisibilityChanged(visibility: Visibility): void;
|
|
10
11
|
private _onRecordingEvent;
|
|
11
12
|
private _attemptToStartRecording;
|
|
12
13
|
private _shutdown;
|
|
13
14
|
private _flushWithSessionID;
|
|
14
15
|
private _logRecordingEvent;
|
|
15
|
-
private
|
|
16
|
+
private _flushAndRefreshSessionID;
|
|
16
17
|
}
|
package/src/SessionReplay.js
CHANGED
|
@@ -21,9 +21,9 @@ class SessionReplay {
|
|
|
21
21
|
instances[sdkKey] = this;
|
|
22
22
|
__STATSIG__.srInstances = instances;
|
|
23
23
|
this._replayer = new SessionReplayClient_1.SessionReplayClient();
|
|
24
|
-
this._client.
|
|
25
|
-
this._client.
|
|
26
|
-
this._client.
|
|
24
|
+
this._client.__on('pre_shutdown', () => this._shutdown());
|
|
25
|
+
this._client.__on('values_updated', () => this._attemptToStartRecording());
|
|
26
|
+
this._client.__on('session_expired', () => {
|
|
27
27
|
this._replayer.stop();
|
|
28
28
|
client_core_1.StatsigMetadataProvider.add({ isRecordingSession: 'false' });
|
|
29
29
|
this._flushWithSessionID(this._sessionID);
|
|
@@ -36,6 +36,7 @@ class SessionReplay {
|
|
|
36
36
|
client_core_1.Log.error(err);
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
+
client_core_1.VisibilityChangeObserver.add(this);
|
|
39
40
|
this._client
|
|
40
41
|
.getAsyncContext()
|
|
41
42
|
.then((context) => {
|
|
@@ -46,26 +47,28 @@ class SessionReplay {
|
|
|
46
47
|
client_core_1.Log.error(err);
|
|
47
48
|
});
|
|
48
49
|
}
|
|
50
|
+
onVisibilityChanged(visibility) {
|
|
51
|
+
if (visibility === 'background') {
|
|
52
|
+
this._flushWithSessionID(this._sessionID);
|
|
53
|
+
this._client.flush().catch((e) => {
|
|
54
|
+
client_core_1.Log.error(e);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
49
58
|
_onRecordingEvent(event, data) {
|
|
50
59
|
this._sessionData = data;
|
|
51
60
|
this._events.push(event);
|
|
52
61
|
const payload = JSON.stringify(this._events);
|
|
53
62
|
if (payload.length > MAX_REPLAY_PAYLOAD_BYTES) {
|
|
54
|
-
this.
|
|
63
|
+
this._flushAndRefreshSessionID();
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
66
|
_attemptToStartRecording() {
|
|
58
|
-
var _a;
|
|
59
67
|
const values = this._client.getContext().values;
|
|
60
68
|
if ((values === null || values === void 0 ? void 0 : values.can_record_session) !== true) {
|
|
61
69
|
this._shutdown();
|
|
62
70
|
return;
|
|
63
71
|
}
|
|
64
|
-
const sampling = (_a = values.session_recording_rate) !== null && _a !== void 0 ? _a : 0;
|
|
65
|
-
if (Math.random() >= sampling) {
|
|
66
|
-
this._shutdown();
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
72
|
if (this._replayer.isRecording()) {
|
|
70
73
|
return;
|
|
71
74
|
}
|
|
@@ -78,19 +81,21 @@ class SessionReplay {
|
|
|
78
81
|
if (this._events.length === 0 || this._sessionData == null) {
|
|
79
82
|
return;
|
|
80
83
|
}
|
|
81
|
-
|
|
82
|
-
this._flush(payload, this._sessionData);
|
|
84
|
+
this._flushAndRefreshSessionID();
|
|
83
85
|
}
|
|
84
86
|
_flushWithSessionID(sessionID) {
|
|
85
87
|
if (this._events.length === 0 || this._sessionData == null) {
|
|
86
88
|
return;
|
|
87
89
|
}
|
|
88
|
-
|
|
89
|
-
const payload = JSON.stringify(this._events);
|
|
90
|
-
this._logRecordingEvent(payload, data, sessionID);
|
|
90
|
+
this._logRecordingEvent(sessionID);
|
|
91
91
|
}
|
|
92
|
-
_logRecordingEvent(
|
|
92
|
+
_logRecordingEvent(sessionID) {
|
|
93
93
|
const { sdkVersion } = client_core_1.StatsigMetadataProvider.get();
|
|
94
|
+
const data = this._sessionData;
|
|
95
|
+
if (data === null || this._events.length === 0) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const payload = JSON.stringify(this._events);
|
|
94
99
|
this._client.logEvent({
|
|
95
100
|
eventName: 'statsig::session_recording',
|
|
96
101
|
value: sessionID,
|
|
@@ -104,11 +109,11 @@ class SessionReplay {
|
|
|
104
109
|
});
|
|
105
110
|
this._events = [];
|
|
106
111
|
}
|
|
107
|
-
|
|
112
|
+
_flushAndRefreshSessionID() {
|
|
108
113
|
this._client
|
|
109
114
|
.getAsyncContext()
|
|
110
115
|
.then((context) => {
|
|
111
|
-
this._logRecordingEvent(
|
|
116
|
+
this._logRecordingEvent(context.sessionID);
|
|
112
117
|
})
|
|
113
118
|
.catch((err) => {
|
|
114
119
|
client_core_1.Log.error(err);
|