> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openrevenue.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Angular installation

> Install OpenRevenue analytics in Angular through index.html or an Angular service.

## Via index.html

The quickest way: add the script to `src/index.html` before `</body>`:

```html src/index.html theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>My App</title>
    <base href="/" />
  </head>
  <body>
    <app-root></app-root>

    <script
      src="https://api.openrevenue.com/tracker.js"
      data-site="your-project-id"
      defer
    ></script>
  </body>
</html>
```

## Via service

For more control, inject the tracker from your root `AppComponent`:

```ts src/app/app.component.ts theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
import { Component, OnInit, Inject, PLATFORM_ID } from "@angular/core"
import { isPlatformBrowser } from "@angular/common"

@Component({
  selector: "app-root",
  template: "<router-outlet />",
})
export class AppComponent implements OnInit {
  constructor(@Inject(PLATFORM_ID) private platformId: object) {}

  ngOnInit() {
    if (isPlatformBrowser(this.platformId)) {
      const script = document.createElement("script")
      script.src = "https://api.openrevenue.com/tracker.js"
      script.dataset["site"] = "your-project-id"
      script.defer = true
      document.head.appendChild(script)
    }
  }
}
```

> [!NOTE]
>
> The `isPlatformBrowser` guard makes this SSR-safe if you use Angular Universal.

## Verify

Deploy and open your app in a browser. Check your [OpenRevenue dashboard](https://www.openrevenue.com/dashboard): a pageview should appear within seconds.

> [!NOTE]
>
> OpenRevenue ignores `localhost` automatically. Test on your deployed URL.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.