> For the complete documentation index, see [llms.txt](https://docs.humblytics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.humblytics.com/how-to-get-started/nextjs.md).

# Next.js

Add Humblytics to your Next.js app in about 5 minutes.

{% hint style="info" %}
**You need:** access to your app's root layout and a production deploy. A local dev server won't verify.
{% endhint %}

## 1. Copy your ID

In Humblytics, open **Site settings → Install**. Your ID is the value after `id=` in the snippet. Replace `YOUR_ID` below with it.

The snippet has two parts. The small inline script prevents A/B-test flicker: it hides the page for a moment (2 seconds at most) until your test variant is ready. Keep both.

## 2. Add it to your root layout

Use `next/script` with `strategy="beforeInteractive"` so Humblytics loads before the page is shown.

**App Router:** `app/layout.tsx`

```tsx
import Script from 'next/script'

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script id="humblytics-reveal" strategy="beforeInteractive">
          {`document.documentElement.style.opacity='0';window._hmblReveal=function(){document.documentElement.style.opacity='1'};setTimeout(window._hmblReveal,2000);`}
        </Script>
        <Script
          src="https://app.humblytics.com/hmbl.min.js?id=YOUR_ID"
          strategy="beforeInteractive"
        />
      </body>
    </html>
  )
}
```

**Pages Router:** add the same two `<Script>` tags inside `<body>` in `pages/_document.tsx`. `beforeInteractive` only works in `_document`, not `_app`.

Next.js places `beforeInteractive` scripts in the `<head>` for you. Route changes are tracked automatically.

<figure><img src="https://1281224403-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqZMBn2D7F1lV2hgGTS2X%2Fuploads%2FsQRHdaMtK6sUwA0lxuJw%2Fcustom%20code%20script.gif?alt=media&amp;token=670adf7b-a09d-4d95-888d-848e32016dca" alt=""><figcaption></figcaption></figure>

## 3. Deploy and verify

1. Deploy to production.
2. Back in Humblytics, click **Verify install**.
3. Open your live site in a private window and click around. Your visit appears in **Observe → Analytics → Overview** under **Live Activity** within about a minute.

**Not verifying?**

* You're testing the production URL, not `localhost`.
* Using a Content Security Policy? Allow `https://app.humblytics.com` in `script-src` and `connect-src`, and allow the inline script (with a nonce or hash).

Still stuck? See [Verify & Troubleshoot Tracking](/how-to-get-started/verify-and-troubleshoot-tracking.md).
