---
title: "useScriptTriggerConsent() · Nuxt Scripts"
description: "Delay a script until the user grants consent."
canonical_url: "https://scripts.nuxt.com/docs/api/use-script-trigger-consent"
meta:
  "og:description": "Delay a script until the user grants consent."
  "og:image": "https://scripts.nuxt.com/_og/s/o_3849d0ffd8ace2af.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "useScriptTriggerConsent() · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_3849d0ffd8ace2af.png"
---

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

**Api**

# **useScriptTriggerConsent()**

[Copy for LLMs](https://scripts.nuxt.com/docs/api/use-script-trigger-consent.md)

Load a script when a resolvable `**consent**` value grants permission or you call `**accept()**`. The `**revoke()**` method updates the reactive consent state; it does not unload a script that has already loaded or cancel a `**postConsentTrigger**` that started after acceptance. A `**Promise<void>**` grants consent when it resolves.

## Signature

```ts
function useScriptTriggerConsent(options?: ConsentScriptTriggerOptions): UseConsentScriptTriggerApi
```

## Arguments

```ts
export interface ConsentScriptTriggerOptions {
  /**
   * An optional reactive (or promise) reference to the consent state. You can use this to accept the consent for scripts
   * instead of using the accept() method.
   */
  consent?: Promise<boolean | void> | Ref<boolean> | ComputedRef<boolean> | boolean
  /**
   * An optional condition to wait for after consent. `onNuxtReady`, a
   * promise-returning function, and callback-style trigger functions are supported.
   */
  postConsentTrigger?: ExcludePromises<NuxtUseScriptOptions['trigger']> | (() => Promise<any>)
}
```

At runtime, `**postConsentTrigger**` supports `**'onNuxtReady'**`, a callback-style function that accepts `**resolve**`, or a zero-argument function that returns a promise. A synchronous zero-argument function never resolves the trigger, even though the wider option type can admit one.

During SSR, the composable returns an unresolved promise with no-op `**accept()**` and `**revoke()**` methods. Consent can only release the load gate in the browser.

## Returns

An extended promise with methods to accept and revoke consent.

```ts
interface UseConsentScriptTriggerApi extends Promise<void> {
  /**
   * A function that can be called to accept the consent and load the script.
   */
  accept: () => void
  /**
   * Revoke consent by setting `consented` to false. This does not unload an
   * already-loaded script.
   */
  revoke: () => void
  /**
   * Reactive reference to the consent state.
   */
  consented: Ref<boolean>
}
```

## Examples

### Basic Usage

app.vue

```vue
<script setup lang="ts">
const trigger = useScriptTriggerConsent()
useScript('https://example.com/script.js', { trigger })
</script>

<template>
  <div v-if="trigger.consented.value">
    <p>Cookies accepted</p>
    <button @click="trigger.revoke">
      Revoke Consent
    </button>
  </div>
  <button v-else @click="trigger.accept">
    Accept Consent
  </button>
</template>
```

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/3.api/3.use-script-trigger-consent.md)

[Markdown For LLMs](https://scripts.nuxt.com/docs/api/use-script-trigger-consent.md)

[**useScript()** Load and control third-party scripts with Nuxt-specific options.](https://scripts.nuxt.com/docs/api/use-script) [**useScriptTriggerElement()** Load a script in response to an element event or visibility change.](https://scripts.nuxt.com/docs/api/use-script-trigger-element)

**On this page **

- [Signature](#signature)
- [Arguments](#arguments)
- [Returns](#returns)
- [Examples](#examples)

```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/api/use-script-trigger-consent#webpage","@type":"WebPage","description":"Delay a script until the user grants consent.","name":"useScriptTriggerConsent()","url":"https://scripts.nuxt.com/docs/api/use-script-trigger-consent","breadcrumb":{"@id":"https://scripts.nuxt.com/docs/api/use-script-trigger-consent#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/docs/api/use-script-trigger-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/api/use-script-trigger-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":"API","item":"https://scripts.nuxt.com/docs/api","position":3},{"@type":"ListItem","name":"useScriptTriggerConsent()","item":"https://scripts.nuxt.com/docs/api/use-script-trigger-consent","position":4}]},{"@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.
