Web SDK · v0.6.0
Consent
Connect RTN to your consent manager, manage purpose-level decisions, and pause collection without losing identity.
Initial state
The SDK resolves the starting decision in this order:
- The
consentoption passed tortn.init(your consent manager wins and the value is stored). - The visitor's previous decision on this site, stored as
rtn_consent. grantedwhen neither exists.
If a consent manager must decide first, initialize with consent: 'pending':
rtn.init('WRITE_KEY', { consent: 'pending' });While consent is pending, nothing is sent and no cookie or localStorage entry is written. Events wait in memory.
Record the visitor's decision
// Call after the visitor accepts analytics cookies.
rtn.setConsent('granted');
// Call after refusal or withdrawal.
rtn.setConsent('denied');grantedreleases buffered events with their original timestamps.denieddeletes the anonymous ID, user ID, attribution data, and the queues of every open tab. Other tabs stop immediately.pendingresets the decision while your consent manager asks again.
The decision is shared across tabs and reused on later page loads. Call rtn.setConsent(...) from your consent banner's callback; do not infer consent from a page view or button impression.
Purpose-level consent
setConsent(state) is a shortcut for the analytics purpose, which gates all collection. SDK 0.5.0 and later also store separate decisions for other purposes and attaches a snapshot to every event:
| Purpose | Use |
|---|---|
analytics | Main gate for event collection |
personalization | On-site personalization |
advertising | Ad measurement |
audiences | Audience and ad activation |
replay | Session replay |
rtn.setConsentPurpose('advertising', 'granted');
rtn.setConsentPurpose('personalization', 'denied');
rtn.getConsentPurpose('advertising'); // 'granted'Purposes other than analytics default to pending. Each event carries the snapshot taken when it was created:
"consent": {
"analytics": "granted",
"personalization": "denied",
"advertising": "granted",
"audiences": "pending",
"replay": "pending"
}The snapshot is not a legal consent record on its own. Services that activate data for a purpose must check that purpose and your server-side consent evidence.
Pause instead of revoking
Use pause() for a temporary operational stop, for example during an internal QA session. It keeps identities and already queued events. Calls made while paused are dropped.
rtn.pause();
// ...
rtn.resume();Use setConsent('denied') only when the visitor withdraws consent.