Add my site

Install on Next.js

One script tag in the root layout covers every page, App Router or Pages Router, server or client rendered.

Takes about two minutes

Where the tag goes

Copy the exact snippet from your dashboard; the data-site-id identifies the installation. Complete the separate DNS or homepage meta-tag check described in Get started to verify domain ownership.

This snippet starts measuring on load. Where consent is required, add data-require-consent before loading and wire acceptance and withdrawal to your consent manager. The consent guide includes the calls and pre-load queue.

App Router: put the tag in your root layout's <head>:

// app/layout.tsx
export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <head>
        <script defer src="https://app.datastated.com/ds.js?v=2026-09-10-consent"
          data-site="acme.com" data-site-id="dst_YOUR_SITE_ID"></script>
      </head>
      <body>{children}</body>
    </html>
  );
}

Pages Router: the same tag goes in pages/_document.tsx inside <Head>. A plain script tag is all it is; you do not need next/script, though <Script strategy="afterInteractive"> with the same attributes works too.

Client-side navigations count as pageviews automatically: the tag follows the History API, so there is nothing to wire into the router.

Verify it worked

Open your live site in a normal browser window and click around. The installation step on your dashboard detects the first recorded pageview. Domain verification is a separate step. Nothing arriving? Walk the troubleshooting list, and remember your own ad blocker or privacy flags silence the tag.

Questions? Email us at hello@datastated.com.