> ## Documentation Index
> Fetch the complete documentation index at: https://docs.taap.it/llms.txt
> Use this file to discover all available pages before exploring further.

# Install Radar on a Next.js site

> Add the Radar script to a Next.js App Router project from the root layout, or through a small component that reads the project key from an env variable.

In a Next.js project that uses the App Router (version 13 and later), the Radar script goes into the root layout, so it loads on every page. Use the `Script` component from `next/script` and replace `pk_xxxx` with your project key.

```tsx src/app/layout.tsx theme={null}
import Script from "next/script";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <head>
        <Script
          src="https://taap.it/scripts/tracker.js"
          data-project="pk_xxxx"
          data-track-outbound="true"
          data-track-forms="true"
        />
      </head>
      <body>{children}</body>
    </html>
  );
}
```

> [!NOTE]
>
> This page covers the App Router only. If your project has no `src` folder, the file is `app/layout.tsx`.

For what each attribute does, see [how the script works](https://docs.taap.it/radar/how-the-script-works.md).

## Alternative: a tracker component

Move the script into its own component when you want to read the project key from an environment variable. The component renders nothing when the key is missing.

```tsx src/components/RadarTracker.tsx theme={null}
import Script from "next/script";

export default function RadarTracker({ projectKey }: { projectKey?: string }) {
  if (!projectKey) return null;

  return (
    <Script
      src="https://taap.it/scripts/tracker.js"
      data-project={projectKey}
      data-track-outbound="true"
      data-track-forms="true"
    />
  );
}
```

Then use it in the root layout:

```tsx src/app/layout.tsx theme={null}
import RadarTracker from "@/components/RadarTracker";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <head>
        <RadarTracker projectKey={process.env.NEXT_PUBLIC_RADAR_PROJECT_KEY} />
      </head>
      <body>{children}</body>
    </html>
  );
}
```

## Keep the key out of development

With the tracker component, set the key for production only. Without a key, the script is not added to the page, so Radar does not load while you develop.

```bash .env.production theme={null}
NEXT_PUBLIC_RADAR_PROJECT_KEY=pk_xxxx
```

If your host manages environment variables for you, set `NEXT_PUBLIC_RADAR_PROJECT_KEY` there instead. Do not define the variable in `.env.local`: Next.js also reads that file for production builds, and it takes priority over `.env.production`.

Next.js only exposes a variable to the browser when its name starts with `NEXT_PUBLIC_`.

## Check that it works

Deploy your site, open the published version, load two pages and click a link. The first event should reach your Radar dashboard within a few seconds. If nothing arrives, follow [check your installation](https://docs.taap.it/help/radar/check-your-installation.md). When the tag is added by JavaScript rather than written in the HTML, it does not show in the raw page source: look for `tracker.js` in the Elements panel of your browser's developer tools instead.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.