Skip to main content

Consent Management

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.* with exposeGlobal: true
  • React Native: sdk.*
CategoryMeaning
necessaryRequired runtime capability (always true in normal operation).
analyticsAnalytics and attribution event families.
marketingMarketing / campaign / ad-oriented signals.
preferencesPreference 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.
widget.grantConsent({
analytics: true,
marketing: true,
preferences: true,
});
widget.revokeConsent(['marketing', 'preferences']);

If no categories are passed, implementation uses runtime defaults.

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);
}

Recommended sequence:

  1. initialize Selwise runtime
  2. read initial consent state
  3. apply consent UI decision
  4. 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

  1. Read initial state.
console.log(widget.getConsentState());
  1. Grant categories and verify state updates.
  2. Revoke categories and verify behavior changes.
  3. Confirm event families are sent/blocked as expected.

React Native-specific check:

  • verify consent write calls use a key with mobile_write scope.

Common Issues

  1. Consent methods seem undefined.
  • runtime is not fully initialized
  • calling through global API without exposeGlobal in npm mode
  1. Consent state resets unexpectedly.
  • storage was cleared
  • environment or site context changed
  1. Consent granted but no event ingestion.
  • payload is invalid for canonical event
  • siteKey/domain/API configuration mismatch