---
title: "Usercentrics · Nuxt Scripts"
description: "Load the Usercentrics CMP v3 and drive useScript consent triggers from UC_UI_CMP_EVENT events."
canonical_url: "https://scripts.nuxt.com/scripts/usercentrics"
meta:
  "og:description": "Load the Usercentrics CMP v3 and drive useScript consent triggers from UC_UI_CMP_EVENT events."
  "og:image": "https://scripts.nuxt.com/_og/s/o_9c5a21b26b5a982c.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Usercentrics · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_9c5a21b26b5a982c.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Scripts**

# **Usercentrics**

[Copy for LLMs](https://scripts.nuxt.com/scripts/usercentrics.md)

[**Usercentrics**](https://usercentrics.com) is a Consent Management Platform (CMP) for recording consent choices and controlling third-party services.

[`**useScriptUsercentrics()**`](https://scripts.nuxt.com/scripts/usercentrics) loads the CMP v3 ("Web CMP") script, types the `**window.__ucCmp**` API, and exposes the `**UC_UI_CMP_EVENT**` changes needed to trigger other registry scripts.

**Usercentrics**

[**View source **](https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/registry/usercentrics.ts)

## Nuxt Config Setup

Add this to your `**nuxt.config.ts**` to load Usercentrics globally. Alternatively you can use the **useScriptUsercentrics** composable for more control.

```
export default defineNuxtConfig({
  scripts: {
    registry: {
      usercentrics: {
        trigger: 'onNuxtReady',
      }
    }
  }
})
```

## useScriptUsercentrics()

The `**useScriptUsercentrics**` composable lets you have fine-grain control over when and how Usercentrics is loaded on your site.

```
const { proxy } = useScriptUsercentrics()
```

Please follow the [**Registry Scripts **](https://scripts.nuxt.com/docs/guides/registry-scripts) guide to learn more about advanced usage.

## Example

Using Usercentrics in a component.

ConversionButton.vue

```
<script setup lang="ts">
const { proxy } = useScriptUsercentrics()

// noop in development, ssr
// just works in production, client
function handleAction() {
  // use proxy methods here
}
</script>

<template>
  <div>
    <button @click="handleAction">
      Send Event
    </button>
  </div>
</template>
```

The composable uses these defaults:

- **Trigger: `**onNuxtReady**`.** The script loads after Nuxt hydration, using the module-wide default.
- **Bundle and proxy: off.** The CMP loads directly from Usercentrics and is not consent-gated.

Access `**ucCmp**` through the proxy, or await `**$script**` when you need the loaded object.

```ts
const { proxy } = useScriptUsercentrics({
  rulesetId: 'your-ruleset-id',
})
function showSettings() {
  proxy.ucCmp.showSecondLayer()
}
```

## Drive consent triggers from Usercentrics

Pair `**consent.onConsentChange(...)**` with [`**useScriptTriggerConsent**`](https://scripts.nuxt.com/docs/api/use-script-trigger-consent) to load any third-party script the moment the user opts in via the Usercentrics banner.

```vue
<script setup lang="ts">
import { ref } from 'vue'

const { consent } = useScriptUsercentrics({
  rulesetId: 'your-ruleset-id',
})

const analyticsGranted = ref(false)

if (import.meta.client) {
  consent.onConsentChange(async (detail) => {
    if (detail.type === 'ACCEPT_ALL' || detail.type === 'SAVE') {
      const details = await window.__ucCmp!.getConsentDetails()
      analyticsGranted.value = !!details?.services?.['your-template-id']?.consent?.status
    }
    else if (detail.type === 'DENY_ALL') {
      analyticsGranted.value = false
    }
  })
}

useScriptGoogleAnalytics({
  id: 'G-XXXXXXX',
  scriptOptions: {
    trigger: useScriptTriggerConsent({ consent: analyticsGranted }),
  },
})
</script>

<template>
  <button @click="consent.showSecondLayer()">
    Privacy settings
  </button>
</template>
```

`**onConsentChange**` returns a teardown function for use with `**onScopeDispose**`. Its callback receives the raw `**UC_UI_CMP_EVENT**` detail, such as `**{ type: 'ACCEPT_ALL' | 'DENY_ALL' | 'SAVE', ... }**`.

## Open the consent UI

Call `**consent.whenReady()**` before the CMP's `**UC_CMP_API_READY**` event when you need to await initialization. The current helper only listens for the next event; it does not detect a CMP that is already ready, so a later call can remain pending. The other `**consent**` helpers call `**window.__ucCmp**` when it is present and otherwise return without doing anything.

```vue
<script setup lang="ts">
const { consent } = useScriptUsercentrics({
  rulesetId: 'your-ruleset-id',
})

async function logConsent() {
  const cmp = await consent.whenReady()
  console.log(await cmp.getConsentDetails())
}
</script>

<template>
  <button @click="consent.showFirstLayer()">
    Show banner
  </button>
  <button @click="consent.acceptAll()">
    Accept all
  </button>
  <button @click="consent.denyAll()">
    Reject all
  </button>
</template>
```

## Auto Blocking

If your Usercentrics ruleset uses **Auto Blocking**, set `**autoblocker: true**` to inject the autoblocker module ahead of the loader:

```ts
useScriptUsercentrics({
  rulesetId: 'your-ruleset-id',
  autoblocker: true,
})
```

Usercentrics requires the autoblocker to run before other service scripts; see its [**direct implementation guide**](https://support.usercentrics.com/hc/en-us/articles/19446626144540-Direct-implementation-and-markup-guide). Because the composable adds this option when it runs on the client, verify the ordering in your rendered app before relying on it for consent enforcement.

`**rulesetId**``string`** required **

Your Usercentrics CMP v3 ruleset ID. Find it in the admin under Implementation; the snippet's \`data-ruleset-id\` value.

`**autoblocker**``boolean` = false

Inject the Usercentrics autoblocker (\`autoblocker.js\`) ahead of the loader. Enable when your ruleset relies on Auto Blocking (vs. Manual Blocking) to gate third-party scripts before consent is granted.

`**language**``string`

Override the language displayed by the CMP UI (BCP-47 code, e.g. \`'en'\`, \`'de'\`).

## Partytown

Do not run Usercentrics under Partytown. Its CMP renders DOM overlays and its `**__ucCmp**` methods are not configured for worker forwarding.

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/usercentrics.md)

[Markdown For LLMs](https://scripts.nuxt.com/scripts/usercentrics.md)

[**Umami Analytics** Load Umami, identify sessions, and inspect or filter event payloads before they are sent.](https://scripts.nuxt.com/scripts/umami-analytics) [**Vercel Analytics** Load Vercel Web Analytics and send page views or custom events.](https://scripts.nuxt.com/scripts/vercel-analytics)

**On this page **

- [Drive consent triggers from Usercentrics](#drive-consent-triggers-from-usercentrics)
- [Open the consent UI](#open-the-consent-ui)
- [Auto Blocking](#auto-blocking)
- [Partytown](#partytown)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/scripts/usercentrics#webpage","@type":"WebPage","description":"Load the Usercentrics CMP v3 and drive useScript consent triggers from UC_UI_CMP_EVENT events.","name":"Usercentrics","url":"https://scripts.nuxt.com/scripts/usercentrics","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/usercentrics#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/usercentrics"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/scripts/usercentrics#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Scripts","item":"https://scripts.nuxt.com/scripts","position":2},{"@type":"ListItem","name":"Usercentrics","item":"https://scripts.nuxt.com/scripts/usercentrics","position":3}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
