--- title: "UC_CONSENT" slug: "uc-consent" updated: 2026-11-17T03:12:30Z published: 2026-11-17T03:12:30Z canonical: "usercentrics.com/uc-consent" --- > ## Documentation Index > Fetch the complete documentation index at: https://usercentrics.com/docs/llms.txt > Use this file to discover all available pages before exploring further. # UC_CONSENT This event gets triggered when consent changes. ## Trigger scenarios `UC_CONSENT` is dispatched every time the CMP applies a consent state, not only after the user interacts with the banner. In practice this happens: - **On initial page load.** As soon as the CMP initializes, it applies whatever consent state is currently in effect for the visitor and fires `UC_CONSENT` — this includes visitors who already gave consent in a previous session (stored/implicit consent being re-applied) as well as first-time visitors before they interact with the banner at all. This is the case most integrations miss: don't assume the first `UC_CONSENT` you receive always came from a user click. - **When the user gives explicit consent through the banner or Preference Manager**, for example clicking "Accept All", "Deny All", or "Save" after making a granular selection of services/categories in the second layer or the embeddings view. - **When consent is changed programmatically** through the public API, e.g. `window.__ucCmp.acceptAllConsents()`, `denyAllConsents()`, `saveConsents()`, `updateServicesConsents()`, `updateServiceConsent()`, `updateCategoriesConsents()`, or `updateCategoryConsent()`. - **When a previously stored consent session is restored or replaced**, e.g. via Cross Domain Consent Sharing, loading a consent record with a given Controller ID, or WebView User Session Continuity. > [!NOTE] > To tell these cases apart at runtime, inspect `event.detail.consent.fromUserAction`: it's `false` when the event fires on init (including the stored-consent-on-page-load case above), and `true` when it fires from a live user action or API call during the current session. Don't rely on `event.detail.consent.type` (`EXPLICIT`/`IMPLICIT`) for this — that field describes the nature of the underlying consent decision itself, not whether *this event* came from page load or a live interaction: a returning visitor who previously accepted explicitly will still show `type: "EXPLICIT"` on the page-load replay, even though `fromUserAction` is `false` for that event. See [consent_status action values](/v1/docs/consent-status#action) for the full breakdown of what triggered the change. ## Event Detail Structure The `event.detail` that is returned will contain a [ConsentDetails](/v1/docs/interfaces-1#consentdetails) object. Example payload: ```json {  "consent": {    "status": "SOME_ACCEPTED",    "serviceIds": ["HkocEodjb7"],    "required": true,    "version": 1,    "controllerId": "YOUR_CONTROLLER_ID",    "language": "en",    "createdAt": 1750000000000,    "updatedAt": 1750000000000,    "updatedBy": "onUpdateServices",    "setting": {      "id": "YOUR_SETTINGS_ID",      "type": "GDPR",      "version": "1.0.0"    },    "type": "EXPLICIT",    "fromUserAction": true,    "hash": "CONSENT_HASH"  },  "services": {    "HkocEodjb7": {      "name": "Google Analytics",      "version": "1.0.0",      "category": "marketing",      "essential": false,      "consent": {        "given": true,        "type": "EXPLICIT"      }    }  },  "categories": {    "marketing": {      "dps": null,      "essential": false,      "hidden": false,      "name": "Marketing",      "state": "SOME_ACCEPTED"    }  } } ``` See [ConsentDetails](/v1/docs/interfaces-1#consentdetails) for the full type definition of every field, including the nested `ServiceData` and `CategoryData` shapes. ## Example ```javascript window.addEventListener('UC_CONSENT', function (event) {  console.log('UC_CONSENT event detail', event.detail) }); ``` ## Integration Example This example shows how to conditionally load a marketing pixel only once, based on whether consent was given for a specific service — and to remove it again if the user later withdraws consent. Because `UC_CONSENT` also fires on initial page load, this same listener correctly loads the pixel for returning visitors with stored consent, without needing a separate `UC_UI_INITIALIZED` check. ```html ```