> ## 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 an Astro site

> Add the Radar script to the base layout of an Astro site, or through a small component that reads the project key from an environment variable.

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.

```astro src/layouts/BaseLayout.astro theme={null}
---
export interface Props {
  title: string;
}
const { title } = Astro.props;
---

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>{title}</title>

    <script
      is:inline
      async
      src="https://taap.it/scripts/tracker.js"
      data-project="pk_xxxx"
      data-track-outbound="true"
      data-track-forms="true"
    ></script>
  </head>
  <body>
    <slot />
  </body>
</html>
```

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](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, 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.

```astro src/components/RadarTracker.astro theme={null}
---
export interface Props {
  projectKey?: string;
}

const { projectKey = "" } = Astro.props;
---

<script is:inline define:vars={{ projectKey }}>
  (function () {
    if (!projectKey) return;
    if (document.querySelector("script[data-project]")) return;

    var s = document.createElement("script");
    s.src = "https://taap.it/scripts/tracker.js";
    s.async = true;
    s.setAttribute("data-project", projectKey);
    s.setAttribute("data-track-outbound", "true");
    s.setAttribute("data-track-forms", "true");
    document.head.appendChild(s);
  })();
</script>
```

Then use it in the `<head>` of your layout:

```astro src/layouts/BaseLayout.astro theme={null}
---
import RadarTracker from "../components/RadarTracker.astro";

export interface Props {
  title: string;
}
const { title } = Astro.props;
---

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>{title}</title>

    <RadarTracker projectKey={import.meta.env.PUBLIC_RADAR_PROJECT_KEY} />
  </head>
  <body>
    <slot />
  </body>
</html>
```

## 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.

```bash .env theme={null}
PUBLIC_RADAR_PROJECT_KEY=
```

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

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](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.