> ## 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 in a React app

> Add the Radar script to a React app through its HTML file, or load it from React Helmet or a hook when the project key comes from an env variable.

In a React single-page app, the simplest way to install Radar is to paste the script into the HTML file that hosts your app. Every screen of the app is served from that one file, so the script loads everywhere. Replace `pk_xxxx` with your project key.

The file is `index.html` at the root of a Vite project, and `public/index.html` in a Create React App project.

```html index.html theme={null}
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>React App</title>

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

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

## Alternative: React Helmet

If your app already manages the document head with React Helmet, add the script there. The condition skips the script when no key is set.

```tsx src/App.tsx theme={null}
import { Helmet } from "react-helmet";

const projectKey = process.env.REACT_APP_RADAR_PROJECT_KEY;

export default function App() {
  return (
    <>
      {projectKey && (
        <Helmet>
          <script
            async
            src="https://taap.it/scripts/tracker.js"
            data-project={projectKey}
            data-track-outbound="true"
            data-track-forms="true"
          />
        </Helmet>
      )}

      {/* rest of your app */}
    </>
  );
}
```

## Alternative: load it from a hook

A hook can add the script to the page when your app starts. It does nothing when the key is missing or when the script is already on the page.

```ts src/hooks/useRadar.ts theme={null}
import { useEffect } from "react";

export function useRadar(projectKey?: string) {
  useEffect(() => {
    if (!projectKey) return;
    if (document.querySelector("script[data-project]")) return;

    const script = document.createElement("script");
    script.src = "https://taap.it/scripts/tracker.js";
    script.async = true;
    script.setAttribute("data-project", projectKey);
    script.setAttribute("data-track-outbound", "true");
    script.setAttribute("data-track-forms", "true");

    document.head.appendChild(script);
  }, [projectKey]);
}
```

Call the hook once, at the root of your app:

```tsx src/App.tsx theme={null}
import { useRadar } from "./hooks/useRadar";

export default function App() {
  useRadar(process.env.REACT_APP_RADAR_PROJECT_KEY);

  return <>{/* rest of your app */}</>;
}
```

## Keep the key out of development

With React Helmet or the hook, 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}
REACT_APP_RADAR_PROJECT_KEY=
```

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

Create React App only exposes variables whose name starts with `REACT_APP_`. With Vite, name the variable `VITE_RADAR_PROJECT_KEY` and read it with `import.meta.env.VITE_RADAR_PROJECT_KEY`.

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