---
title: "useScriptTriggerConsent · Nuxt Scripts"
description: "API documentation for the useScriptTriggerConsent function."
canonical_url: "https://scripts.nuxt.com/docs/v0/api/use-script-trigger-consent"
meta:
  "og:description": "API documentation for the useScriptTriggerConsent function."
  "og:image": "https://scripts.nuxt.com/_og/d/c_Docs%2Ctitle_useScriptTriggerConsent%2Cdescription_API%2Bdocumentation%2Bfor%2Bthe%2BuseScriptTriggerConsent%2Bfunction.%2Cheadline_Api%2Cp_Ii9kb2NzL3YwL2FwaS91c2Utc2NyaXB0LXRyaWdnZXItY29uc2VudCI%2Cs_7fjku3mmytmrLgnN.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/d/c_Docs%2Ctitle_useScriptTriggerConsent%2Cdescription_API%2Bdocumentation%2Bfor%2Bthe%2BuseScriptTriggerConsent%2Bfunction.%2Cheadline_Api%2Cp_Ii9kb2NzL3YwL2FwaS91c2Utc2NyaXB0LXRyaWdnZXItY29uc2VudCI%2Cs_7fjku3mmytmrLgnN.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/v0/api/use-script-trigger-consent.md)

Load a script once consent has been provided either through a resolvable `**consent**` or calling the `**accept**` method.

The trigger by itself does nothing - scripts will only load when consent is granted through either the `**accept()**` method or by providing a `**consent**` option that resolves to `**true**`.

## 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
  /**
   * Should the script be loaded on the `requestIdleCallback` callback. This is useful for non-essential scripts that
   * have already been consented to be loaded.
   */
  postConsentTrigger?: NuxtUseScriptOptions['trigger']
}
```

## Returns

A extended promise api with an `**accept**` method to accept the consent and load the script.

```ts
interface UseConsentScriptTriggerApi extends Promise<void> {
  /**
   * A function that can be called to accept the consent and load the script.
   */
  accept: () => void
}
```

## Examples

### Basic Usage

app.vue

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

<template>
  <button @click="trigger.accept">
    Accept Consent
  </button>
</template>
```

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

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

[**useScript** API documentation for the useScript function.](https://scripts.nuxt.com/docs/v0/api/use-script) [**useScriptTriggerElement** API documentation for the useScriptTriggerElement function.](https://scripts.nuxt.com/docs/v0/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/v0/api/use-script-trigger-consent#webpage","@type":"WebPage","description":"API documentation for the useScriptTriggerConsent function.","name":"useScriptTriggerConsent","url":"https://scripts.nuxt.com/docs/v0/api/use-script-trigger-consent","breadcrumb":{"@id":"https://scripts.nuxt.com/docs/v0/api/use-script-trigger-consent#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/docs/v0/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/v0/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":"V0","item":"https://scripts.nuxt.com/docs/v0","position":3},{"@type":"ListItem","name":"API","item":"https://scripts.nuxt.com/docs/v0/api","position":4},{"@type":"ListItem","name":"useScriptTriggerConsent","item":"https://scripts.nuxt.com/docs/v0/api/use-script-trigger-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.
