# Remix and React Router

URL: https://privacyboard.io/docs/cookie-banner/remix

Last updated 2026-11-22.

Add the Privacyboard cookie banner, privacy policy and cookie policy to a Remix or React Router app, and start analytics only after consent.

In a Remix app, or a React Router app in framework mode, the banner is one plain `<script>` tag, first in the `<head>` of `app/root.tsx`. The privacy policy and cookie policy are pages of your privacy center, linked from the footer. You can let a coding agent do it with one command, or add it by hand.

## The fastest way: one command

From the project's folder:

```bash
npx privacyboard init --site acme.com
```

It reads the package names in `package.json` (never their values), recognises the tools that handle personal data and prints the script, where it goes in a Remix project, the footer links and a link to claim the setup. Coding agents can run it for you: see [Set up with an AI coding agent](/docs/getting-started/set-up-with-an-ai-agent). Nothing goes live until you claim the setup, check the tools found, validate your documents and publish.

If you already have a workspace, take the script from **Cookie banner → Install** instead, and follow the steps below.

## Put the script first in app/root.tsx

Add the tag before `<Meta />` and `<Links />`, so it runs before any other script:

```tsx
export default function App() {
  return (
    <html lang="en">
      <head>
        <script src="https://privacyboard.io/cmp/your-banner-id.js" />
        <Meta />
        <Links />
      </head>
      <body>
        <Outlet />
        <Scripts />
      </body>
    </html>
  );
}
```

If your root uses a `Layout` export, put the tag in its `<head>` the same way. The banner must run before your analytics and advertising code to hold it back.

## Footer links

Link your privacy policy and cookie policy from the footer of every page, and add a link that reopens the banner:

```html
<footer>
  <a href="https://acme.privacyboard.io/privacy-policy">Privacy policy</a>
  <a href="https://acme.privacyboard.io/cookie-policy">Cookie policy</a>
  <a href="#" data-pb-open>Cookie settings</a>
</footer>
```

Use the addresses of your own privacy center, shown in **Privacy center**, or your own domain if you set one up.

## Analytics installed from npm

Tools bundled into your app, such as `posthog-js` or `mixpanel-browser`, do not load a script tag the banner could hold. Start them once their category is allowed, with the `privacyboard` package (`npm i privacyboard`), in a component rendered once in the root:

```tsx
import posthog from 'posthog-js';
import { useWhenAllowed } from 'privacyboard/react';

export function Analytics() {
  useWhenAllowed('analytics', () => posthog.init('your-project-key', { api_host: 'https://eu.i.posthog.com' }));
  return null;
}
```

`useWhenAllowed` runs only in the browser: right away if analytics is already allowed, otherwise when the visitor accepts it.

## Check it

Run the site, open it in a private window and check that the banner appears. Once it is online, run the [site scan](/docs/cookie-banner/site-scan): it shows what your pages contact before a visitor chooses. If your site sends a Content Security Policy, add `https://privacyboard.io` to `script-src` and `connect-src`.

## FAQ

### Does it work with React Router v7?
Yes. React Router in framework mode uses the same `app/root.tsx` with `<Meta />` and `<Links />`: put the script before them.

### Can I add the script through a route meta or links export?
No. Those are rendered after the tags written directly in the head. Write the script tag itself, first.

### Does it slow down navigation between routes?
The banner runs once per page load. Client-side navigation does not reload it.
