Add a cookie consent banner to a Nuxt site

Cookbook · platform Last verified View raw markdown (for agents)

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 #

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 #

More help #