Consent Management
Consent API Surface
Consent methods are available after runtime initialization.
getConsentState()grantConsent(categories?)revokeConsent(categories?)
Access by mode:
- CDN:
window.Selwise.* - npm instance:
widget.* - npm global:
window.Selwise.*withexposeGlobal: true - React Native:
sdk.*
Consent Categories
| Category | Meaning |
|---|---|
necessary | Required runtime capability (always true in normal operation). |
analytics | Analytics and attribution event families. |
marketing | Marketing / campaign / ad-oriented signals. |
preferences | Preference and personalization storage. |
Read Current State
const consent = widget.getConsentState();
console.log(consent);
Possible values:
null: no state available yet or data-layer/consent module is disabled.- object: consent category state.
Grant Consent
widget.grantConsent({
analytics: true,
marketing: true,
preferences: true,
});
Revoke Consent
widget.revokeConsent(['marketing', 'preferences']);
If no categories are passed, implementation uses runtime defaults.
Banner Integration Pattern
function onAcceptAll() {
widget.grantConsent({
analytics: true,
marketing: true,
preferences: true,
});
}
function onRejectOptional() {
widget.revokeConsent(['analytics', 'marketing', 'preferences']);
}
function onSavePreferences(input: {
analytics: boolean;
marketing: boolean;
preferences: boolean;
}) {
widget.grantConsent(input);
}
Consent + Event Flow
Recommended sequence:
- initialize Selwise runtime
- read initial consent state
- apply consent UI decision
- start normal event flow
await widget.init({ siteKey: 'YOUR_SITE_KEY', apiUrl: 'https://api.selwise.com/api/v1' });
const initial = widget.getConsentState();
if (!initial?.analytics) {
// keep analytics-gated interactions behind consent UI
}
Verification
- Read initial state.
console.log(widget.getConsentState());
- Grant categories and verify state updates.
- Revoke categories and verify behavior changes.
- Confirm event families are sent/blocked as expected.
React Native-specific check:
- verify consent write calls use a key with
mobile_writescope.
Common Issues
- Consent methods seem undefined.
- runtime is not fully initialized
- calling through global API without
exposeGlobalin npm mode
- Consent state resets unexpectedly.
- storage was cleared
- environment or site context changed
- Consent granted but no event ingestion.
- payload is invalid for canonical event
- siteKey/domain/API configuration mismatch