Recipes

Copy-paste Session Replay setups - record only certain pages, sample a fraction of traffic, always capture checkout, and mask sensitive data.

Each setup goes inside the session_replay block of your ours('init', ...) call. For every available option, see Configuration.

Note: These options live in your install snippet (or a Tag Manager variable), so changing them is a snippet edit, not a dashboard toggle.


Scope recording to specific pages

Record only the home page

Use when you want to start small and watch one page before rolling out wider.

ours('init', '{cdp_token}', {
  session_replay: {
    token: 'replay_token',
    recordOnPaths: ['/'],
  },
});

Start on the home page, then expand

Use when you're ready to add your blog and landing pages. Add patterns to the allowlist as you grow.

ours('init', '{cdp_token}', {
  session_replay: {
    token: 'replay_token',
    recordOnPaths: ['/', '/blog/*', '/landing/*'],
  },
});

Record everywhere except sensitive routes

Use when you want broad coverage but need to keep recording off account, admin, or checkout pages. excludePaths always wins, so everything else records.

ours('init', '{cdp_token}', {
  session_replay: {
    token: 'replay_token',
    excludePaths: ['/account/*', '/admin/*', '/checkout/*'],
  },
});

Control how many sessions you record

Sample a fraction, but always capture checkout

Use when full recording is more than you need, but you never want to miss a purchase or an error. This records 10% of sessions, plus any session where checkout_started or payment_error fires.

ours('init', '{cdp_token}', {
  session_replay: {
    token: 'replay_token',
    sampleRate: 0.1,
    alwaysRecordEvents: ['checkout_started', 'payment_error'],
  },
});

Record nothing until a key event fires

Use when you only care about specific high-value journeys. Nothing records by default; recording starts the moment a listed event fires.

ours('init', '{cdp_token}', {
  session_replay: {
    token: 'replay_token',
    sampleRate: 0,
    alwaysRecordEvents: ['feature_activated', 'upgrade_clicked'],
  },
});

Note: Path scoping is a hard boundary. If you also set recordOnPaths, an alwaysRecordEvents event will not start recording on a path that's out of scope. Keep the paths where those events fire in the allowlist.


Protect sensitive data

Mask everything on the marketing site, never touch the app

Use when your public site is safe to record with text masked, but your authenticated app should never be captured.

ours('init', '{cdp_token}', {
  session_replay: {
    token: 'replay_token',
    mask_all_text: true,
    recordOnPaths: ['/', '/pricing', '/conditions/*'],
    excludePaths: ['/app/*', '/portal/*'],
  },
});

Capture the page, but mask specific PII fields

Use when you want readable replays for layout and copy analysis, but need to keep fields like email and phone out of the recording.

ours('init', '{cdp_token}', {
  session_replay: {
    token: 'replay_token',
    mask_text_selector: '.email-field, .phone-field, [data-pii]',
  },
});

For the full masking model (global masking, CSS classes, and selector overrides), see Privacy and masking.


Single-page apps

All of the path recipes work in single-page apps. Recording starts and stops automatically as visitors navigate between in-scope and out-of-scope routes, with no page reload required. Each in-scope visit is captured as part of the same session, so a session can contain several recorded segments with gaps where the visitor was off-scope.

Record only the onboarding flow

Use when you run a single-page app and only want to capture the onboarding wizard as visitors move through it.

ours('init', '{cdp_token}', {
  session_replay: {
    token: 'replay_token',
    recordOnPaths: ['/onboarding/*'],
  },
});

Next steps

How is this guide?

On this page