ForNext.js logoNext.js

Cookie consent for Next.js

Consent for the App Router and Pages Router that blocks trackers before the page paints.

In Next.js, third-party scripts can load before a client-side consent library runs, so a cookie-only banner leaks data on the first paint. ConsentStack's React package works in the App Router and Pages Router and blocks trackers until the user consents, covering GDPR, CCPA, and 70+ regulations.

Why ConsentStack on Next.js

  • Works with the App Router and Pages Router: render the component once in your root layout.
  • Blocks third-party scripts before they load instead of after the page paints.
  • Consent state is seeded from the edge, so useConsent gates resolve immediately without a flash.
  • Pixel-perfect brand matching, so the banner looks built into your Next.js site, never bolted on.

Install in Next.js

terminal
npm install @consentstack/react
app/layout.tsx
import { ConsentStack } from "@consentstack/react"

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <ConsentStack siteKey="YOUR_SITE_KEY" />
      </body>
    </html>
  )
}

Replace YOUR_SITE_KEY with the site key from your ConsentStack dashboard.

Add <ConsentStack /> in your root layout (App Router) or _app (Pages Router). Consent state is seeded from the edge, so gating passes immediately on the landing page.

Common questions

100+ happy customers

AN
ML
LP
DM
JT

Ship consent on Next.js. In minutes.

Scan your site free to see what is firing before consent, then turn on real blocking from one install.

Get started free