Tracking
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
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?
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?"