Skip to main content
By default, the SDK stores a persistent first-party visitor ID. If your site must get consent before analytics storage (for example, for visitors in the EU), start the SDK in consent mode. Until you call setConsent(true):
  • The SDK reads and writes no cookies and no localStorage.
  • Page views and custom events are still sent, but without anonymous_id, session_id or user_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.
Add data-require-consent="true":
Then call the SDK from your consent banner:
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

  1. Load your site in a private window and open the developer tools.
  2. Before consent, confirm that no ua_ cookie or localStorage key exists, and that POST /v0/events bodies have no anonymous_id.
  3. Grant consent. Confirm that the anonymous-id cookie appears and that later events carry it.
  4. 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.