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.What do I need before starting?
- Next.js (App Router) project (
app/directory). - Your CookieChimp Account ID (replace
YOUR_ACCOUNT_IDbelow). - If testing locally:
localhostadded to Additional Domains in Account Settings > General.
What will this guide cover?
- Load the CookieChimp script first in
<head> - Add the required trigger container
- Listen for consent and log if a service is allowed
How do I load the CookieChimp script?
Use Next.js<Script> with strategy="beforeInteractive" so CookieChimp runs before hydration.
How do I check consent status in code?
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.How do I use the consent logger on a page?
Drop the logger onto any page (or mount once inapp/layout.tsx if you prefer a global listener).
How do I verify it’s working?
- 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
What else should I know?
- 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.logwith your real actions (e.g., loading pixels/SDKs) only after consent.
How do I set this up with 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.