Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions docs/content/3.nuxt/2.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,48 @@ Don't forget to regenerate the .nuxt folder after installation and .env alterati

## Basic installation

The basic and required configuration can be done as follows:
The Cookiebot ID is configured via Nuxt's [runtime config](https://nuxt.com/docs/guide/going-further/runtime-config), which keeps it out of your build and allows it to be overridden at runtime via environment variables.


::code-group
```ts [Module options nuxt.config.ts]
```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: ["@ambitiondev/nuxt-cookiebot"],
cookiebot: {
cookieBotId: 'COOKIEBOT_ID_HERE',
cookiebot: {},
runtimeConfig: {
public: {
cookiebot: {
id: 'COOKIEBOT_ID_HERE',
},
},
},
});
```
```ts [Inline options nuxt.config.ts]
export default defineNuxtConfig({
modules: [["@ambitiondev/nuxt-cookiebot", {
cookieBotId: 'COOKIEBOT_ID_HERE',
}]]
});
```
::

### .env usage

Nuxt comes with built-in .env support, so you can easily use it like this:
Nuxt automatically maps `NUXT_PUBLIC_*` environment variables to `runtimeConfig.public`. You can set your Cookiebot ID without touching `nuxt.config.ts`:

::code-group
```ts [.env]
COOKIEBOT_ID=supersecret
NUXT_PUBLIC_COOKIEBOT_ID=supersecret
```

```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: ["@ambitiondev/nuxt-cookiebot"],
cookiebot: {
cookieBotId: import.meta.env.COOKIEBOT_ID,
cookiebot: {},
runtimeConfig: {
public: {
cookiebot: {
id: '', // overridden by NUXT_PUBLIC_COOKIEBOT_ID at runtime
},
},
},
});
```
::
::

::alert{type="info"}
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.
::

[api-ref-href]: /api
8 changes: 7 additions & 1 deletion docs/content/3.nuxt/4.advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export default defineNuxtConfig({
cookiebot: {
// disable auto consent banner when overriding with composable
autoConsentBanner: false,
cookieBotId: "COOKIEBOT_ID_HERE",
},
runtimeConfig: {
public: {
cookiebot: {
id: "COOKIEBOT_ID_HERE",
},
},
},
});
```
Expand Down
Loading
Loading