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

# React Router cookie consent

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

Updated: 2026-12-01

In React Router, pass the saved answer with `consent()` from `@nextanalytica/tag` in an effect in `app/root.tsx`, and again when the visitor clicks your banner. Until there's an answer, nextanalytica counts without cookies.

## How does it look?

```tsx title="app/root.tsx"
import { useEffect } from "react";
import { Analytics } from "@nextanalytica/tag/react";
import { consent } from "@nextanalytica/tag";

export function ConsentFromStorage() {
  useEffect(() => {
    const saved = localStorage.getItem("consent"); // "yes", "no" or null
    if (saved !== null) consent(saved === "yes");
  }, []);
  return <Analytics project="na_…" />;
}
// render <ConsentFromStorage /> inside <body>, next to <Scripts />
```

## What can you ask your agent?

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

## Next steps

- [React Router analytics](/docs/platforms/react-router)
- [Cookieless counting and consent](/docs/tracking/cookieless-and-consent)

Canonical address: https://nextanalytica.app/docs/platforms/react-router/consent
