---
title: "Consent Management · Nuxt Scripts"
meta:
  "og:description": "Learn how to get user consent before loading scripts."
  "og:title": "Consent Management · Nuxt Scripts"
  description: "Learn how to get user consent before loading scripts."
---

**Guides**

# **Consent Management**

[Copy for LLMs](https://scripts.nuxt.com/docs/guides/consent.md)

Last updated **Mar 5, 2026** by [Harlan Wilton](https://github.com/harlan-zw) in [chore: lint](https://github.com/nuxt/scripts/commit/0f18bea0215cd80ed02811141680cbaf8febee21).

[](https://stackblitz.com/github/nuxt/scripts/tree/main/examples/cookie-consent)Try the live [**Cookie Consent Example**](https://stackblitz.com/github/nuxt/scripts/tree/main/examples/cookie-consent) or [**Granular Consent Example**](https://stackblitz.com/github/nuxt/scripts/tree/main/examples/granular-consent) on [**StackBlitz**](https://stackblitz.com).

## [Background](#background)

Many third-party scripts include tracking cookies that require user consent under privacy laws. Nuxt Scripts simplifies this process with the [`useScriptTriggerConsent()`](https://scripts.nuxt.com/docs/api/use-script-trigger-consent) composable, allowing scripts to load only after you receive user consent.

## [Usage](#usage)

The [`useScriptTriggerConsent()`](https://scripts.nuxt.com/docs/api/use-script-trigger-consent) composable offers flexible interaction options suitable for various scenarios.

See the [**API**](https://scripts.nuxt.com/docs/api/use-script-trigger-consent) docs for full details on the available options.

### [Accepting as a Function](#accepting-as-a-function)

The easiest way to make use of [`useScriptTriggerConsent()`](https://scripts.nuxt.com/docs/api/use-script-trigger-consent) is by invoking the `accept` method when user consent is granted.

For an example of how you might lay out your code to handle this, see the following:

```
export const agreedToCookiesScriptConsent = useScriptTriggerConsent()
```

```
<script setup lang="ts">
import { agreedToCookiesScriptConsent } from '#imports'

useScript('https://www.google-analytics.com/analytics.js', {
  trigger: agreedToCookiesScriptConsent
})
</script>
```

```
<script setup lang="ts">
import { agreedToCookiesScriptConsent } from '#imports'
</script>

<template>
  <button @click="agreedToCookiesScriptConsent.accept()">
    Accept Cookies
  </button>
</template>
```

### [Accepting as a resolvable boolean](#accepting-as-a-resolvable-boolean)

Alternatively, you can pass a reactive reference to the consent state to the [`useScriptTriggerConsent()`](https://scripts.nuxt.com/docs/api/use-script-trigger-consent) composable. This will automatically load the script when the consent state is `true`.

```
const agreedToCookies = ref(false)
useScript('https://www.google-analytics.com/analytics.js', {
  trigger: useScriptTriggerConsent({
    consent: agreedToCookies
  })
})
```

### [Delaying script load after consent](#delaying-script-load-after-consent)

There may be instances where you want to trigger the script load after a certain event, only if the user has consented.

For this you can use the `postConsentTrigger`, which shares the same API as `trigger` from the [`useScript()`](https://scripts.nuxt.com/docs/api/use-script) composable.

```
const agreedToCookies = ref(false)
useScript('https://www.google-analytics.com/analytics.js', {
  trigger: useScriptTriggerConsent({
    consent: agreedToCookies,
    // load 3 seconds after consent is granted
    postConsentTrigger: () => new Promise<void>(resolve =>
      setTimeout(resolve, 3000),
    ),
  })
})
```

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

[Markdown For LLMs](https://scripts.nuxt.com/docs/guides/consent.md)

[**Bundling Remote Scripts** Optimize third-party scripts by bundling them with your app.](https://scripts.nuxt.com/docs/guides/bundling) [**Script Event Page** Learn how to send page events to your analytics provider.](https://scripts.nuxt.com/docs/guides/page-events)

**On this page **

- [Background](#background)
- [Usage](#usage)