Skip to main content

Consent architecture overview

The DigiWedge CMP keeps consent state in sync across banners, dialogs, drop-in scripts, and tag controllers. Use this reference to decide when to reach for the React helpers versus the vanilla snippet.

Core packages

  • @digiwedge/cmp-consent-core — consent storage, category logic, tag registration helpers, GA4/Meta adapters.
  • @digiwedge/cmp-consent-react<ConsentProvider>, <ConsentBanner>, <ConsentDialog>, CookieSettingsLink for React apps.
  • @digiwedge/cmp-consent-plugin — Nx generator that wires the React helpers into a project template.

Strict defaults deny non-essential categories until the visitor opts in. Security storage stays granted.

React quick start

import { createConsentCore, registerGA4 } from '@digiwedge/cmp-consent-core';
import {
ConsentProvider,
ConsentBanner,
ConsentDialog,
CookieSettingsLink,
} from '@digiwedge/cmp-consent-react';

const consent = createConsentCore({
version: 1,
store: 'localStorage',
geofencing: { eeaRequiresOptIn: true },
});

consent.tags.register({
id: 'ga4',
category: 'analytics',
loader: () => registerGA4({ measurementId: import.meta.env.VITE_GA_ID }),
enabled: false,
});

<ConsentProvider core={consent}>
<App />
<ConsentBanner />
<ConsentDialog />
<CookieSettingsLink />
</ConsentProvider>;

The banner/dialog emit cmp_accept and cmp_reject events before invoking your callbacks, so GTM or custom analytics can react immediately.

Drop-in snippet

<script
src="https://cdn.example.com/cmp/dw-cmp.min.js"
data-site-key="SITE_KEY"
data-config-url="https://cmp-registry.example.com/api"
defer
crossorigin="anonymous"
></script>

The snippet reads remote config, renders the UI, and exposes helpers on window.DWConsent (setAll, open, subscribe).

Consent Mode defaults every storage type to denied. When categories flip to granted, the controller calls gtag('consent', 'update', ...) and notifies registered tag loaders.

consent.subscribe((state) => {
const granted = state.categories.analytics ? 'granted' : 'denied';
window.gtag?.('consent', 'update', { analytics_storage: granted });
});

Register other channels (Meta Pixel, TikTok) with consent.tags.register and share the same subscription handler.

QA helpers

  • The Portal diagnostics page captures the latest decision (dw.cmp.diagnostics in localStorage).
  • E2E tests can set localStorage.setItem('dw.cmp.e2eRegion', 'EU') to force geotargeting.
  • Global Privacy Control support keeps non-essential categories denied whenever navigator.globalPrivacyControl is true.

Need API references? Head to the SDK and API pages in this section for full surface details.