Skip to main content
Using the @cookiechimp npm packages? Follow the Consent SDK getting-started guide. This page covers the hosted CookieChimp widget.
This guide covers plain React apps — bundled with Vite or Create React App (CRA). If you’re using Next.js, follow our Next.js guide. If you’re using Remix, follow our Remix guide.
Before you start: have your CookieChimp Account ID ready (replace YOUR_ACCOUNT_ID in the snippets below). If you're testing on localhost, add localhost to Additional Domains in your Account Settings — otherwise the banner won't show locally.

How do I install CookieChimp in a Vite + React app?

Add the script tag to index.html (at the project root) inside <head>, before any module scripts so it loads first:
Vite serves index.html as the entry point in both dev and production. The script tag goes here once — there’s no separate build step needed.

How do I install CookieChimp in a Create React App?

Add the script tag to public/index.html inside <head>, before any other scripts:
CRA injects your bundle after the HTML is served, so a static <script> in <head> runs before React mounts.

How do I handle client-side routing (React Router)?

If your app uses React Router (v6+), pages don’t reload on navigation — they swap components. CookieChimp needs to know about route changes so it can re-evaluate which scripts to allow. Create a small component that listens to location changes and re-injects the CookieChimp script. We skip the first render because the static <script> tag in index.html has already loaded CookieChimp on initial page load.
Mount it once at the top of your app, inside the router:

How do I add a Privacy Trigger container?

Place a <div> with the ID cookiechimp-container somewhere in your layout that doesn’t unmount on navigation — typically your root layout or App.tsx:

Listen for the cc:onConsented event (fires once when consent has been given) and cc:onUpdate (fires when the user changes their preferences).
Replace "Google Analytics" and "analytics" with the exact service and category names you configured in CookieChimp.
For all available events, methods, and properties, see the JavaScript SDK.

Troubleshooting

  • Banner shows on first load but not after navigation — make sure CookieChimpReinit is mounted inside <BrowserRouter>.
  • Privacy Trigger disappears — keep #cookiechimp-container in a layout component that stays mounted across routes.
  • Banner doesn't appear at all — confirm localhost (or your domain) is in Additional Domains in Account Settings.
  • Enable Debug mode in the CookieChimp dashboard and check the browser console for logs.