@spotify-confidence/session-recording 0.0.0 → 0.17.3
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/CHANGELOG.md +52 -0
- package/README.md +155 -0
- package/dist/index.cjs +13324 -0
- package/dist/index.d.cts +103 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +13305 -0
- package/package.json +49 -1
- package/src/flag-observer.test.ts +96 -0
- package/src/flag-observer.ts +32 -0
- package/src/index.test.ts +195 -0
- package/src/index.ts +248 -0
- package/src/version.ts +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.17.3](https://github.com/spotify/confidence-sdk-js/compare/session-recording-v0.17.2...session-recording-v0.17.3) (2026-06-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ✨ New Features
|
|
7
|
+
|
|
8
|
+
* add route parameterization for route change and meta events ([#370](https://github.com/spotify/confidence-sdk-js/issues/370)) ([6efbee0](https://github.com/spotify/confidence-sdk-js/commit/6efbee08776c88b05dfa0949844f6c330bb0bcaa))
|
|
9
|
+
* emit flag evaluations into session recordings ([#369](https://github.com/spotify/confidence-sdk-js/issues/369)) ([3728c6d](https://github.com/spotify/confidence-sdk-js/commit/3728c6d682f97c3b2f18c8979dc91c50328b2345))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* The following workspace dependencies were updated
|
|
15
|
+
* dependencies
|
|
16
|
+
* @spotify-confidence/csr-common bumped to 0.17.3
|
|
17
|
+
* @spotify-confidence/csr-recorder bumped to 0.17.3
|
|
18
|
+
|
|
19
|
+
## [0.17.2](https://github.com/spotify/confidence-sdk-js/compare/session-recording-v0.17.1...session-recording-v0.17.2) (2026-06-15)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### 🐛 Bug Fixes
|
|
23
|
+
|
|
24
|
+
* improve csr package READMEs ([#367](https://github.com/spotify/confidence-sdk-js/issues/367)) ([3c5a254](https://github.com/spotify/confidence-sdk-js/commit/3c5a254b6b7bd23142ffe7ce6d99f327e67ff478))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Dependencies
|
|
28
|
+
|
|
29
|
+
* The following workspace dependencies were updated
|
|
30
|
+
* dependencies
|
|
31
|
+
* @spotify-confidence/csr-common bumped to 0.17.2
|
|
32
|
+
* @spotify-confidence/csr-recorder bumped to 0.17.2
|
|
33
|
+
|
|
34
|
+
## [0.17.1](https://github.com/spotify/confidence-sdk-js/compare/session-recording-v0.17.0...session-recording-v0.17.1) (2026-06-15)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### 🐛 Bug Fixes
|
|
38
|
+
|
|
39
|
+
* add csr packages to release-please ([#363](https://github.com/spotify/confidence-sdk-js/issues/363)) ([f868e03](https://github.com/spotify/confidence-sdk-js/commit/f868e036ee27fcdd26ee26c8a47d2466a47e2a60))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### ✨ New Features
|
|
43
|
+
|
|
44
|
+
* add session recording packages ([#360](https://github.com/spotify/confidence-sdk-js/issues/360)) ([4584f50](https://github.com/spotify/confidence-sdk-js/commit/4584f502f17d01a15390789519c99308797a513d))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Dependencies
|
|
48
|
+
|
|
49
|
+
* The following workspace dependencies were updated
|
|
50
|
+
* dependencies
|
|
51
|
+
* @spotify-confidence/csr-common bumped to 0.17.1
|
|
52
|
+
* @spotify-confidence/csr-recorder bumped to 0.17.1
|
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @spotify-confidence/session-recording
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Browser SDK for recording user sessions with [Confidence](https://confidence.spotify.com). Captures DOM events in real time and streams them to the Confidence backend for analysis.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @spotify-confidence/session-recording
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { initSessionRecorder } from '@spotify-confidence/session-recording';
|
|
17
|
+
|
|
18
|
+
const recorder = initSessionRecorder({
|
|
19
|
+
clientSecret: '<your-client-secret>',
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
That's it. In `automatic` mode (the default), recording begins as soon as a session is established with the backend. The SDK handles sampling, transport, and reconnection automatically.
|
|
24
|
+
|
|
25
|
+
## Privacy: masking and blocking
|
|
26
|
+
|
|
27
|
+
The SDK provides two mechanisms to prevent sensitive content from being captured:
|
|
28
|
+
|
|
29
|
+
**Masking** replaces text content with `•` characters while preserving the layout. The element is still visible in the replay, but the actual text is never sent to the backend.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const recorder = initSessionRecorder({
|
|
33
|
+
clientSecret: '<your-client-secret>',
|
|
34
|
+
maskSelectors: ['.pii', '[data-sensitive]'],
|
|
35
|
+
maskInputs: true, // mask all <input>, <textarea>, and contenteditable values (default: true)
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Blocking** replaces entire subtrees with an empty placeholder. The blocked element's dimensions are preserved, but nothing inside it — text, images, child nodes — is serialized or sent.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const recorder = initSessionRecorder({
|
|
43
|
+
clientSecret: '<your-client-secret>',
|
|
44
|
+
blockSelectors: ['video', '.third-party-widget', '[data-block]'],
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`maskInputs` defaults to `true` — all input values are masked unless you explicitly opt out.
|
|
49
|
+
|
|
50
|
+
## Context
|
|
51
|
+
|
|
52
|
+
Context lets you attach custom dimensions to the recording session. These are sent alongside the auto-collected browser metadata (user agent, OS, viewport, language, timezone) in the session init request. Context serves two purposes: it helps you find and filter recordings later, and the backend uses it to target recordings to specific cohorts of your user population (e.g. only record premium users, or users on a specific build version).
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const recorder = initSessionRecorder({
|
|
56
|
+
clientSecret: '<your-client-secret>',
|
|
57
|
+
targetingKey: 'user-42',
|
|
58
|
+
context: {
|
|
59
|
+
buildVersion: '2.3.1',
|
|
60
|
+
environment: 'production',
|
|
61
|
+
plan: 'premium',
|
|
62
|
+
featureFlags: 'new-checkout-enabled',
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`targetingKey` is the end-user identifier (visitor ID, device ID, etc.). The backend uses it for sampling and targeting decisions — it determines whether this user should be recorded.
|
|
68
|
+
|
|
69
|
+
## Configuration
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const recorder = initSessionRecorder({
|
|
73
|
+
// Required
|
|
74
|
+
clientSecret: '<your-client-secret>',
|
|
75
|
+
|
|
76
|
+
// Identity and context
|
|
77
|
+
targetingKey: 'user-42',
|
|
78
|
+
context: { buildVersion: '2.3.1' },
|
|
79
|
+
|
|
80
|
+
// Privacy
|
|
81
|
+
maskSelectors: ['.pii'],
|
|
82
|
+
blockSelectors: ['video'],
|
|
83
|
+
maskInputs: true, // default: true
|
|
84
|
+
|
|
85
|
+
// Capture options
|
|
86
|
+
captureConsoleLogs: true, // capture browser console output (default: false)
|
|
87
|
+
captureNetworkRequests: false, // capture fetch/XHR metadata (default: false)
|
|
88
|
+
captureRouteChanges: true, // capture client-side route changes (default: true)
|
|
89
|
+
|
|
90
|
+
// Recording mode
|
|
91
|
+
mode: 'automatic', // 'automatic' (default) or 'manual'
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Route parameterization
|
|
96
|
+
|
|
97
|
+
Routes containing dynamic segments (such as IDs in the URL) are automatically normalized into patterns — for example, `/users/123/profile` becomes `/users/:id/profile`. This ensures that per-page metrics are grouped by route rather than by individual page visit, keeping dashboards meaningful and query performance fast.
|
|
98
|
+
|
|
99
|
+
If your app uses URL patterns that aren't automatically detected, you can provide a custom `parameterizeRoute` function to control how routes are grouped:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { defaultParameterizeRoute } from '@spotify-confidence/csr-recorder';
|
|
103
|
+
|
|
104
|
+
const recorder = initSessionRecorder({
|
|
105
|
+
clientSecret: '<your-client-secret>',
|
|
106
|
+
parameterizeRoute: route => {
|
|
107
|
+
return defaultParameterizeRoute(route).replace(/\/teams\/[^/]+/, '/teams/:slug');
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
See the [`@spotify-confidence/csr-recorder` README](../csr-recorder/README.md#route-parameterization) for the full list of default patterns.
|
|
113
|
+
|
|
114
|
+
## Manual mode
|
|
115
|
+
|
|
116
|
+
Use `manual` mode to control when recording starts — useful for gating on user consent or feature flags.
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const recorder = initSessionRecorder({
|
|
120
|
+
clientSecret: '<your-client-secret>',
|
|
121
|
+
mode: 'manual',
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Later, when ready:
|
|
125
|
+
recorder.start();
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Custom tags and measurements
|
|
129
|
+
|
|
130
|
+
Attach metadata to a recording for filtering and analysis.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
recorder.tag('plan', 'premium');
|
|
134
|
+
recorder.measure('checkout_items', 3);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## API
|
|
138
|
+
|
|
139
|
+
### `initSessionRecorder(options): SessionRecorder`
|
|
140
|
+
|
|
141
|
+
Creates a session recorder. Always returns a `SessionRecorder` — safe to call, never throws.
|
|
142
|
+
|
|
143
|
+
### `SessionRecorder`
|
|
144
|
+
|
|
145
|
+
| Method | Description |
|
|
146
|
+
| ---------------------- | -------------------------------------------------------------- |
|
|
147
|
+
| `start()` | Start recording. No-op in automatic mode. |
|
|
148
|
+
| `stop()` | Stop recording permanently. Idempotent. |
|
|
149
|
+
| `tag(key, value?)` | Attach a string tag. Tags with the same key accumulate values. |
|
|
150
|
+
| `measure(key, value?)` | Record a numeric measurement. Same key = summed. |
|
|
151
|
+
| `isRecording` | Whether the recorder is actively capturing events. |
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
Apache 2.0 — see [LICENSE](../../LICENSE).
|