Implement consent-based tag firing in Usercentrics with the Browser SDK event API for a single-page application

domain: docs.usercentrics.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Load the Usercentrics Browser SDK in your SPA entry point: import { UC_UI } from '@usercentrics/cmp-browser-sdk'; UC_UI.init({ settingsId: 'YOUR_SETTINGS_ID' });
  2. Subscribe to consent-change events: UC_UI.getControllersBaseInfo().then((info) => { /* initial state */ }); and window.addEventListener('ucEvent', (e) => { if (e.detail.event === 'consent_status') { handleConsentChange(e.detail); } });
  3. Read per-service consent status programmatically: const services = UC_UI.getServicesBaseInfo(); services.forEach((s) => { if (s.consent.status) { loadTag(s.id); } }); use the service templateId as the key to map to your third-party integrations.
  4. For route changes in an SPA, do not re-initialize the SDK — consent state persists in memory; re-check consent status on route change for any tags that are route-scoped.
  5. To trigger the consent banner programmatically (e.g., after a region-detection check), call UC_UI.showFirstLayer() to display the first layer or UC_UI.showSecondLayer() to open the full service settings.
  6. In a server-side rendering (SSR) context, guard all SDK calls with typeof window !== 'undefined' checks as the Usercentrics SDK is browser-only.

Known gotchas

Related routes

Implement a Didomi consent event to record and retrieve user consent proofs via the Didomi REST API
developers.didomi.io · 6 steps · unrated
Integrate the Osano CMP JavaScript API to read consent status and gate analytics event firing
developers.osano.com · 6 steps · unrated
Implement Google Consent Mode v2 for Google Ads and Analytics tags
advertising · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans