> ## 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 an Angular app

> Add the Radar script to an Angular app through src/index.html, or load it at startup from a service that reads the project key from your environment files.

In an Angular app, the simplest way to install Radar is to paste the script into `src/index.html`. Every screen of the app is served from that one file, so the script loads everywhere. Replace `pk_xxxx` with your project key.

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

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

Do not write an HTML comment inside the tag, next to the attributes: it breaks the script.

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

## Alternative: load it from a service

Use this version when you want to read the project key from your environment files. The service adds the script to the document head. It does nothing when the key is empty or when the script is already on the page.

```typescript src/app/core/radar.service.ts theme={null}
import { DOCUMENT } from '@angular/common';
import { inject, Injectable } from '@angular/core';

@Injectable({ providedIn: 'root' })
export class RadarService {
  private readonly document = inject(DOCUMENT);

  load(projectKey: string): void {
    if (!projectKey) return;
    if (this.document.querySelector('script[data-project]')) return;

    const script = this.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');

    this.document.head.appendChild(script);
  }
}
```

Call the service when the app starts, with `APP_INITIALIZER`. Pick the tab that matches how your app is bootstrapped.

```typescript app.config.ts (standalone) theme={null}
import { ApplicationConfig, APP_INITIALIZER } from '@angular/core';
import { RadarService } from './core/radar.service';
import { environment } from '../environments/environment';

export const appConfig: ApplicationConfig = {
  providers: [
    {
      provide: APP_INITIALIZER,
      useFactory: (radar: RadarService) => () => radar.load(environment.radarProjectKey),
      deps: [RadarService],
      multi: true,
    },
  ],
};
```

```typescript app.module.ts (NgModule) theme={null}
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { RadarService } from './core/radar.service';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [
    {
      provide: APP_INITIALIZER,
      useFactory: (radar: RadarService) => () => radar.load(environment.radarProjectKey),
      deps: [RadarService],
      multi: true,
    },
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}
```

## Keep the key out of development

With the service, store the key in your environment files 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.

```typescript environment.ts theme={null}
export const environment = {
  production: false,
  radarProjectKey: '', // empty: Radar is not loaded locally
};
```

```typescript environment.prod.ts theme={null}
export const environment = {
  production: true,
  radarProjectKey: 'pk_xxxx',
};
```

Both files live in `src/environments`. Their names depend on how your project is set up: projects created with a recent Angular CLI use `environment.development.ts` for development and `environment.ts` for production. Put the empty key in the development file.

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