Configuration
Now that the Cookiebot package is installed, we need to add some global configuration to your app.
Don't forget to regenerate the .nuxt folder after installation and .env alteration!
Basic installation
The Cookiebot ID is configured via Nuxt's runtime config, which keeps it out of your build and allows it to be overridden at runtime via environment variables.
nuxt.config.ts
export default defineNuxtConfig({
modules: ["@ambitiondev/nuxt-cookiebot"],
cookiebot: {},
runtimeConfig: {
public: {
cookiebot: {
id: 'COOKIEBOT_ID_HERE',
},
},
},
});
.env usage
Nuxt automatically maps NUXT_PUBLIC_* environment variables to runtimeConfig.public. You can set your Cookiebot ID without touching nuxt.config.ts:
.env
NUXT_PUBLIC_COOKIEBOT_ID=supersecret
The
runtimeConfig.public.cookiebot.id key is automatically registered by the module. You only need to declare it in your config if you want to set a default value.