Skip to content
Docs menu · Consent

Features

Recording Only After Consent

Wait for consent before AnyReplay records anything: requireConsent, consent(true) and consent(false), and wiring the recorder to a cookie or consent banner.

With requireConsent: true the recorder loads and does nothing — no snapshot, no events, no requests, and nothing written to the visitor's browser or device — until you call consent(true). Whether you need consent, and for whom, is a decision for you and your legal advice; this page is about making the recorder follow that decision exactly.

Turning it on

anyreplay('init', { projectKey: 'YOUR_PROJECT_KEY', requireConsent: true });

// when the visitor agrees
anyreplay('consent', true);
  • Nothing is stored. The visitor id in localStorage and the session state in sessionStorage are created when consent(true) is called, not when the recorder loads. On React Native nothing is written to storage.
  • Nothing is read as consent. An id left by an earlier visit does not start recording — it may predate a refusal. Only your call to consent does.
  • Nothing is observed. The recording engine is not started and no listeners are attached to the page.
  • status() is awaiting-consent and sessionId() is null. flush() and stop() do nothing; after stop() a later consent(true) is ignored.
  • track and identify calls are kept in memory — up to 32 events, and the latest traits — and sent once recording starts. They are dropped if consent is refused.
CallEffect
consent(true)Creates the visitor id and session, then starts recording from this moment: a full snapshot, then events. Nothing from before the call is recorded, apart from up to 32 queued track events.
consent(false)Removes the visitor id and session state from storage — whether this page wrote them or an earlier visit did — and drops the queued events. If the recorder was recording, it stops for the rest of this page (or app session); anything already sent stays in the session. If it had not started, it keeps waiting, so a consent(true) later on the same page starts recording, as a new visitor. (Before 0.2.0 it stayed stopped until the next page load.)

With requireConsent, sampling is decided when consent is granted rather than when the page loads. It is still decided from the visitor id, so the answer holds across pages and visits; a visitor who refuses is forgotten, so a later acceptance is a fresh draw.

Every consent management platform offers the same two hooks: a way to read the stored choice when the page loads, and an event when the choice changes. Connect both.

anyreplay('init', { projectKey: 'YOUR_PROJECT_KEY', requireConsent: true });

function applyChoice(allowed) {
  anyreplay('consent', allowed);
}

// 1. On load: the visitor may have decided on an earlier visit.
if (bannerHasStoredChoice()) applyChoice(bannerAllows('analytics'));

// 2. When the visitor decides or changes their mind.
onBannerChoiceChanged(() => applyChoice(bannerAllows('analytics')));
A generic pattern — replace the two functions with your banner's API.

Which category session replay belongs to — analytics, performance, statistics — depends on how your banner is configured; use the one your privacy policy describes it under.

With Google Tag Manager you can do the same without code on the page: keep the AnyReplay tag on All Pages with requireConsent: true, and add a second Custom HTML tag that runs anyreplay('consent', true), triggered by your consent platform's "analytics granted" trigger.

Frameworks

  • Next.js — a client component exports setRecordingConsent(granted) for the banner.
  • React and Vue — export the handle from a module and call recorder.consent(true) from the banner's accept handler.
  • Expo and React Native — store the choice yourself, for example in AsyncStorage, and call consent(true) on launch; right after init is fine.
  • Events tracked while waiting are kept (up to 32) and emitted once recording starts — see custom events.
  • An identify call made while waiting is held and sent once recording starts — see identify users.
  • Masking applies whether or not consent is required — see masking and blocking.