GDPRChecker

Home / Knowledge Base / Next.js How to Fix Cookies After Reject All: A Practical Compliance Guide

Website Compliance

Next.js How to Fix Cookies After Reject All: A Practical Compliance Guide

A practical guide for Next.js developers on fixing cookies after a user rejects all. Covers consent mode, CMP integration, conditional script loading, common mistakes, and validation with GDPRChecker scans.

Run a free GDPR compliance scanPreview the findings before choosing a CMP.

Author

GDPRChecker Editorial Team

Reviewed by

Privacy & Compliance Research Team

Last updated

July 2026

Reading time

9 min read

Educational guidance for compliance readiness — not legal advice. Requirements vary by jurisdiction and your specific processing activities.

Introduction

Updated for 2026 compliance practices.

When a visitor clicks “Reject All” on your cookie banner, your Next.js site must respect that choice immediately. This means no non‑essential cookies, no tracking scripts firing, and no personal data flowing to third parties until consent is given. For many website owners, the gap between what the banner says and what the browser actually does is where compliance risk hides. This guide walks through what “Next.js how to fix cookies after reject all” means in practice, how to implement it step by step, and how to verify your setup with GDPRChecker scans.

What “Next.js How to Fix Cookies After Reject All” Means for Website Owners

“Next.js how to fix cookies after reject all” is a practical compliance topic for website owners validating consent, tags, and disclosures. In a Next.js application, cookies and tracking scripts are often loaded through custom _app.js logic, third‑party integrations like Google Analytics or Meta Pixel, and tag managers such as Google Tag Manager. When a user rejects all cookies, every one of these channels must be blocked until the user changes their preference.

The challenge is that Next.js renders pages both on the server and in the browser. Server‑side rendering can inadvertently set cookies or inject scripts before the client‑side consent state is even known. Fixing cookies after reject all therefore means:

  • Ensuring no non‑essential cookies are set on the server response.
  • Delaying client‑side scripts until consent is confirmed.
  • Respecting the consent signal across page navigations and full reloads.
  • Keeping the consent state synchronised between your CMP (Consent Management Platform) and all tags.

This is not a one‑time configuration. It requires ongoing validation, especially after deploying new features, updating third‑party libraries, or changing your cookie banner provider.

Requirements and Compliance Expectations

Under the ePrivacy Directive and the GDPR, websites must obtain valid consent before storing or accessing information on a user’s device, unless the cookie is strictly necessary. See ePrivacy Directive Article 5(3). The European Data Protection Board (EDPB) and national data protection authorities expect that a “Reject All” option is as easy to use as “Accept All.” Once rejected, the website must not set non‑essential cookies or fire tracking requests.

From a technical standpoint, this means:

  • Pre‑consent blocking: All tags that set cookies or read device information must be blocked by default.
  • Consent propagation: When consent is updated (e.g., from “rejected” to “accepted”), the new state must be communicated to all relevant scripts without a page reload.
  • No “implied consent”: Continuing to browse does not constitute consent. The default state must be “no consent” until the user makes an affirmative choice.
  • Documentation: Your cookie banner, cookie policy, and privacy policy must clearly disclose what cookies are used, their purpose, and how to withdraw consent.

Google’s Consent Mode provides a standardised way to signal consent state to Google tags. When a user rejects all, Consent Mode instructs Google Analytics, Google Ads, and Floodlight to operate in a cookieless mode that does not set cookies or read device identifiers. Implementing Consent Mode correctly is a key part of fixing cookies after reject all in a Next.js environment.

How to Implement Step by Step

1. Choose a Consent Management Platform (CMP)

A CMP handles the consent banner, stores user preferences, and exposes a consent API. For Next.js, you need a CMP that works well with client‑side rendering and supports Google Consent Mode. Many CMPs provide a JavaScript snippet that you can add to your _app.js or a custom <Script> component.

2. Integrate the CMP with Next.js

Place the CMP script early in the <head> of your application. In Next.js, you can use the <Script> component with the strategy="beforeInteractive" attribute to ensure it loads before any other scripts. For example:

import Script from 'next/script'

function MyApp({ Component, pageProps }) {
  return (
    <>
      <Script
        id="cmp-script"
        strategy="beforeInteractive"
        src="https://your-cmp-provider.com/script.js"
      />
      <Component {...pageProps} />
    </>
  )
}

Make sure the CMP script does not set any cookies before consent. Some CMPs set a technical cookie to remember the banner state; this is usually considered strictly necessary, but verify with your legal advisor.

3. Configure Default Consent State

Google Consent Mode requires you to set a default consent state before any Google tags fire. This is done by adding a small inline script that defines gtag('consent', 'default', { ... }). The default should deny all non‑essential purposes:

<Script id="consent-defaults" strategy="beforeInteractive">
  {`
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('consent', 'default', {
      'ad_storage': 'denied',
      'analytics_storage': 'denied',
      'functionality_storage': 'denied',
      'personalization_storage': 'denied',
      'security_storage': 'granted',
      'ad_user_data': 'denied',
      'ad_personalization': 'denied',
      'wait_for_update': 500
    });
  `}
</Script>

This snippet must run before any Google tags are loaded. The wait_for_update parameter tells Google tags to wait for a consent update before firing, which is useful if your CMP loads asynchronously.

4. Update Consent State on User Action

When the user interacts with the cookie banner, your CMP should call gtag('consent', 'update', { ... }) with the appropriate granted or denied values. For a “Reject All” action, all non‑essential purposes remain denied. For “Accept All,” they are granted. Most CMPs handle this automatically if you enable the Consent Mode integration.

If you are building a custom banner, you must listen for user choices and call the update function yourself. Store the consent state in a cookie or localStorage so it persists across pages.

5. Conditionally Load Third‑Party Scripts

Even with Consent Mode, some third‑party scripts (like Meta Pixel or LinkedIn Insight Tag) may not natively respect the consent signal. You need to conditionally load these scripts based on the consent state.

One approach is to use the CMP’s callback or event listener to know when consent has been granted. For example:

useEffect(() => {
  if (userConsentedTo('marketing')) {
    // Load Meta Pixel
    !function(f,b,e,v,n,t,s)
    { ... }(window,document,'script', ...);
  }
}, [consentState])

Alternatively, you can use a tag manager like Google Tag Manager (GTM) and configure triggers that fire only when the appropriate consent is granted. GTM’s Consent Overview makes this relatively straightforward.

6. Handle Server‑Side Rendering (SSR) and Static Generation

Next.js can pre‑render pages on the server. If your page includes components that set cookies or inject tracking scripts, you must ensure they do not execute on the server without consent. Since consent is a client‑side concept, you should:

  • Avoid setting non‑essential cookies in getServerSideProps or API routes.
  • Use dynamic imports with { ssr: false } for components that contain tracking scripts.
  • Check for the presence of a consent cookie in getServerSideProps and pass it to the page, but never rely solely on server‑side consent checks because the user could have changed their preference.

7. Test the “Reject All” Flow

After implementation, test thoroughly:

  1. Open your site in an incognito/private window.
  2. Click “Reject All” on the cookie banner.
  3. Check the browser’s developer tools (Application > Cookies) to see which cookies are set. Only strictly necessary cookies should be present.
  4. Go to the Network tab and reload the page. Filter by third‑party domains (e.g., google-analytics.com, facebook.com). No requests should be sent to these domains before consent.
  5. Verify that Google Consent Mode is working by typing __tcfapi or google_tag_data in the console and inspecting the consent state.

Common Mistakes and How to Avoid Them

1. Setting Cookies Before Consent

A frequent mistake is loading a script that immediately sets a cookie, even before the CMP has loaded. This can happen if you place a third‑party script in _document.js or in the <head> without a blocking mechanism. Always load non‑essential scripts conditionally or through a tag manager that respects consent.

2. Ignoring Server‑Side Cookies

Next.js API routes or server‑side code might set cookies (e.g., session cookies, language preferences). If these are not strictly necessary, they must be blocked until consent. Review all Set-Cookie headers in your server responses and ensure they are categorised correctly.

3. Incomplete Consent Mode Configuration

Setting only analytics_storage and ad_storage is not enough. Google Consent Mode v2 introduced ad_user_data and ad_personalization. If you use Google Ads or Floodlight, you must include these parameters. Otherwise, Google tags may still set cookies.

4. Not Testing After Every Deployment

A new marketing pixel, a library update, or a change in your CMP configuration can reintroduce non‑compliant cookies. Automate compliance checks as part of your CI/CD pipeline or schedule regular manual scans.

5. Assuming the CMP Handles Everything

CMPs are powerful, but they only control scripts that are properly integrated. If you add a script directly to your codebase without wiring it to the CMP, it will fire regardless of consent. Always verify that every third‑party script is gated by consent.

How to Validate with GDPRChecker

GDPRChecker scans help verify pre‑consent network requests, banner behavior, and disclosure gaps after changes. Once you have implemented the fixes, run a scan to confirm that your Next.js site respects the “Reject All” choice.

A GDPRChecker scan will:

  • Detect cookies set before consent.
  • Identify third‑party requests that fire despite denied consent.
  • Check that your cookie banner appears correctly and offers a genuine “Reject All” option.
  • Verify that your privacy policy and cookie policy are present and contain required disclosures.

To use GDPRChecker:

  1. Enter your website URL.
  2. Configure the scan to simulate a “Reject All” interaction.
  3. Review the report for any flagged issues.
  4. Fix the issues and rescan until your site is clean.

Regular scanning is essential because compliance is not a one‑time achievement. New scripts, updated consent requirements, and changes in browser behavior can all affect your compliance posture.

Implementation Checklist

  1. To do: Select a CMP that supports Google Consent Mode and works with Next.js.
  2. To do: Add the CMP script to your Next.js app with strategy="beforeInteractive".
  3. To do: Set default consent state to denied for all non‑essential purposes.
  4. To do: Configure the CMP to update consent state on user action.
  5. To do: Conditionally load all third‑party scripts based on consent.
  6. To do: Ensure no non‑essential cookies are set server‑side.
  7. To do: Test the “Reject All” flow in an incognito window.
  8. To do: Verify that no third‑party network requests fire before consent.
  9. To do: Check that Google Consent Mode signals are correctly set.
  10. To do: Run a GDPRChecker scan to validate pre‑consent behavior.
  11. To do: Document your cookie categories and purposes in your cookie policy.
  12. To do: Schedule regular scans and re‑validate after any site changes.

FAQ

What is Next.js how to fix cookies after reject all?

“Next.js how to fix cookies after reject all” refers to the technical process of ensuring a Next.js website blocks all non‑essential cookies and tracking scripts when a user clicks “Reject All” on the cookie banner. It involves configuring consent management, conditionally loading scripts, and verifying compliance through testing and scanning.

Do I need Next.js how to fix cookies after reject all for GDPR?

Yes, if your Next.js site serves users in the EU/EEA and uses non‑essential cookies or tracking technologies, you must obtain valid consent before setting those cookies. A “Reject All” option must be offered and respected. Failing to do so can lead to enforcement actions by data protection authorities.

How do I implement Next.js how to fix cookies after reject all?

Implement by integrating a CMP, setting default consent to denied, conditionally loading scripts, and testing thoroughly. Use Google Consent Mode for Google services and ensure server‑side code does not set non‑essential cookies. Validate with a scanner like GDPRChecker.

How can I verify Next.js how to fix cookies after reject all with a scanner?

Use GDPRChecker to scan your site. It simulates a “Reject All” interaction and checks for pre‑consent cookies, third‑party requests, and banner behavior. The report highlights compliance gaps so you can fix them.

What are common Next.js how to fix cookies after reject all mistakes?

Common mistakes include setting cookies before consent, incomplete Consent Mode configuration, ignoring server‑side cookies, assuming the CMP handles everything, and not testing after deployments. Regular scanning and a thorough implementation checklist help avoid these pitfalls.

Next Steps

Fixing cookies after reject all in Next.js is a continuous process. Start by auditing your current setup with a GDPRChecker scan. If you haven’t yet chosen a CMP, read our guide on cookie banner requirements to understand what to look for. For sites that don’t run Google Ads, you may still need a CMP—see do I need a CMP if I do not run Google Ads. To dive deeper into pre‑consent blocking, check out block Google Analytics before consent. And for broader context on the rules governing cookies, see what is ePrivacy and what is cookie consent.

Remember, this guide provides technical implementation guidance, not legal advice. For legal questions specific to your situation, consult a qualified privacy professional. Ready to verify your Next.js site? Run a GDPRChecker scan now and close the consent gap.

GDPRChecker guides are educational resources and do not constitute legal advice. Use them to understand technical and operational privacy requirements, and consult qualified counsel for legal interpretation.

Check Your Website in Under 60 Seconds

  • Sign in required
  • GDPR-focused checks
  • Cookie banner detection
  • Privacy policy verification