Choose how visitors are remembered
Set the identity lifetime and consent flow for your website. These choices affect returning visitor counts and attribution.
← All documentationPersistent identity
The default tracker stores a random anonymous ID in localStorage on the current origin when tracking is allowed. Reloads, new tabs and later visits from that browser can share an identity. Other browser profiles and root domains do not automatically share it.
<script defer src="https://YOUR-TRACKER-HOST/track.js" data-site="YOUR_SITE_ID" data-privacy="persistent"></script>
First-party cookie identity
Set data-privacy="cookie" to remember an anonymous visitor ID in a host-only cookie for up to one year. It uses Path=/, SameSite=Lax, and Secure on HTTPS. Browser restrictions may shorten its lifetime. The installation snippet includes data-consent="required": connect your consent banner to betterdata.consent(true) before tracking starts. Revoking consent removes the ID cookie; opt-out also prevents future collection.
Memory-only identity
Set data-privacy="memory" and choose memory mode in website settings. The random ID lasts only for the current page. A reload or new tab can look like a new visitor. Long journeys and delayed revenue attribution become less complete. Memory mode does not create an IP-based daily identifier and cannot use cross-domain identity links.
<script defer src="https://YOUR-TRACKER-HOST/track.js" data-site="YOUR_SITE_ID" data-privacy="memory"></script>
Wait for consent
Use data-consent="required" if your website must wait for a visitor’s choice. The tracker sends nothing before the grant. A saved persistent ID is read only after consent. Revoking clears the pending queue and stored ID; granting again starts a new visitor. Events already accepted by the server remain until handled through your data deletion process.
<script defer src="https://YOUR-TRACKER-HOST/track.js" data-site="YOUR_SITE_ID" data-consent="required"></script>
After your consent UI receives the visitor’s choice, call the matching method:
// In your consent UI’s accept callback: await window.betterdata.ready; await window.betterdata.consent(true); // In its revoke callback: await window.betterdata.consent(false);
Browser opt-out
betterdata.optOut() stops tracking and saves that choice on the current origin for later loads. Open tabs on the same origin also stop. betterdata.optIn() removes the choice and starts a new visitor. The choice is not shared automatically across domains or devices.
betterdata.optOut(); // If the visitor chooses to resume later: await betterdata.optIn();
Do Not Track, Global Privacy Control and the existing betterdata:ignore browser flag stop tracker initialization. Keep your own privacy notice and consent UI aligned with your website’s requirements.