> ## Documentation Index
> Fetch the complete documentation index at: https://docs.molesignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# RUM data sampling

> Control Browser RUM session and replay volume with independent sampling rates and bounded client queues.

The Browser RUM SDK makes a sampling decision during session creation. The decision remains stable
for that browser-tab session.

## Configure sampling rates

```ts theme={null}
const rum = initRum({
  applicationId: 'checkout-web',
  clientToken: 'msrum_your_client_token',
  site: 'https://molesignal.example.com',
  sessionSampleRate: 25,
  sessionReplaySampleRate: 20,
});
```

Both values are percentages from `0` through `100`:

* `sessionSampleRate` controls whether the SDK reports a session and associated RUM events. The default is `100`.
* `sessionReplaySampleRate` applies only after the session is sampled. The default is `0`.

The effective replay rate is the product of both decisions. In the example, approximately 25% of
sessions report RUM data and approximately 5% of all sessions record replay (`25% × 20%`).

<Note>
  Calling `startSessionReplayRecording()` can enable replay for the current sampled session, but the method
  cannot promote a session excluded by `sessionSampleRate`.
</Note>

## Choose initial values

| Traffic profile              | Session rate | Replay rate within sampled sessions |
| ---------------------------- | -----------: | ----------------------------------: |
| Development or controlled QA |        `100` |                               `100` |
| Low-volume production        |        `100` |                           `10`–`25` |
| High-volume production       |    `10`–`50` |                            `1`–`10` |

These are starting points, not universal defaults. Estimate event volume, object storage, retention,
and the number of sessions needed for each browser and release before rollout.

## Session boundaries

The SDK stores the decision in `sessionStorage`. A new session starts after either boundary:

* `sessionInactivityTimeout`: 30 minutes by default;
* `maxSessionDuration`: 4 hours by default.

Both values accept milliseconds. The allowed range is one minute through 24 hours.

```ts theme={null}
sessionInactivityTimeout: 15 * 60_000,
maxSessionDuration: 2 * 60 * 60_000,
```

Changing a sampling option does not change the decision already stored for the current session. Use
a new tab or clear the `molesignal_rum_session_<applicationId>` session-storage entry when testing a
new configuration.

## Bound client-side volume

Use transport controls to keep memory and request sizes predictable:

```ts theme={null}
flushInterval: 5_000,
batchSize: 50,
replayFlushInterval: 10_000,
replayBatchSize: 100,
maxQueueSize: 1_000,
```

Monitor intake rate, replay storage, browser overhead, and investigation coverage after each
change. Roll out sampling changes gradually by application and release.

<CardGroup cols={2}>
  <Card title="Browser RUM SDK" icon="code" href="/en-US/rum/browser-sdk">
    Review all initialization options.
  </Card>

  <Card title="Session replay" icon="video" href="/en-US/rum/session-replay">
    Configure replay collection and storage-sensitive options.
  </Card>
</CardGroup>
