How consent mode works
Until you callsetConsent(true):
- The SDK reads and writes no cookies and no
localStorage. - Page views and custom events are still sent, but without
anonymous_id,session_idoruser_id. - These events count toward page view and event totals. They do not count as visitors or sessions, and they do not appear in retention, funnels, user paths or profiles.
- An
identify()call is held in memory and sent when consent is granted.
setConsent(true) creates or restores the persistent visitor ID. setConsent(false) clears all identity storage, drops the user ID, removes identity fields from queued events and discards queued identify events.
The SDK does not store the consent choice. Call setConsent() on each page load, after your consent manager reports the choice.
Enable consent mode
- HTML snippet
- npm
Add Then call the SDK from your consent banner:
data-require-consent="true":setConsent() also works without consent mode. setConsent(false) then turns identity off for that instance.
Opt out
For a visitor who asks not to be tracked at all:Test it
- Load your site in a private window and open the developer tools.
- Before consent, confirm that no
ua_cookie orlocalStoragekey exists, and thatPOST /v0/eventsbodies have noanonymous_id. - Grant consent. Confirm that the
anonymous-idcookie appears and that later events carry it. - Withdraw consent. Confirm that the cookies are removed.
Whether your site needs consent is a decision for you and your legal advisers. Consent mode gives you the technical control.