Install guides / Next.js

Add AnalyzeUser to Next.js

Replace YOUR_SITE_ID with the site id from your project's setup screen.

  1. App Router: put the tag inside <head> in app/layout.tsx (the root layout), as a plain <script> element.
  2. Pages Router: put it inside <Head> in pages/_document.js.
  3. Deploy. Route changes count as pageviews on their own - nothing else to add.
// app/layout.tsx
export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <head>
        <script defer src="https://analyzeuser.com/track.js" data-site-id="YOUR_SITE_ID"></script>
      </head>
      <body>{children}</body>
    </html>
  );
}

To check it works, open your site in another browser (browsers you use the dashboard in are left out of your stats) and watch the dashboard's Online count. Next: custom events, revenue attribution, or proxying through your domain so ad blockers don't hide visitors.

Other code

Start free trial