> ## 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 a Nuxt site

> Add the Radar script to a Nuxt site from nuxt.config.ts, or load it with useHead or a client plugin when the project key comes from runtime config.

In a Nuxt project, the simplest way to install Radar is to declare the script in `nuxt.config.ts`. Nuxt then adds it to the `<head>` of every page. Replace `pk_xxxx` with your project key.

```ts nuxt.config.ts theme={null}
export default defineNuxtConfig({
  app: {
    head: {
      script: [
        {
          src: "https://taap.it/scripts/tracker.js",
          async: true,
          "data-project": "pk_xxxx",
          "data-track-outbound": "true",
          "data-track-forms": "true",
        },
      ],
    },
  },
});
```

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

## Alternative: useHead with runtime config

Use this version when you want to read the project key from an environment variable and skip the script when the key is not set.

First declare the key in the public runtime config. Nuxt replaces the empty value with the `NUXT_PUBLIC_RADAR_PROJECT_KEY` environment variable when it is set.

```ts nuxt.config.ts theme={null}
export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      radarProjectKey: "",
    },
  },
});
```

Then call `useHead` in `app.vue`:

```vue app.vue theme={null}
<script setup lang="ts">
const config = useRuntimeConfig();
const projectKey = config.public.radarProjectKey;

useHead({
  // no script when the key is missing, for example in development
  script: projectKey
    ? [
        {
          src: "https://taap.it/scripts/tracker.js",
          async: true,
          "data-project": projectKey,
          "data-track-outbound": "true",
          "data-track-forms": "true",
          tagPosition: "head",
        },
      ]
    : [],
});
</script>

<template>
  <NuxtPage />
</template>
```

## Alternative: a client plugin

A plugin keeps the script out of `app.vue`. It uses the same runtime config as above. The `.client.ts` suffix tells Nuxt to run the plugin in the browser only, so no `import.meta.client` check is needed.

```ts plugins/radar.client.ts theme={null}
export default defineNuxtPlugin(() => {
  const config = useRuntimeConfig();
  const projectKey = config.public.radarProjectKey;

  if (!projectKey) return;

  useHead({
    script: [
      {
        src: "https://taap.it/scripts/tracker.js",
        async: true,
        "data-project": projectKey,
        "data-track-outbound": "true",
        "data-track-forms": "true",
        tagPosition: "head",
      },
    ],
  });
});
```

## Keep the key out of development

With `useHead` or the plugin, 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.

Set this variable in the environment where your site is built and hosted, and leave it out of your local `.env` file:

```bash theme={null}
NUXT_PUBLIC_RADAR_PROJECT_KEY=pk_xxxx
```

Nuxt does not load a `.env.production` file on its own, so do not rely on one unless your build command points to it.

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