Framework · Install guide
Cookie consent for Astro
Updated
Astro processes scripts by default. Mark the Kiescy script is:inline in your base layout so it stays as written and runs first.
- Setup time
- About 10 minutes
- Coding
- One line in your layout
- Laws covered
- GDPR, UK GDPR, CCPA, DPDP
- Google Consent Mode v2
- Built in, basic or advanced
Set up cookie consent on Astro in 3 steps
- Create a free accountAdd your website. Kiescy scans it and finds the trackers that need consent.
- Paste one script into AstroYour banner appears and starts holding back trackers until visitors choose.
- Check it worksOpen your site in a private window and run the free check to confirm nothing loads early.
Why Astro sites need cookie consent
Astro sites are fast content and marketing sites that frequently add Google Analytics or ad pixels, sometimes through Partytown. EU visitors must be asked first.
Your options on Astro
| Approach | Good for | Watch out for |
|---|---|---|
| Partytown-only setups | Performance | Partytown moves scripts off the main thread but doesn't ask for consent |
| Kiescy with is:inline | Any Astro site | Keep it out of Partytown |
Add your privacy policy
Put the embed where your privacy policy should appear, or link straight to your hosted policy URL from the footer:
<div data-kiescy-doc="privacy"></div>
<script src="https://script.kiescy.com/embed/policy/YOUR_SITE_KEY.js" async></script>Check that it works
Open your site in a private window: the banner should appear for a first-time visitor. Then run the free privacy check, which opens your site as a new EU visitor and lists anything that still loads before consent.
Kiescy's monitoring repeats that check on a schedule and emails you if a new script starts tracking before consent.
What your Astro visitors see
Kiescy detects where each visitor is and shows the version their law requires, so you don't have to choose between the strictest banner for everyone and no banner at all.
Trackers Astro sites usually load
These are the tools that most often need consent on Astro sites, and how Kiescy treats them. Run a cookie scan to see exactly what yours loads.
| Tool | Category | What happens |
|---|---|---|
| GA4 (often via Partytown) | Analytics | Load after consent |
| Meta Pixel | Advertising | Held back once your scan finds it |
Google Consent Mode v2 on Astro
With Kiescy first in the head, Consent Mode v2 defaults exist before gtag.js, including when gtag runs in Partytown.
New to Consent Mode? Read basic vs advanced Consent Mode v2.
Troubleshooting
The script gets bundled or deferred
Add is:inline. Without it Astro treats the tag as a module script.
View transitions re-run the banner
With Astro view transitions, the script runs once on first load. Add data-astro-rerun only if you need it to re-run, which you usually don't.
Compliance checklist for Astro
- A consent banner that blocks non-essential trackers until the visitor agrees (opt-in for the EU, UK and India).
- A "Do Not Sell or Share" option for California visitors, and Global Privacy Control honored.
- A privacy policy that names the tools above, linked from every page.
- A cookie policy listing the cookies your scan finds.
- A way for people to request, correct or delete their data.
- Records of each consent choice, kept as proof.
- A "Cookie settings" link calling window.pira.open() in your footer.
Guides for Astro site owners
Questions
Does it hurt Lighthouse scores?
The script is small and cached; its configuration is cached on repeat visits.
Does it work with Astro's static output?
Yes, in static and server output modes alike.
Official Astro documentation
Menus move. If a step above doesn't match what you see, Astro's own docs show the current way to add code.
Get compliant this afternoon, not this quarter.
Set up your policies, banner and request form in one place. Free while Kiescy is in early access.