> ## 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 Vue app

> Add the Radar script to a Vue app through its HTML file, or load it with useHead, vue-meta or a composable when the key comes from an env variable.

In a Vue 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 Vue CLI 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.0" />
    <title>Vue 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="app"></div>
  </body>
</html>
```

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

## Alternative: your head manager

If your app already manages the document head with a library, add the script there. Both examples skip the script when no key is set.

> [tab] Vue 3 (useHead)
>
> With `@unhead/vue` already set up in your app, call `useHead` in your root component:
>
> ```vue src/App.vue theme={null}
> <script setup lang="ts">
> import { useHead } from "@unhead/vue";
>
> const projectKey = import.meta.env.VITE_RADAR_PROJECT_KEY;
>
> useHead({
>   script: projectKey
>     ? [
>         {
>           src: "https://taap.it/scripts/tracker.js",
>           async: true,
>           "data-project": projectKey,
>           "data-track-outbound": "true",
>           "data-track-forms": "true",
>         },
>       ]
>     : [],
> });
> </script>
>
> <template>
>   <RouterView />
> </template>
> ```

> [tab] Vue 2 (vue-meta)
>
> With `vue-meta`, declare the script in the `metaInfo` option of your root component:
>
> ```js src/App.vue (script block) theme={null}
> export default {
>   name: "App",
>   metaInfo() {
>     const projectKey = process.env.VUE_APP_RADAR_PROJECT_KEY;
>
>     return {
>       script: projectKey
>         ? [
>             {
>               src: "https://taap.it/scripts/tracker.js",
>               async: true,
>               "data-project": projectKey,
>               "data-track-outbound": "true",
>               "data-track-forms": "true",
>             },
>           ]
>         : [],
>     };
>   },
> };
> ```

## Alternative: load it from a composable

A composable can add the script to the page when your root component mounts. It does nothing when the key is missing or when the script is already on the page.

```ts src/composables/useRadar.ts theme={null}
import { onMounted } from "vue";

export function useRadar(projectKey?: string) {
  onMounted(() => {
    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);
  });
}
```

Call it once, in your root component:

```vue src/App.vue theme={null}
<script setup lang="ts">
import { useRadar } from "./composables/useRadar";

useRadar(import.meta.env.VITE_RADAR_PROJECT_KEY);
</script>

<template>
  <RouterView />
</template>
```

## Keep the key out of development

With a head manager or the composable, 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}
VITE_RADAR_PROJECT_KEY=
```

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

Vite only exposes variables whose name starts with `VITE_`. With Vue CLI, name the variable `VUE_APP_RADAR_PROJECT_KEY` and read it with `process.env.VUE_APP_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.