Skip to main content
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.
src/app/layout.tsx
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.

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.
src/components/RadarTracker.tsx
Then use it in the root layout:
src/app/layout.tsx

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.
.env.production
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. 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.