Skip to content
Next.js

Cookie consent in Next.jsThe framework sets nothing, your script tags do

Reviewed · 4 sources

Next.js does not set cookies on ordinary visitors, and it has no consent mechanism either. Every cookie on a Next.js site comes from code you or a dependency added: analytics, auth, pixels, embeds.

That makes compliance your job in a very direct way. A script component in the root layout runs for every visitor on every page, and nothing in the framework will stop it.

Check your Next.js site

See every cookie it sets before consent, after Reject and after Accept.

What Next.js setsOn its own

  • __prerender_bypassSet only when a route enables Draft Mode, for editors previewing content. Ordinary visitors never get it.No consent needed

The Next.js documentation describes no other framework cookie. Session cookies from your auth library, such as authjs.session-token, are necessary for login and need no consent.

Built-in consent tools

Nothing built in

The @next/third-parties package provides GoogleAnalytics, GoogleTagManager, YouTubeEmbed and GoogleMapsEmbed components. Its documentation has no consent option: GoogleAnalytics accepts gaId, dataLayerName, debugMode and nonce, and the scripts are fetched after hydration wherever the component is rendered.

So consent is something you build: keep the visitor's choice in state (and a first-party cookie or local storage entry, which is necessary and needs no consent), and render tracking components only when the matching category is allowed.

Where the cookies come fromThe ones that need consent

GoogleAnalytics and GoogleTagManager components

Placed in the root layout, they load for every visitor. Render them conditionally, or set Consent Mode defaults to denied before they load.

next/script tags

Any <Script> with a pixel or analytics snippet runs as soon as its strategy allows. The strategy controls timing, not consent.

Analytics packages

Vercel says Web Analytics does not use cookies and identifies visitors with a hash that is valid for one day. It does not say whether consent is needed; other analytics packages commonly do set cookies.

Embeds and fonts

YouTube and map embeds contact Google when they render. next/font downloads Google Fonts at build time and serves them from your own domain, so use it instead of a stylesheet link.

Make Next.js compliantIn 5 steps

  1. 1

    Keep consent in one place

    A small client-side store with the categories (analytics, marketing) and a banner that writes to it. Persist the choice so returning visitors are not asked again.

  2. 2

    Render tracking only when allowed

    Wrap each tracking component in a client component that returns null until its category is granted.

  3. 3

    Or use Consent Mode

    If you must load Google tags first, push consent defaults of denied to the dataLayer before the tag, and update them when the visitor chooses.

  4. 4

    Make Reject and withdrawal work

    On reject or withdrawal, stop rendering the component and delete the cookies it set. Unmounting a script does not remove its cookies.

  5. 5

    Check every route

    Tags added in a nested layout or a single page are easy to miss. Scan a few different routes, not only the homepage.

Load Google Analytics only after consent
"use client";

import { GoogleAnalytics } from "@next/third-parties/google";
import { useConsent } from "@/lib/consent"; // your own consent store

export function Analytics() {
  const { analytics } = useConsent();
  return analytics ? <GoogleAnalytics gaId="G-XXXXXXXXXX" /> : null;
}

useConsent is your own hook. Render <Analytics /> in the root layout in place of <GoogleAnalytics />.

Tools that help: tracking script blocker · Consent Mode v2 generator · cookie reference

Common mistakesOn Next.js sites

GoogleAnalytics straight in the root layout

It is the pattern the documentation shows, and it sets _ga for every visitor before any choice.

Treating the script strategy as consent

lazyOnload and afterInteractive delay a script. They do not ask anyone.

Reading consent on the server only

A consent cookie read in a server component is fine for the first render, but the page must also react when the visitor chooses without reloading.

Not clearing cookies on withdrawal

After the visitor withdraws, the _ga cookie is still there unless you delete it.

Checklist for Next.js sites

  • No tracking component rendered before consent
  • Consent stored first-party and read on every route
  • Reject and withdrawal remove tracking cookies
  • Fonts through next/font, not a third-party stylesheet
  • YouTube and map embeds behind a click or consent
  • Auth and session cookies listed in the policy as necessary
  • Several routes scanned, not only the homepage

QuestionsAnd short answers

Does Next.js set cookies?
Not on ordinary visitors. The documented exception is __prerender_bypass, set when a route enables Draft Mode for content previews. Other cookies come from your own code and dependencies.
Does @next/third-parties handle consent?
No. Its documentation has no consent option for GoogleAnalytics or GoogleTagManager. You gate them yourself by rendering conditionally or by setting Consent Mode defaults.
Do I need a cookie banner with Vercel Web Analytics?
Vercel states that Web Analytics does not use cookies and identifies visitors with a daily hash. Vercel does not say whether consent is required, and regulators differ on cookieless analytics, so check the rules of the countries you serve.
Do NextAuth or Auth.js cookies need consent?
No. Session and CSRF cookies are strictly necessary to provide the login the user asked for. List them in your cookie policy.

Sources

  1. Next.js: How to optimize third-party libraries
  2. Next.js: Draft Mode
  3. Vercel Web Analytics
  4. Vercel Web Analytics: Privacy and Compliance

Reviewed 20 November 2026 against Next.js's own documentation. Platforms change their cookies and consent features; follow the links for the current state. General information about EU cookie rules, not legal advice.

Other platformsAnd guides by industry

Check your Next.js siteSee what loads before consent

Free scan · every cookie before consent, after Reject and after Accept