Open-source primitives for building cookie banners and preferences.
Consent logic, not consent UI.
OpenCookies gives you a tiny, headless state machine and framework-native hooks for managing user consent. You write the banner. We handle the rules.
Most consent libraries ship a banner with the logic baked in. You either bend your design to match theirs or fight the library every step of the way.
OpenCookies takes the opposite approach. The state machine, expressions, storage, and script gating are all yours to use — the UI is whatever you build around them.
# React
npm install @opencookies/core @opencookies/react
# Vue
npm install @opencookies/core @opencookies/vue
# Solid
npm install @opencookies/core @opencookies/solid
# Svelte
npm install @opencookies/core @opencookies/svelte
# Angular
npm install @opencookies/core @opencookies/angular
import { OpenCookiesProvider, useConsent, ConsentGate } from "@opencookies/react";
const config = {
categories: [
{ key: "essential", label: "Essential", locked: true },
{ key: "analytics", label: "Analytics" },
{ key: "marketing", label: "Marketing" },
],
};
function App() {
return (
<OpenCookiesProvider config={config}>
<YourApp />
<CookieBanner />
</OpenCookiesProvider>
);
}
function CookieBanner() {
const { route, acceptAll, acceptNecessary, setRoute } = useConsent();
if (route !== "cookie") return null;
return (
<div className="your-styles-here">
<p>We use cookies to improve your experience.</p>
<button onClick={acceptAll}>Accept all</button>
<button onClick={acceptNecessary}>Necessary only</button>
<button onClick={() => setRoute("preferences")}>Customise</button>
</div>
);
}
// Gate third-party code on consent
<ConsentGate requires="analytics">
<GoogleAnalytics />
</ConsentGate>;
// vite.config.ts
import openCookies from "@opencookies/vite";
export default {
plugins: [openCookies({ mode: "warn" })],
};
The plugin scans your code for cookie writes and known third-party vendors, and flags any that aren't behind a ConsentGate or has() check.
| Package | Description |
|---|---|
@opencookies/core |
Headless consent store, GPC handling, jurisdiction resolvers, script gating, storage adapters |
@opencookies/react |
React 18+ adapter — useConsent, useCategory, <ConsentGate> |
@opencookies/vue |
Vue 3 adapter — plugin or <OpenCookiesProvider>, composables, <ConsentGate> |
@opencookies/solid |
Solid adapter — signals-based hooks and provider |
@opencookies/svelte |
Svelte 5 runes adapter (+ Svelte 4 Readable fallback at /stores) |
@opencookies/angular |
Angular 18+ adapter — provideOpenCookies, ConsentService, injectCategory, *ocConsent |
@opencookies/scanner |
Static AST detection of cookie writes and vendor scripts |
@opencookies/vite |
Vite plugin: surfaces ungated cookie / vendor calls in dev and CI |
@opencookies/cli |
Terminal UI for scans and config sync (scaffold) |
@opencookies/scripts |
Pre-built script integrations: GA4, Meta Pixel, PostHog, Segment, GTM, Hotjar |
Until a docs site lands, each package README is the canonical reference. Shared concepts (categories, GPC, jurisdiction, re-consent triggers, script gating, storage adapters) live in @opencookies/core; the framework adapters are thin wrappers over it.
OpenCookies pairs with OpenPolicy for the full privacy story: a single config drives your cookie banner, your cookie policy document, and your privacy policy disclosures. They work great together — and just as well apart.
Pre-1.0 and under active development. APIs may change before v1. Track progress on the roadmap.