Important Setup Notes: Before following this guide, ensure you have your correct Account ID from your CookieChimp dashboard. If you’re testing on
localhost
, make sure to add localhost
to the Additional Domains in your Account Settings > General, otherwise the banner will not show during local development.Looking for a complete example? Check out our Next.js example implementation on GitHub for a working reference.
Prerequisites
- Next.js (App Router) project (
app/
directory). - Your CookieChimp Account ID (replace
YOUR_ACCOUNT_ID
below). - If testing locally:
localhost
added to Additional Domains in Account Settings > General.
What You’ll Build
- Load the CookieChimp script first in
<head>
- Add the required trigger container
- Listen for consent and log if a service is allowed
Step 1 - Load CookieChimp in <head>
first
Use Next.js <Script>
with strategy="beforeInteractive"
so CookieChimp runs before hydration.
Replace
YOUR_ACCOUNT_ID
with your actual CookieChimp Account ID from your dashboard.Step 2 - Add a consent logger
If you need to take actions based on user consent (such as loading analytics scripts, tracking pixels, or other third-party services), this is where you’ll implement that logic. If you’re using Google Tag Manager, you can implement the GTM setup following our Google Tag Manager integration guide for the same approach. This client component:- Checks if a single service is allowed (e.g., “Google Analytics” in “analytics”)
- Logs the result on initial load and on user updates
Replace
"Google Analytics"
and "analytics"
with the exact service and category names you configured in CookieChimp.Step 3 - Use the logger on your page
Drop the logger onto any page (or mount once inapp/layout.tsx
if you prefer a global listener).
Verify
- Start your app and open the homepage.
- Open DevTools → Console.
- Interact with the Cookie banner (Accept / Deny / Update preferences).
-
You should see logs:
✅ Google Analytics allowed
❌ Google Analytics blocked
Notes & Tips
- Service vs Category: use
acceptedService("Service", "Category")
for granular control. - Already Consented Users: the logger runs once on mount to catch prior consent, and again on
cc:onConsented
/cc:onUpdate
. - Production: replace
console.log
with your real actions (e.g., loading pixels/SDKs) only after consent.
Pages Router?
If you’re on the Pages Router, place the<Script>
tag in pages/_document.tsx
within <Head>
, keep the <div id="cookiechimp-container" />
in pages/_app.tsx
, and use the same ConsentLogger
.