Api
useScriptTriggerConsent
API documentation for the useScriptTriggerConsent function.
Load a script once consent has been provided either through a resolvable consent
or calling the accept
method.
Signature
function useScriptTriggerConsent(options?: ConsentScriptTriggerOptions): UseConsentScriptTriggerApi {}
Arguments
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.
interface UseConsentScriptTriggerApi extends Promise<void> {
/**
* A function that can be called to accept the consent and load the script.
*/
accept: () => void
}
Example
app.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>