Skip to main content
In an Astro project, the Radar script goes into the layout that wraps all your pages, so it loads everywhere. Replace pk_xxxx with your project key. The is:inline directive tells Astro to leave the tag exactly as written.
src/layouts/BaseLayout.astro
If your site has several layouts, add the tag to each one, or use the component below. 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, or reuse it across several layouts. The component adds the script from the browser. It does nothing when the key is missing or when the script is already on the page.
src/components/RadarTracker.astro
Then use it in the <head> of your layout:
src/layouts/BaseLayout.astro

Keep the key out of development

With the tracker component, store the key in an environment file and leave it empty for development. Without a key, the script is not added to the page, so Radar does not load while you develop.
Astro only exposes variables whose name starts with PUBLIC_ to code that runs in the browser.

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.