Tracking
Gatsby cookie consent
Wire a cookie banner in Gatsby to analytics: count without cookies until the answer, and pass the saved answer on every page.
Updated
In Gatsby, pass the saved answer with consent() from @nextanalytica/tag when the site starts in the browser, in gatsby-browser, and again when the visitor clicks your banner. Until there's an answer, nextanalytica counts without cookies.
How does it look?
gatsby-browser.tsx
import { consent } from "@nextanalytica/tag";
export const onClientEntry = () => {
const saved = localStorage.getItem("consent"); // "yes", "no" or null
if (saved !== null) consent(saved === "yes");
};What can you ask your agent?
- "How many visitors this week came before answering the banner?"