Skip to main content
Astro builds static-by-default sites, but the install pattern depends on whether you’re using View Transitions. With View Transitions enabled, Astro behaves like a single-page app and the script needs to be reinitialized on each navigation. Without them, a standard script tag is enough.
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 standard Astro site?

If you’re not using <ClientRouter /> (formerly <ViewTransitions />), every navigation is a full page load — a single script tag in your root layout works:
Replace YOUR_ACCOUNT_ID with your actual CookieChimp Account ID from your dashboard.
The is:inline directive tells Astro not to bundle, hash, or process the script — it ships exactly as written so it runs as the first thing in <head>.

How do I install CookieChimp with View Transitions?

If your site uses Astro’s <ClientRouter /> (Astro 5+) or <ViewTransitions /> (Astro 3-4), navigation happens client-side without a full reload. Re-inject the CookieChimp script after every transition so it rescans the newly rendered page. astro:page-load fires on the first page load as well, so this single handler covers both cases — no separate static script tag needed.

How do I position the Privacy Trigger?

Add a <div id="cookiechimp-container"> somewhere in your layout, and mark it with transition:persist so View Transitions don’t tear it down between routes:
See the Astro docs on maintaining state with transition:persist for more.
Inline Astro scripts run on every page (or just once with View Transitions). Listen for CookieChimp events:
Replace "Google Analytics" and "analytics" with the exact service and category names you configured in CookieChimp.
For all available events, see Callbacks & Events.

Troubleshooting

  • Banner shows on first load but disappears after navigation — you’re using View Transitions but the astro:page-load listener isn’t wired up. Use the View Transitions install pattern above.
  • Privacy Trigger flashes or disappears between pages — add transition:persist to your #cookiechimp-container div.
  • Script doesn’t run first — make sure you used is:inline on the script tag so Astro doesn’t defer it.
  • 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.