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

# React installation

> Install OpenRevenue analytics in a React app with a script tag or component-level setup.

## Via index.html

The simplest approach: paste the script tag into your `public/index.html` or `index.html` before the closing `</body>`:

```html index.html theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
<body>
  <div id="root"></div>

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

## Via component

Prefer loading it from your React tree? Add a small effect to your root `App.tsx`:

```tsx App.tsx theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
import { useEffect } from "react"

export default function App() {
  useEffect(() => {
    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)
  }, [])

  return <>{/* your app */}</>
}
```

> [!NOTE]
>
> The empty dependency array ensures the script is injected once on mount (not on every re-render).

## npm package

For Vite and other bundlers, install the package and call `init` once from your root:

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
npm install openrevenue
```

```tsx main.tsx theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
import { init, track } from "openrevenue"

init({ siteId: "your-project-id" })

// Later: track("signup")
```

## Verify

Deploy your app and open it 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, not the dev server.


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