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

# Next.js installation

> Install OpenRevenue analytics in a Next.js app using the App Router, Pages Router, or a client component.

## Add the script

Copy your project ID from [Settings → General](https://www.openrevenue.com/dashboard), then add the tracker to the right file for your router.

> [!TIP]
>
> Use Next.js `Script`. It loads the tracker outside your app bundle.

## App Router

Add the script to your root `app/layout.tsx`:

```tsx app/layout.tsx {1,8-12} theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
import Script from "next/script"

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <Script
          src="https://api.openrevenue.com/tracker.js"
          data-site="your-project-id"
          strategy="afterInteractive"
        />
      </body>
    </html>
  )
}
```

## Pages Router

Add the script to your `pages/_app.tsx`:

```tsx pages/_app.tsx theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
import Script from "next/script"
import type { AppProps } from "next/app"

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <Component {...pageProps} />
      <Script
        src="https://api.openrevenue.com/tracker.js"
        data-site="your-project-id"
        strategy="afterInteractive"
      />
    </>
  )
}
```

## npm package

Prefer a package? Install `openrevenue` and use the thin `OpenRevenueScript` helper (still loads the CDN tracker), or call `init` from a client component.

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

```tsx app/layout.tsx theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
import { OpenRevenueScript } from "openrevenue/next"

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <OpenRevenueScript siteId="your-project-id" />
      </body>
    </html>
  )
}
```

```tsx components/analytics.tsx theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
"use client"

import { useEffect } from "react"
import { init, track } from "openrevenue"

export function Analytics() {
  useEffect(() => {
    init({ siteId: "your-project-id" })
  }, [])

  return null
}

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

## Verify

Deploy your app and visit any page. A pageview should appear in your [OpenRevenue dashboard](https://www.openrevenue.com/dashboard) within seconds.

> [!NOTE]
>
> OpenRevenue ignores `localhost` and `127.0.0.1` automatically. Open your live site, not the dev server.


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