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);const recorder = createRecorder({ projectKey: 'YOUR_PROJECT_KEY', requireConsent: true });
recorder.status(); // 'awaiting-consent'
recorder.consent(true);
recorder.status(); // 'recording'import { init, consent } from '@anyreplay/react-native';
init({ projectKey: 'YOUR_PROJECT_KEY', requireConsent: true });
// when the person agrees — before or after init has finished
consent(true);Before consent is given
- Nothing is stored. The visitor id in
localStorageand the session state insessionStorageare created whenconsent(true)is called, not when the recorder loads. On React Native nothing is written tostorage. - 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
consentdoes. - Nothing is observed. The recording engine is not started and no listeners are attached to the page.
status()isawaiting-consentandsessionId()isnull.flush()andstop()do nothing; afterstop()a laterconsent(true)is ignored.trackandidentifycalls are kept in memory — up to 32 events, and the latest traits — and sent once recording starts. They are dropped if consent is refused.
What consent(true) and consent(false) do
| Call | Effect |
|---|---|
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.
Wiring it to a consent banner
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')));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 afterinitis fine.
Related
- Events tracked while waiting are kept (up to 32) and emitted once recording starts — see custom events.
- An
identifycall 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.