Sampling and Event-Triggered Recording
Use sampleRate and alwaysRecordEvents to control which sessions get recorded. Record 10% of traffic and always capture checkout flows.
Sampling and Event-Triggered Recording
Recording every session is expensive and rarely necessary. sampleRate and alwaysRecordEvents let you record a small slice of traffic but still guarantee coverage on the sessions that matter.
sampleRate
sampleRate is a number between 0 and 1 that controls what fraction of sessions are recorded.
1(default) — record every session0.1— record 10% of sessions0— never auto-record (you can still promote sessions viaalwaysRecordEvents)
The sampling decision is made once per session and is sticky for the rest of the session lifetime — a session is either in or out, it doesn't flip mid-flight from random sampling.
ours('init', '{cdp_token}', {
session_replay: {
token: 'replay_token',
sampleRate: 0.1,
},
});alwaysRecordEvents
alwaysRecordEvents is a list of event names that override sampling. When a track event with a matching name fires during a session that was sampled out, recording starts immediately from that point forward.
ours('init', '{cdp_token}', {
session_replay: {
token: 'replay_token',
sampleRate: 0.1,
alwaysRecordEvents: ['checkout', 'purchase', 'error'],
},
});Note: The Ours Privacy Web SDK automatically notifies Session Replay whenever a
trackevent fires, so event-triggered recording works without any additional code on your part.
What gets captured when an event triggers recording
Recording starts at the moment the event fires — events and DOM activity that happened before the trigger are not retroactively captured. If you need to capture the lead-up to a promotion event, set sampleRate higher (e.g., 0.5) and trade off cost for context.
Common patterns
Record 10% of traffic, but always capture checkout and errors
session_replay: {
token: 'replay_token',
sampleRate: 0.1,
alwaysRecordEvents: ['checkout', 'purchase', 'error'],
}Only record sessions with specific events
session_replay: {
token: 'replay_token',
sampleRate: 0,
alwaysRecordEvents: ['checkout'],
}This records no sessions by default. Recording starts the moment a checkout event fires. Cheap, targeted, and useful for funnel debugging.
Record everything during a launch, scale back later
session_replay: {
token: 'replay_token',
sampleRate: 1, // 100% — flip to 0.1 once you have enough data
alwaysRecordEvents: ['checkout', 'signup', 'plan_upgrade'],
}The Web SDK handles replay event notifications and session rotation automatically. You only need to configure sampleRate and alwaysRecordEvents in your session_replay settings.
Next steps
- Configuration — every supported option
How is this guide?