Use when adding or configuring cookie consent in a Nuxt 4 app with nuxt-cookie-consent (@websideproject/nuxt-cookie-consent) - provides consent categories (cookie and cookieless tracking), the banner/modal/floating-button components, $consent, useRequestConsent, useConsentCookie, and consent-gated script loading via Nuxt Scripts.
Ships in nuxt-cookie-consent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Cookie and cookieless-tracking consent for Nuxt 4. Categories are declared in nuxt.config.ts; the module provides
a banner (shown only when a category needs it), a preferences modal, a floating settings button, a $consent store,
and composables to gate cookies and scripts per category.
kind: 'tracking')useScript + $consent.triggers.<category>)useConsentCookie)useRequestConsent)consentVersion, expiresInDays)consent:changed / consent:granted / consent:revoked hooks), Google Consent Mode v2npm install @websideproject/nuxt-cookie-consent @nuxt/scripts
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@websideproject/nuxt-cookie-consent'],
cookieConsent: {
categories: {
necessary: { readonly: true },
analytics: {
cookies: [{ id: '_ga', descriptionKey: 'cookies.analytics.ga.description', provider: 'Google LLC', duration: '2 years' }],
},
},
},
})
>=4.0.0. @nuxt/scripts is a peer dependency (^1.0.0); the module registers it itself — do NOT add
@nuxt/scripts to modules as well.app.vue or a layout:<template>
<NuxtLayout><NuxtPage /></NuxtLayout>
<CookieConsentBanner />
<CookieConsentModal />
<CookieConsentFab />
</template>
cookieConsent)| Option | Type | Default | Notes |
|---|---|---|---|
categories | Record<string, CategoryOptions> | — | Keys become the category names (ConsentCategory). Always include necessary: { readonly: true }. |
locale / fallbackLocale | string | 'en' | Built-in texts: en, de, es, fr. Switch at runtime with $consent.setLocale(). |
texts | Record<locale, …> | built-in | Deep-merged over the defaults. Placeholders {privacy} / {imprint} become links via linkMap. |
linkMap | Record<string, string> | { privacy: '/privacy-policy', imprint: '/imprint' } | Routes for the text placeholders. |
colors | Partial<ColorOptions> | neutral palette | CSS variables for the default components: background, foreground, primary, primaryForeground, secondary, secondaryForeground, border, borderInput. |
darkColors | Partial<ColorOptions> | false | dark neutral palette | Used instead of colors under a .dark ancestor (Nuxt color mode's class on <html>). false = colors in both modes. |
cookieName | string | 'cookie_consent' | Renaming it makes every visitor decide again. |
consentVersion | string | — | Policy version, stored with the choice (<cookieName>_meta). Changing it asks every visitor again; setting it the first time asks everyone once. |
expiresInDays | number | 365 | A choice older than this is asked again. |
reloadOnRevoke | boolean | true | Reload when a category granted on this page is withdrawn (scripts cannot be unloaded). Also per category. |
googleConsentMode | { mapping, waitForUpdate? } | false | false | mapping: category → Consent Mode type(s). Sends default from the head and update on load and every change, into window.dataLayer. A type is granted only while every category mapped to it is; unmapped types are denied. |
CategoryOptions| Field | Meaning |
|---|---|
readonly | Always on, cannot be toggled (use for necessary). |
kind | 'cookie' (default): modal shows a provider/duration table from cookies[]. 'tracking': a plain toggle + description, no table, cookies[] not needed (cookieless analytics). |
cookies | { id, descriptionKey, provider, duration, requiresBanner? }[] — descriptionKey is a path into texts; provider and duration are a string or one per locale ({ en: '1 year', de: '1 Jahr' }). Deleted when the category is withdrawn; an id ending in * matches by prefix (_ga_*). |
description | Shown in the modal (mainly for kind: 'tracking'); a string or one per locale. Falls back to texts.<locale>.categories.<key>.description. |
requiresBanner | Forces (or suppresses) the first-visit banner for this category. |
defaultEnabled | State before the visitor chooses. |
reloadOnRevoke | Overrides the module option for this category. |
When is the banner shown? Only if some non-readonly category requires it:
kind: 'tracking' → only when requiresBanner: true (default is opt-out: on, no banner).requiresBanner wins; without it, a category with no cookies requires a banner, and a
category with cookies requires one if any cookie has requiresBanner !== false.Default state: necessary on; a kind: 'tracking' category without a banner on (opt-out); everything else off.
defaultEnabled: false on a tracking category = opt-in without a banner (e.g. session replays).
$consent (from useNuxtApp())const { $consent } = useNuxtApp()
$consent.state.value.analytics // boolean per category (Ref<Record<ConsentCategory, boolean>>)
$consent.hasMadeChoice.value // true once a choice is persisted in the consent cookie
$consent.isModalOpen.value = true // open the settings modal
$consent.updateState({ ...$consent.state.value, analytics: true }) // update + persist
$consent.acceptAll() // every category on
$consent.rejectAll() // every non-readonly category off, opt-out tracking included
$consent.consentedAt.value // ms when the stored choice was made, null before
$consent.triggers.analytics // Promise, resolved when the category is granted
$consent.currentLocale.value // current UI locale
$consent.setLocale('de')
| Composable | Use |
|---|---|
useRequestConsent(category) | Promise<boolean>. Resolves true immediately if granted (or 'necessary'); otherwise opens the modal with a context message and resolves with the choice when it closes. |
useConsentCookie<T>(name, category, cookieOptions) | Like useCookie, but the value is only written to the cookie while the category is granted; it is read back once consent is given, and the cookie is deleted when consent is withdrawn. Takes useCookie options (default, maxAge, …). |
useConsentText(key, replacements?) | Localized text as a non-empty array of parts { type: 'string' | 'link', content, href? }, so {privacy}-style placeholders render as links. [0].content for plain strings. |
useConsentLocalized(value) | A provider / duration / description value in the active locale (string as-is; { en, de } by locale, then fallbackLocale). |
useConsentBanner() | { isVisible, acceptAll, rejectAll, customize, colors, darkColors } |
useConsentModal() | { isOpen, categories, localConsentState, openAccordions, contextualMessage, acceptAll, rejectAll, saveSelection, closeModal, toggleAccordion, colors, darkColors } — categories is [key, CategoryOptions][]; contextualMessage is text parts (empty unless opened by useRequestConsent). |
useConsentFab() | { isVisible, openModal, colors, darkColors } — visible once a choice is made, or from the start when no banner is required. |
<script setup lang="ts">
const { $consent } = useNuxtApp()
useScript('https://example.com/analytics.js', { trigger: $consent.triggers.analytics })
</script>
The trigger resolves once, on grant, and is not reset on revoke: useScript cannot unload a script. So withdrawing a
category deletes its declared cookies and reloads the page (reloadOnRevoke). To stop a tracker without a reload,
set reloadOnRevoke: false on the category and stop it in the hook:
// app/plugins/consent-events.client.ts
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.hook('consent:revoked', (category) => { if (category === 'analytics') myTracker.stop() })
})
Runtime hooks, browser only, awaited in order (not fired for the choice restored on load):
consent:changed ({ state, previous, granted, revoked, action: 'acceptAll' | 'rejectAll' | 'save' }),
then consent:granted (category) per granted, consent:revoked (category) per revoked. Cookie deletion and the
reload run after the hooks, even if one throws.
const theme = useConsentCookie<'light' | 'dark'>('theme_preference', 'preferences', { default: () => 'light' })
async function toggleTheme() {
if (await useRequestConsent('preferences')) theme.value = theme.value === 'light' ? 'dark' : 'light'
}
Give such a cookie requiresBanner: false so it does not force the first-visit banner.
Preferences need no first-visit banner: declare their cookies with requiresBanner: false, and ask on first use.
// nuxt.config.ts — Nuxt color mode writes its storage only when the preference changes
colorMode: { storage: 'cookie', storageKey: 'theme_preference' },
const colorMode = useColorMode()
async function toggleColorMode() {
if (!(await useRequestConsent('preferences'))) return // declined: no change, no cookie
colorMode.preference = colorMode.value === 'dark' ? 'light' : 'dark'
}
const { $consent } = useNuxtApp()
const locale = useConsentCookie<'en' | 'de'>('locale_preference', 'preferences', { default: () => 'en' })
watch(locale, v => $consent.setLocale(v ?? 'en'), { immediate: true })
async function switchLanguage(next: 'en' | 'de') {
await useRequestConsent('preferences') // asks only while not granted
locale.value = next // changes either way; written to the cookie only with consent
}
Do NOT use a plain useCookie (or color mode's default localStorage) for these — that stores before consent.
categories: {
necessary: { readonly: true },
analytics: { kind: 'tracking', description: 'Cookieless, anonymous usage statistics.' },
}
The default components are plain CSS (themed by colors, and by darkColors under .dark), registered with negative priority — a component with the
same name in the app (CookieConsentBanner.vue, CookieConsentModal.vue, CookieConsentFab.vue) replaces it.
Build it on the composables above; see references/custom-ui.md.
@nuxt/scripts in modules — the module installs it.texts.<locale>.categories.<key> (name, description) label the modal; add them for custom keys.necessary must be readonly: true; useRequestConsent('necessary') always resolves true.cookie_consent) and cookie_consent_meta are themselves strictly necessary; renaming cookieName resets every visitor.rejectAll, text rejectAllBtn).acceptAll / rejectAll / updateState fire the hooks and the withdrawal; writing $consent.state.value directly does not.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/nuxt-cookie-consent-skills:nuxt-cookie-consentfrom nuxt-cookie-consent-skills
npx claudepluginhub websideproject/nuxt-cookie-consent --plugin nuxt-cookie-consent-skills