> AI agents: this is one page of nextanalytica's docs. The full index for agents: https://nextanalytica.app/llms.txt

# Docusaurus cookie consent

> Wire a cookie banner in Docusaurus to analytics: count without cookies until the answer, and pass the saved answer on every page.

Updated: 2026-12-01

In Docusaurus, pass your banner's answer to the tag from a client module, which runs in the browser on every page. Until there's an answer, nextanalytica counts without cookies.

## How does it look?

```js title="src/consent.js"
export function onRouteDidUpdate({ previousLocation }) {
  if (previousLocation) return; // first page only
  const saved = localStorage.getItem("consent"); // "yes", "no" or null
  if (saved !== null) window.nextanalytica?.consent(saved === "yes");
}
```

Register it with `clientModules` in `docusaurus.config.js`.

## What can you ask your agent?

- "How many visitors this week came before answering the banner?"

## Next steps

- [Docusaurus analytics](/docs/platforms/docusaurus)
- [Cookieless counting and consent](/docs/tracking/cookieless-and-consent)

Canonical address: https://nextanalytica.app/docs/platforms/docusaurus/consent
