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.Documentation Index
Fetch the complete documentation index at: https://docs.cookiechimp.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
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:
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:
transition:persist for more.
How do I run code based on consent?
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.Troubleshooting
- Banner shows on first load but disappears after navigation — you’re using View Transitions but the
astro:page-loadlistener isn’t wired up. Use the View Transitions install pattern above. - Privacy Trigger flashes or disappears between pages — add
transition:persistto your#cookiechimp-containerdiv. - Script doesn’t run first — make sure you used
is:inlineon 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.