---
title: "Consent Management · Nuxt Scripts"
description: "Learn how to get user consent before loading scripts."
canonical_url: "https://scripts.nuxt.com/docs/v0/guides/consent"
meta:
  "og:description": "Learn how to get user consent before loading scripts."
  "og:image": "https://scripts.nuxt.com/_og/d/c_Docs%2Ctitle_Consent%2BManagement%2Cdescription_Learn%2Bhow%2Bto%2Bget%2Buser%2Bconsent%2Bbefore%2Bloading%2Bscripts.%2Cheadline_Guides%2Cp_Ii9kb2NzL3YwL2d1aWRlcy9jb25zZW50Ig%2Cs_Eh5vwm3UkIZqMzuE.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Consent Management · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/d/c_Docs%2Ctitle_Consent%2BManagement%2Cdescription_Learn%2Bhow%2Bto%2Bget%2Buser%2Bconsent%2Bbefore%2Bloading%2Bscripts.%2Cheadline_Guides%2Cp_Ii9kb2NzL3YwL2d1aWRlcy9jb25zZW50Ig%2Cs_Eh5vwm3UkIZqMzuE.png"
---

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

**Guides**

# **Consent Management**

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

## 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/v0/api/use-script-trigger-consent) composable, allowing scripts to be loaded only after receiving user consent.

## Usage

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

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

### Accepting as a Function

The easiest way to make use of `**useScriptTriggerConsent**` 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:

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

### Accepting as a resolvable boolean

Alternatively, you can pass a reactive reference to the consent state to the `**useScriptTriggerConsent**` composable. This will automatically load the script when the consent state is `**true**`.

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

### 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**` composable.

```ts
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/0.x/docs/content/1.guides/3.consent.md)

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

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

**On this page **

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

```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/docs/v0/guides/consent#webpage","@type":"WebPage","description":"Learn how to get user consent before loading scripts.","name":"Consent Management","url":"https://scripts.nuxt.com/docs/v0/guides/consent","breadcrumb":{"@id":"https://scripts.nuxt.com/docs/v0/guides/consent#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/docs/v0/guides/consent"]}],"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/docs/v0/guides/consent#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Documentation","item":"https://scripts.nuxt.com/docs","position":2},{"@type":"ListItem","name":"V0","item":"https://scripts.nuxt.com/docs/v0","position":3},{"@type":"ListItem","name":"Guides","item":"https://scripts.nuxt.com/docs/v0/guides","position":4},{"@type":"ListItem","name":"Consent Management","item":"https://scripts.nuxt.com/docs/v0/guides/consent","position":5}]},{"@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.
