Cookie Consent for Next.js

By: Masha Komnenic CIPP/E, CIPM, CIPT, FIP Masha Komnenic CIPP/E, CIPM, CIPT, FIP | Updated on: August 1, 2025

Free Cookie Consent Solution
Cookie-Consent-Nextjs-01

If you’re building your website with Next.js, you’re probably focused on speed, scalability, and user experience.

But what about data privacy compliance?

Chances are, your website relies on cookies, whether you’re using Google Analytics, running ads, or simply storing user preferences. These cookies may be regulated by privacy laws, meaning you might need a cookie consent strategy that works with Next.js.

In this guide, I explain how cookies work in Next.js, when and why consent is required under laws like the GDPR, and how Termly can help you set up a banner that keeps your site transparent, user-friendly, and aligned with global privacy standards.

Table of Contents
  1. How Cookies Work in Next.js
  2. Cookie Consent Requirements for Next.js Sites
  3. How Termly Helps Meet Cookie Consent Requirements in Next.js

How Cookies Work in Next.js

Cookies are small pieces of data stored in a user’s browser used by websites to track visits, save preferences, personalize content, and gather analytics data.

While all cookies are ultimately stored in the browser, the way they’re set and managed can vary depending on how your site is built.

In a Next.js environment, cookies are either set from the client side (after the page has loaded in the browser) or from the server side (before the page loads, during the server’s response).

Understanding this distinction is crucial because it affects when cookies are triggered, and whether they’re being set before the user has the chance to give consent.

Cookies Set After the Page Loads (Client-Side)

Client-side cookies are added using code that runs after the page has already loaded in a person’s browser. This is often the case when you’re using tracking tools like Google Analytics or a marketing plugin.

Because this kind of code runs later, it’s easier to hold off and ask for user permission first, which is ideal for following privacy laws.

Cookies Set Before the Page Loads (Server-Side)

Next.js also allows you to add cookies earlier, before the page is displayed to the visitor. These are often used for tasks such as logging people in or managing sessions.

The challenge here is that these cookies can be set before your cookie consent banner even appears. That’s a problem if the cookies are non-essential and you haven’t gotten consent yet.

So, while you may not need to worry about the technical differences between the two, it’s essential to understand that cookies can be added at different stages, which can affect how you manage privacy on your site.

If your Next.js site uses cookies for purposes beyond basic functionality, such as displaying analytics, running ads, or storing user preferences, you’ll likely need to comply with cookie consent requirements under various privacy laws.

Privacy Laws Impacting Cookie Consent

Several global privacy laws impose strict rules on how websites can use cookies, not only regarding when consent is required, but also how cookies are disclosed, categorized, and managed over time.

Laws like these are designed to give users more control over their data and ensure businesses are transparent about the technologies they use to track or personalize online experiences.

Below are some of the key laws that may apply to your Next.js site:

  • General Data Pprotection Regulation (GDPR): Requires opt-in consent for non-essential cookies and emphasizes clear, informed user choices.
  • ePrivacy Directive: Often referred to as the EU Cookie Law, the ePrivacy Directive focuses specifically on cookie usage and requires consent before accessing or storing information on a user’s device.
  • California Consumer Protection Act (CCPA): Requires businesses to disclose their tracking practices and provide a method for users to opt out of data sharing or selling, including through cookies.
  • Other global laws: Laws like Brazil’s LGPD, Canada’s PIPEDA also contain cookie-related rules you may need to follow based on where your users are located.

While each regulation has its nuances, they all aim to provide users with more control and transparency over how their data is collected and used through cookies.

What Cookie Consent Should Look Like on a Next.js Site

Now that you know which laws may apply, let’s examine the specific steps you should take to help align your site with current consent standards.

Present a Cookie Consent Banner on First Visit

The first step is to display a cookie consent banner when someone lands on your site, before setting any non-essential cookies.

This banner should:

  • Let users know your site uses cookies
  • Explain the purpose behind them (e.g., analytics, ads)
  • Allow users to choose whether to accept, reject, or manage cookies.

To be valid under laws like the GDPR, consent must be:

  • Informed: Users should know exactly what they’re agreeing to
  • Freely given: Access to the site can’t depend on accepting cookies
  • Granular: Users should be able to accept some types of cookies and reject others

Avoid using pre-checked boxes or vague “by continuing to browse…” notices, as these don’t meet today’s expectations for consent.

Link to a Clear Privacy or Cookie Policy

A key part of cookie compliance is transparency. Your business should disclose its cookie practices in a way that is easy to find and written in a way that users can understand.

This information can be included as a clause in your main privacy policy or a dedicated cookie policy.

Your policy should cover:

  • The types of cookies your site uses
  • What each cookie does and why it’s being used
  • How long each cookie remains active
  • Whether the cookies are set by your site or third parties
  • How users can manage or withdraw their consent

It should be linked directly from your cookie banner and made available in other visible areas of your site, such as the footer or account settings.

For help creating the proper disclosures, you can use Termly’s Privacy Policy Generator or Cookie Policy Generator to build documents tailored to your site’s data practices.

Offer a Cookie Preference Center

A cookie preference center is a dedicated area where users can change their cookie choices anytime.

It supports the idea (and legal requirement) that consent isn’t a one-time event; it can be easily withdrawn or adjusted at any time.

Your preference center should:

  • List the categories of cookies your site uses
  • Allow users to update or withdraw their consent
  • Be easy to find (like through a link in your site’s footer).

Offering this level of control enhances transparency and aligns with legal requirements for withdrawing consent.

Track and Log Consent

To demonstrate that your site respects user choices, especially in regulated regions, it’s essential to log each consent event. This record may be required in the event of an audit or privacy complaint.

Consent logs should include:

  • The user’s choices (accepted/declined cookie categories)
  • A timestamp of consent
  • The version of the banner or settings shown
  • Additional info like location or language, where permitted

Maintaining a thorough consent log is particularly important for Next.js sites that utilize third-party tools, such as Google Analytics, YouTube embeds, or ad platforms — tools that may process personal data.

Support Universal Opt-Out Signals

Some privacy laws, particularly the CCPA, require businesses to respect browser-based privacy signals, such as the Global Privacy Control (GPC).

While not universally mandated across all U.S. laws, supporting these signals helps businesses align with evolving privacy standards.

If a user has GPC enabled in their browser, your site should treat it as an automatic opt-out of data sharing or tracking, even if they haven’t clicked on any elements of your banner.

Recognizing these signals:

  • Helps ensure compliance with laws like the CCPA
  • Reduces user friction by honoring their preferences
  • Demonstrates that your business takes privacy seriously

Want to learn more about how GPC works? Read Termly’s breakdown of the Global Privacy Control for a full explanation.

If you’re looking for an easier way to manage cookie consent on your Next.js site, Termly’s Consent Management Platform offers a flexible, all-in-one solution designed to keep you aligned with global privacy laws.

From setup to ongoing compliance efforts, Termly helps simplify the technical aspects of cookie consent, allowing you to focus on building a fast and user-friendly experience within your site.

Key features of our CMP include:

  • A fully customizable cookie banner with geo-targeting and granular consent options
  • Automatic cookie scanning and categorization by type (e.g., essential, analytics, marketing)
  • Script blocking that prevents non-essential cookies from loading before consent
  • A built-in cookie preference center for real-time user control
  • Consent logging and record-keeping to support audits or legal requests
  • Support for universal opt-out signals like Global Privacy Control (GPC)

Whether you’re setting up a new Next.js project or updating your current site to meet today’s privacy expectations, Termly makes it easier to manage cookie consent in a transparent and user-focused way.

Try Termly’s consent solutions to help eliminate the guesswork from cookie compliance.

Masha Komnenic CIPP/E, CIPM, CIPT, FIP
More about the author

Written by Masha Komnenic CIPP/E, CIPM, CIPT, FIP

Masha is an Information Security and Data Privacy Specialist and a Certified Data Protection Officer. She has been a Data Protection Officer for the past six years, helping small and medium-sized enterprises achieve legal compliance. She has also been a privacy compliance mentor to many international business accelerators. She specializes in implementing, monitoring, and auditing business compliance with privacy regulations (HIPAA, PIPEDA, ePrivacy Directive, GDPR, CCPA, POPIA, LGPD). Masha studied Law at Belgrade University, and she passed the Bar examination in 2016. More about the author

Related Articles

Explore more resources

Enter Your Website URL

In order to help you create a cookie solution that is GDPR and Cookie Law compliant, we must first scan your website for cookies.