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.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
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
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 fortracker.js in the Elements panel of your browser’s developer tools instead.