Skip to content
Docs menu · Sampling

Features

Sampling: Recording a Share of Visitors

Record a fraction of visitors with sampleRate. AnyReplay decides once per visitor, so a recorded person stays recorded across pages, reloads and later visits.

On a busy site you rarely need every session. sampleRate records a share of visitors — 0.25 records about a quarter of them — and leaves the rest untouched: no snapshot, no requests.

anyreplay('init', { projectKey: 'YOUR_PROJECT_KEY', sampleRate: 0.25 });

Per visitor, not per page

The decision is not a coin flip on each page. The recorder gives each browser a random visitor id, stored in localStorage, and hashes it to a number between 0 and 1. The visitor is recorded when that number is below sampleRate. The same visitor therefore gets the same answer on every page and every later visit, so a recorded journey is whole rather than a set of disconnected fragments.

  • 1 (the default) records everyone; 0 records no one. Values outside 0–1 are rejected with a configuration error.
  • Raising the rate from 0.1 to 0.2 keeps everyone already recorded and adds a further slice; lowering it removes a slice. Visitors do not reshuffle.
  • Where localStorage is unavailable — some privacy modes — the recorder cannot remember the id, so the decision may differ between pages.
  • A sampled-out visitor has status() 'sampled-out', and every call on the handle is a no-op.

React Native

The mobile SDK takes the same option with the same per-visitor rule. Pass a storage such as AsyncStorage so the visitor id survives relaunches; with the default in-memory storage each launch is a new visitor for sampling purposes.

Sampling, caps and plan limits

ControlDecidesWhere
sampleRateWhich visitors are recorded at allIn the page or app, before anything is sent
Session capHow many sessions a project may start per monthAt ingest, on the first chunk
Plan limitsHow many sessions and hours the organisation may record per monthAt ingest, on the first chunk

Sampling spreads recordings evenly across the month. A cap alone records everyone until the cap is reached and then nobody, which biases your recordings towards the start of the month. For steady coverage on a high-traffic site, use a sample rate sized to your monthly allowance and keep a cap as a safety net.

Choosing a rate

Start from the number of sessions you want a month and divide by your monthly visits: 10,000 wanted from 200,000 visits is a rate of 0.05. Check Projects after a week — it shows what each project has recorded this month — and adjust.