Privacyboard

Cookie banner

Nuxt

Add the Privacyboard cookie banner, privacy policy and cookie policy to a Nuxt app through nuxt.config, and start analytics plugins only after consent.

Updated 22 November 20262 min read

In a Nuxt app, the banner is declared once in nuxt.config.ts, as the first script of every page. The privacy policy and cookie policy are pages of your privacy center, linked from the footer. You can let a coding agent do it with one command, or add it by hand.

#The fastest way: one command

From the project's folder:

npx privacyboard init --site acme.com

It reads the package names in package.json (never their values), recognises the tools that handle personal data and prints the script, where it goes in a Nuxt project, the footer links and a link to claim the setup. Coding agents can run it for you: see Set up with an AI coding agent. Nothing goes live until you claim the setup, check the tools found, validate your documents and publish.

If you already have a workspace, take the script from Cookie banner → Install instead, and follow the steps below.

#Declare the script in nuxt.config.ts

Add the script to the app's head with a critical priority, so it is placed before the other scripts:

export default defineNuxtConfig({
  app: {
    head: {
      script: [
        { src: 'https://privacyboard.io/cmp/your-banner-id.js', tagPosition: 'head', tagPriority: 'critical' },
      ],
    },
  },
});

Do not add async or defer: the banner must run before your analytics and advertising code to hold it back.

Link your privacy policy and cookie policy from the footer of every page, and add a link that reopens the banner:

<footer>
  <a href="https://acme.privacyboard.io/privacy-policy">Privacy policy</a>
  <a href="https://acme.privacyboard.io/cookie-policy">Cookie policy</a>
  <a href="#" data-pb-open>Cookie settings</a>
</footer>

Use the addresses of your own privacy center, shown in Privacy center, or your own domain if you set one up.

#Analytics installed from npm

Tools bundled into your app, such as posthog-js, do not load a script tag the banner could hold. Start them once their category is allowed, with the privacyboard package (npm i privacyboard), in a client-only plugin, plugins/analytics.client.ts:

import posthog from 'posthog-js';
import { whenAllowed } from 'privacyboard';

export default defineNuxtPlugin(() => {
  whenAllowed('analytics', () => posthog.init('your-project-key', { api_host: 'https://eu.i.posthog.com' }));
});

The .client suffix keeps it out of server rendering. whenAllowed runs your code right away if analytics is already allowed, otherwise when the visitor accepts it.

#Check it

Run the site, open it in a private window and check that the banner appears. Once it is online, run the site scan: it shows what your pages contact before a visitor chooses. If your site sends a Content Security Policy, add https://privacyboard.io to script-src and connect-src.

#FAQ

#Can I use useHead in a page instead of nuxt.config?

Declare it in nuxt.config.ts so it is on every page from the first render. A tag added by a single page would miss the others.

#Does it work with Nuxt Scripts?

Load the banner itself as a plain script in nuxt.config.ts, not through a loader that delays it. Your other third-party scripts can then wait for consent.

#Does it work with static generation?

Yes. nuxi generate writes the script into every page, and the banner runs in the visitor’s browser.

Privacyboard is a guidance tool, not legal advice. This page describes what the product does today. Found something unclear or out of date? Write to hello@privacyboard.io.