Tracking
Remix cookie consent
Wire a cookie banner in Remix to analytics: count without cookies until the answer, and pass the saved answer on every page.
Updated
In Remix, pass your banner's answer with consent() from @nextanalytica/tag when the visitor clicks, and on every app start from the answer you saved, in an effect in app/root.tsx. Until there's an answer, nextanalytica counts without cookies.
How does it look?
app/root.tsx
import { useEffect } from "react";
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "@remix-run/react";
import { Analytics } from "@nextanalytica/tag/react";
import { consent } from "@nextanalytica/tag";
export default function App() {
useEffect(() => {
const saved = localStorage.getItem("consent"); // "yes", "no" or null
if (saved !== null) consent(saved === "yes");
}, []);
return (
<html lang="en">
<head><Meta /><Links /></head>
<body>
<Outlet />
<ScrollRestoration />
<Scripts />
<Analytics project="na_…" />
</body>
</html>
);
}What can you ask your agent?
- "How many visitors this week came before answering the banner?"