Add a cookie consent banner to a Nuxt site
In short: paste the live snippet as the first entries of app.head.script in nuxt.config.ts, as plain synchronous scripts (no async or defer on any entry in that array).
You need #
- A Cookie Compliance AppID and the live snippet from MCP
install.getSnippetor dashboard Integrations → Manual Integration (a new app uses/v2/hu-banner.min.js; an existing app keeps the URL in that snippet). A domain added in the dashboard is published automatically; if the status check still says the app is not published yet, or after later edits, click Publish Now, then copy the snippet. A snippet copied before publishing must be copied again. No account yet? Sign up (free plan, no card); with MCP, callhelp.startSignup. - Edit access to
nuxt.config.ts.
Where it goes #
Put the live snippet in app.head.script in nuxt.config.ts. This is resolved at server-render time and lands in the initial HTML response, the same way a root layout's <head> does in other frameworks.
// nuxt.config.ts
export default defineNuxtConfig({
app: {
head: {
script: [
{
innerHTML: 'var huOptions = { "appID": "YOUR_APP_ID", "currentLanguage": "en", "blocking": true, "globalCookie": false };',
type: 'text/javascript'
},
{
src: 'https://cdn.hu-manity.co/v2/hu-banner.min.js',
// A new app. If the live snippet has no /v2/, the app is on v1 — keep that URL.
type: 'text/javascript'
},
// Existing trackers stay below, unchanged:
{ src: 'https://www.googletagmanager.com/gtag/js?id=YOUR_GA_ID' }
]
}
}
})
Prefer pasting the exact HTML string's two pieces (the huOptions object and the CDN src) from MCP/dashboard rather than retyping huOptions keys by hand: the live snippet may carry Consent Mode defaults, blockingEngine, or custom providers you would otherwise miss.
If the snippet is currently in a useHead() call or a .client.ts plugin, move it to app.head.script in nuxt.config.ts.
What the order controls #
The banner holds recognised trackers that load after it until the visitor chooses, in regions whose rule requires consent first. A script placed above the snippet runs straight away, and a script you mark data-hu-category="1" is treated as essential. What runs before consent is your decision, so keep analytics and pixels below the snippet.
Confirm the result #
Run verify-install (skills/verify-install/SKILL.md) against the running site: banner shows, no tracking cookies before the visitor chooses in a region whose rule requires consent first, trackers start after Allow. Test from a region your strictest rule covers (for example the EU), or confirm region rules are off. Nuxt-specific extra:
| # | Check | Result |
|---|---|---|
| N1 | View source (not devtools' rendered DOM) on / and an inner route |
huOptions and the hu-banner.min.js (or /v2/…) tag are the first two <script> tags, in that order, with no async/defer. |
| N2 | Grep app.head.script in nuxt.config.ts |
Every entry, Cookie Compliance's and your trackers', is a plain synchronous script without async or defer. |
Gotchas #
- Leave out
asyncanddeferinapp.head.script. Nuxt's head manager (unhead) moves an entry markedasync: trueahead of entries listed earlier, including a synchronous Cookie Compliance snippet. Plain entries (noasyncordefer) render in the order you wrote them. Check the order with View Source of the response. - Use the static config for the banner.
app.headinnuxt.config.tsrenders into the initial HTML.useHead()inside a page or component runs as part of that component's setup, after the config entries, so it suits page-specific tags; the banner belongs in the static config. - Keep the banner out of
.client.tsplugins. A.client.tsplugin runs in the browser after hydration, whileapp.head.scriptis in the server-rendered HTML. - Engine switch: re-paste the live snippet when
widgetVersionchanges in the dashboard;nuxt.config.tsdoes not auto-update.
More help #
- Where to put the Cookie Compliance snippet — the placement rule for every platform, for the site owner.
- Banner not displayed — what to check when the banner does not show.