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
npm install @consentstack/reactimport { 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
Install @consentstack/react and render the ConsentStack component with your site key in your root layout (App Router) or in _app (Pages Router). No extra configuration is needed for the banner and script blocking.
Yes. The package supports both the App Router and the Pages Router. Add the component once near the root and it handles the banner, blocking, and geo-detection.
No. Consent state is seeded from the edge, so hooks like useConsent resolve immediately on the landing page. Gate scripts on isReady && hasConsent(category) to avoid a flash.
100+ happy customers
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.