@statsig/session-replay 1.0.0 → 1.0.1
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 +41 -3
- package/package.json +2 -2
- package/src/SessionReplay.d.ts +8 -2
- package/src/SessionReplay.js +23 -15
- package/src/SessionReplayClient.d.ts +3 -1
- package/src/SessionReplayClient.js +4 -4
package/README.md
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<img src="https://github.com/statsig-io/js-client-monorepo/assets/95646168/ae5499ed-20ff-4584-bf21-8857f800d485" />
|
|
3
|
+
<div />
|
|
4
|
+
<a href="https://statsig.com/?ref=gh_jsm">Statsig</a>
|
|
5
|
+
</h1>
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/statsig-io/js-client-monorepo/blob/main/LICENSE">
|
|
9
|
+
<img src="https://img.shields.io/badge/license-ISC-blue.svg?colorA=1b2528&colorB=ccfbc7&style=for-the-badge">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@statsig/js-client">
|
|
12
|
+
<img src="https://img.shields.io/npm/v/@statsig/js-client.svg?colorA=1b2528&colorB=b2d3ff&style=for-the-badge">
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://statsig.com/community?ref=gh_jsm">
|
|
15
|
+
<img src="https://img.shields.io/badge/slack-statsig-brightgreen.svg?logo=slack&colorA=1b2528&colorB=FFF8BA&style=for-the-badge">
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
Statsig helps you move faster with feature gates (feature flags), and/or dynamic configs. It also allows you to run A/B/n tests to validate your new features and understand their impact on your KPIs. If you're new to Statsig, check out our product and create an account at [statsig.com](https://www.statsig.com/?ref=gh_jsm).
|
|
4
20
|
|
|
5
21
|
## Getting Started
|
|
6
22
|
|
|
7
|
-
Read through the [Documentation](https://docs.statsig.com/
|
|
23
|
+
Read through the [Documentation](https://docs.statsig.com/client/javascript-sdk?ref=gh_jsm) or check out the [Samples](samples/).
|
|
24
|
+
|
|
25
|
+
## Packages
|
|
26
|
+
|
|
27
|
+
Clients
|
|
28
|
+
|
|
29
|
+
- [Precomputed Evaluations (Recommended)](packages/js-client/README.md)
|
|
30
|
+
- [On Device Evaluations](packages/js-on-device-eval-client/README.md)
|
|
31
|
+
|
|
32
|
+
Product Bundles
|
|
33
|
+
|
|
34
|
+
- [Session Replay](packages/session-replay/README.md)
|
|
35
|
+
- [Web Analytics](packages/web-analytics/README.md)
|
|
36
|
+
|
|
37
|
+
Framework Specific Bindings
|
|
38
|
+
|
|
39
|
+
- [React](packages/react-bindings/README.md)
|
|
40
|
+
- [React Native](packages/react-native-bindings/README.md)
|
|
41
|
+
- [React Native (Expo)](packages/expo-bindings/README.md)
|
|
42
|
+
|
|
43
|
+
## Community
|
|
44
|
+
|
|
45
|
+
If you need any assitance or just have a question, feel free to reach out to us on [Slack](https://statsig.com/community?ref=gh_jsm).
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/session-replay",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"rrweb": "2.0.0-alpha.12",
|
|
6
|
-
"@statsig/client-core": "1.0.
|
|
6
|
+
"@statsig/client-core": "1.0.1"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@rrweb/types": "2.0.0-alpha.12"
|
package/src/SessionReplay.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
|
|
2
|
-
|
|
2
|
+
import { RRWebConfig } from './SessionReplayClient';
|
|
3
|
+
type SessionReplayOptions = {
|
|
4
|
+
rrwebConfig?: RRWebConfig;
|
|
5
|
+
};
|
|
6
|
+
export declare function runStatsigSessionReplay(client: PrecomputedEvaluationsInterface, options?: SessionReplayOptions): void;
|
|
3
7
|
export declare class SessionReplay {
|
|
4
8
|
private _client;
|
|
9
|
+
private _options?;
|
|
5
10
|
private _replayer;
|
|
6
11
|
private _sessionData;
|
|
7
12
|
private _events;
|
|
8
13
|
private _currentSessionID;
|
|
9
14
|
private _errorBoundary;
|
|
10
|
-
constructor(_client: PrecomputedEvaluationsInterface);
|
|
15
|
+
constructor(_client: PrecomputedEvaluationsInterface, _options?: SessionReplayOptions | undefined);
|
|
11
16
|
private _subscribeToVisibilityChanged;
|
|
12
17
|
private _onVisibilityChanged;
|
|
13
18
|
private _onRecordingEvent;
|
|
@@ -18,3 +23,4 @@ export declare class SessionReplay {
|
|
|
18
23
|
private _bumpSessionIdleTimerAndLogRecording;
|
|
19
24
|
private _getSessionIdFromClient;
|
|
20
25
|
}
|
|
26
|
+
export {};
|
package/src/SessionReplay.js
CHANGED
|
@@ -13,13 +13,14 @@ exports.SessionReplay = exports.runStatsigSessionReplay = void 0;
|
|
|
13
13
|
const client_core_1 = require("@statsig/client-core");
|
|
14
14
|
const SessionReplayClient_1 = require("./SessionReplayClient");
|
|
15
15
|
const MAX_REPLAY_PAYLOAD_BYTES = 2048;
|
|
16
|
-
function runStatsigSessionReplay(client) {
|
|
17
|
-
new SessionReplay(client);
|
|
16
|
+
function runStatsigSessionReplay(client, options) {
|
|
17
|
+
new SessionReplay(client, options);
|
|
18
18
|
}
|
|
19
19
|
exports.runStatsigSessionReplay = runStatsigSessionReplay;
|
|
20
20
|
class SessionReplay {
|
|
21
|
-
constructor(_client) {
|
|
21
|
+
constructor(_client, _options) {
|
|
22
22
|
this._client = _client;
|
|
23
|
+
this._options = _options;
|
|
23
24
|
this._sessionData = null;
|
|
24
25
|
this._events = [];
|
|
25
26
|
const { sdkKey, errorBoundary } = _client.getContext();
|
|
@@ -36,7 +37,7 @@ class SessionReplay {
|
|
|
36
37
|
this._client.on('session_expired', () => {
|
|
37
38
|
this._replayer.stop();
|
|
38
39
|
client_core_1.StatsigMetadataProvider.add({ isRecordingSession: 'false' });
|
|
39
|
-
this._logRecording();
|
|
40
|
+
this._logRecording('session_expired');
|
|
40
41
|
this._currentSessionID = this._getSessionIdFromClient();
|
|
41
42
|
});
|
|
42
43
|
this._subscribeToVisibilityChanged();
|
|
@@ -54,12 +55,13 @@ class SessionReplay {
|
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
_onVisibilityChanged(visibility) {
|
|
57
|
-
if (visibility
|
|
58
|
-
|
|
59
|
-
this._client.flush().catch((e) => {
|
|
60
|
-
this._errorBoundary.logError('SR::visibility', e);
|
|
61
|
-
});
|
|
58
|
+
if (visibility !== 'background') {
|
|
59
|
+
return;
|
|
62
60
|
}
|
|
61
|
+
this._logRecording();
|
|
62
|
+
this._client.flush().catch((e) => {
|
|
63
|
+
this._errorBoundary.logError('SR::visibility', e);
|
|
64
|
+
});
|
|
63
65
|
}
|
|
64
66
|
_onRecordingEvent(event, data) {
|
|
65
67
|
this._sessionData = data;
|
|
@@ -75,6 +77,7 @@ class SessionReplay {
|
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
_attemptToStartRecording() {
|
|
80
|
+
var _a, _b;
|
|
78
81
|
const values = this._client.getContext().values;
|
|
79
82
|
if ((values === null || values === void 0 ? void 0 : values.can_record_session) !== true) {
|
|
80
83
|
this._shutdown();
|
|
@@ -84,7 +87,7 @@ class SessionReplay {
|
|
|
84
87
|
return;
|
|
85
88
|
}
|
|
86
89
|
client_core_1.StatsigMetadataProvider.add({ isRecordingSession: 'true' });
|
|
87
|
-
this._replayer.record((e, d) => this._onRecordingEvent(e, d));
|
|
90
|
+
this._replayer.record((e, d) => this._onRecordingEvent(e, d), (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.rrwebConfig) !== null && _b !== void 0 ? _b : {});
|
|
88
91
|
}
|
|
89
92
|
_shutdown() {
|
|
90
93
|
this._replayer.stop();
|
|
@@ -94,23 +97,24 @@ class SessionReplay {
|
|
|
94
97
|
}
|
|
95
98
|
this._bumpSessionIdleTimerAndLogRecording();
|
|
96
99
|
}
|
|
97
|
-
_logRecording() {
|
|
100
|
+
_logRecording(endReason) {
|
|
98
101
|
if (this._events.length === 0 || this._sessionData == null) {
|
|
99
102
|
return;
|
|
100
103
|
}
|
|
104
|
+
endReason = (0, client_core_1._isUnloading)() ? 'is_leaving_page' : endReason;
|
|
101
105
|
this._currentSessionID
|
|
102
|
-
.then((sessionID) => this._logRecordingWithSessionID(sessionID))
|
|
106
|
+
.then((sessionID) => this._logRecordingWithSessionID(sessionID, endReason))
|
|
103
107
|
.catch((err) => {
|
|
104
108
|
this._errorBoundary.logError('SR::flush', err);
|
|
105
109
|
});
|
|
106
110
|
}
|
|
107
|
-
_logRecordingWithSessionID(sessionID) {
|
|
111
|
+
_logRecordingWithSessionID(sessionID, endReason) {
|
|
108
112
|
const data = this._sessionData;
|
|
109
113
|
if (data === null || this._events.length === 0) {
|
|
110
114
|
return;
|
|
111
115
|
}
|
|
112
116
|
const payload = JSON.stringify(this._events);
|
|
113
|
-
|
|
117
|
+
const event = {
|
|
114
118
|
eventName: 'statsig::session_recording',
|
|
115
119
|
value: sessionID,
|
|
116
120
|
metadata: {
|
|
@@ -120,7 +124,11 @@ class SessionReplay {
|
|
|
120
124
|
rrweb_events: payload,
|
|
121
125
|
session_replay_sdk_version: client_core_1.SDK_VERSION,
|
|
122
126
|
},
|
|
123
|
-
}
|
|
127
|
+
};
|
|
128
|
+
if (endReason) {
|
|
129
|
+
event.metadata[endReason] = 'true';
|
|
130
|
+
}
|
|
131
|
+
this._client.logEvent(event);
|
|
124
132
|
this._events = [];
|
|
125
133
|
}
|
|
126
134
|
_bumpSessionIdleTimerAndLogRecording() {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { eventWithTime } from '@rrweb/types';
|
|
2
|
+
import * as rrweb from 'rrweb';
|
|
2
3
|
import { Flatten } from '@statsig/client-core';
|
|
3
4
|
export type ReplayEvent = Flatten<eventWithTime>;
|
|
5
|
+
export type RRWebConfig = Omit<rrweb.recordOptions<unknown>, 'emit'>;
|
|
4
6
|
export type ReplaySessionData = {
|
|
5
7
|
startTime: number;
|
|
6
8
|
endTime: number;
|
|
@@ -12,7 +14,7 @@ export declare class SessionReplayClient {
|
|
|
12
14
|
private _startTimestamp;
|
|
13
15
|
private _endTimestamp;
|
|
14
16
|
private _clickCount;
|
|
15
|
-
record(callback: (latest: ReplayEvent, data: ReplaySessionData) => void, stopCallback?: () => void): void;
|
|
17
|
+
record(callback: (latest: ReplayEvent, data: ReplaySessionData) => void, config: RRWebConfig, stopCallback?: () => void): void;
|
|
16
18
|
stop(): void;
|
|
17
19
|
isRecording(): boolean;
|
|
18
20
|
}
|
|
@@ -10,7 +10,7 @@ class SessionReplayClient {
|
|
|
10
10
|
this._endTimestamp = null;
|
|
11
11
|
this._clickCount = 0;
|
|
12
12
|
}
|
|
13
|
-
record(callback, stopCallback) {
|
|
13
|
+
record(callback, config, stopCallback) {
|
|
14
14
|
if ((0, client_core_1._getDocumentSafe)() == null) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
@@ -44,7 +44,7 @@ class SessionReplayClient {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
|
-
this._stopFn = _minifiedAwareRecord(emit);
|
|
47
|
+
this._stopFn = _minifiedAwareRecord(emit, config);
|
|
48
48
|
}
|
|
49
49
|
stop() {
|
|
50
50
|
if (this._stopFn) {
|
|
@@ -61,9 +61,9 @@ exports.SessionReplayClient = SessionReplayClient;
|
|
|
61
61
|
* We do a simple concat of rrweb during minification.
|
|
62
62
|
* This function ensures we handle both "npm" and "<script ..>" install options.
|
|
63
63
|
*/
|
|
64
|
-
function _minifiedAwareRecord(emit) {
|
|
64
|
+
function _minifiedAwareRecord(emit, config) {
|
|
65
65
|
const record = typeof rrweb === 'function' ? rrweb : rrweb.record;
|
|
66
|
-
return record({ emit });
|
|
66
|
+
return record(Object.assign(Object.assign({}, config), { emit }));
|
|
67
67
|
}
|
|
68
68
|
function _isClickEvent(event) {
|
|
69
69
|
// we use the raw number so we can support the minified rrweb file.
|