Source: https://usedataowl.com/docs/nextjs-app-router
Markdown source: https://usedataowl.com/docs/nextjs-app-router.md
Description: How to add privacy-friendly web analytics, session replay, and error tracking to a Next.js 15+ App Router project using next/script in your root layout.

# How to Add Web Analytics & Error Tracking to Next.js App Router

The way to load a script on every page of a Next.js App Router app is the root layout.

1. Open your root layout, usually `app/layout.tsx`.
2. Import `Script` from `next/script`.
3. Add the DataOwl script to the `<head>` with `strategy="afterInteractive"`:

```tsx title="app/layout.tsx"
import Script from "next/script"

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <head>
        <Script
          defer
          data-website-id="YOUR_SITE_ID"
          src="https://usedataowl.com/js/script.cookies.js"
          strategy="afterInteractive"
        />
      </head>
      <body>{children}</body>
    </html>
  )
}
```

> Replace `YOUR_SITE_ID` with your site ID from the dashboard.

## Verify installation

After you deploy:

- Visit your live website.
- Open the **Realtime** page of your [DataOwl dashboard](/dashboard). Your visit shows up within a second, and the setup page says "Receiving events".

> DataOwl ignores localhost so you don't count your own development traffic. Add `data-allow-localhost="true"` to the tag to test locally. More options are in the [script configuration reference](/docs/script-configuration).
