Tracking
TanStack Start cookie consent
Wire a cookie banner in TanStack Start to analytics: count without cookies until the answer, and pass the saved answer on every page.
Updated
In TanStack Start, start the tag once in the browser and pass the saved answer with consent() from @nextanalytica/tag, in an effect in your root route. Until there's an answer, nextanalytica counts without cookies.
How does it look?
src/routes/__root.tsx
import { useEffect } from "react";
import nextanalytica, { consent } from "@nextanalytica/tag";
// inside your root route's component:
useEffect(() => {
nextanalytica.init("na_…");
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?"