# astro-consent A **privacy-first, zero-dependency cookie consent banner** for Astro projects โ€” built for speed, compliance, and total visual control. Designed and maintained by **Velohost**. --- ## Why astro-consent? Most cookie consent solutions are bloated, opaque, or tied to third-party services. **astro-consent** is built differently: - No trackers - No remote calls - No analytics SDKs - No vendor lock-in - No runtime dependencies Just a **fast, deterministic, developer-controlled consent layer** that respects user privacy and legal boundaries. --- ## โœจ Features - โœ… GDPR / UK GDPR friendly - ๐Ÿช Consent categories: Essential, Analytics, Marketing - ๐ŸŽ›๏ธ Preferences modal with toggle switches - โšก Zero runtime dependencies - ๐ŸŽจ Fully themeable via CSS variables - ๐Ÿง  Frontend-controlled script loading - ๐Ÿงฉ Native Astro integration - ๐Ÿงพ Built-in TypeScript declarations - ๐Ÿ› ๏ธ CLI installer & remover - ๐Ÿ” Clean uninstall with no residue - ๐ŸŒ Framework-agnostic frontend API --- ## ๐Ÿ“ฆ Installation (Required) This package uses **both an Astro integration and a CLI installer**. ### 1๏ธโƒฃ Install the package ```bash npm install astro-consent ``` This step is **required** so Astro can import the integration at build time. --- ### 2๏ธโƒฃ Run the installer ```bash npx astro-consent ``` This will automatically: - Inject the Astro integration into `astro.config.*` - Create `src/cookiebanner.css` for theme control - Enable the consent banner across your site No manual wiring required. --- ### โŒ Uninstall ```bash npx astro-consent remove ``` This cleanly removes: - The integration entry - Generated files - All banner logic No orphaned config. No hidden state. --- ## ๐Ÿ”ง Astro Integration Usage ```ts import astroConsent from "astro-consent"; export default { integrations: [ astroConsent({ siteName: "My Website", policyUrl: "https://example.com/privacy-policy", consent: { days: 30, storageKey: "astro-cookie-consent" }, categories: { analytics: false, marketing: false } }) ] }; ``` ### Configuration notes - **policyUrl** A full, public URL to your Privacy or Cookie Policy page. This is linked directly from the consent banner. - **consent.days** How long (in days) consent is stored before the user is asked again. - **consent.storageKey** The `localStorage` key used to persist consent. You may change this freely if you need per-site or per-environment isolation. - **categories.analytics** Allows analytics scripts to load only after consent. Typical use: Plausible, self-hosted analytics, Google Analytics. - **categories.marketing** Allows marketing and advertising scripts to load only after consent. Typical use: ad pixels, remarketing tags, embedded social trackers. Scripts outside the **essential** category must be conditionally loaded. --- ## ๐Ÿง  Frontend API ```js window.cookieConsent.get(); window.cookieConsent.set({ essential: true, analytics: true }); window.cookieConsent.reset(); ``` ## ๐Ÿงพ TypeScript TypeScript declarations are included in the package. No separate `@types` install is required. --- ## ๐ŸŽจ Theming All visuals are controlled via: ``` src/cookiebanner.css ``` You must ensure this file is included globally. ### Recommended import (Astro) Import the stylesheet once in your main layout or entry file: ```ts import "../cookiebanner.css"; ``` This guarantees the banner styles are available on every page. - This file is never overwritten - All colours, spacing, radius, and animations are controlled via CSS variables - Full visual control with zero JavaScript theming --- ## ๐Ÿ” Privacy - No cookies before consent - No tracking without permission - No external requests - Stored locally with TTL --- ## ๐Ÿ™ Acknowledgements Thanks to [@magicspon](https://github.com/magicspon) for assisting with the PR and issue triage. --- ## ๐Ÿ“„ License MIT ยฉ Velohost --- ## ๐Ÿข Velohost https://velohost.co.uk/