The Consent / Cookies library provides a complete consent management solution: a banner UI component, a preference model, analytics gating logic, and a persistence layer. Applications integrate it to collect, store, and enforce user consent choices in compliance with GDPR, CCPA, and similar regulations. All analytics and tracking scripts are gated on consent state, preventing execution until the user grants permission.
Goals
Provide a composable consent banner component with accept-all, reject-all, and customize options.
Model consent preferences as a typed, serializable structure with granular categories (necessary, analytics, marketing, functional).
Gate analytics and tracking script loading on consent state via a programmatic API.
Persist consent choices in cookies with configurable expiration and domain scope.
Support server-side consent checks for SSR applications.
Non-Goals
Implementing a full Consent Management Platform (CMP) with vendor tag management.
Providing legal advice or jurisdiction-specific consent text.
A logical grouping of cookies/scripts: necessary (always allowed), analytics, marketing, functional
Consent banner
The initial UI prompting the user to accept, reject, or customize cookie preferences
Preference center
A detailed UI showing all consent categories with individual toggles
Analytics gating
The mechanism that prevents analytics/tracking scripts from loading until consent is granted
Consent cookie
The cookie storing the user’s serialized consent preferences
Current State
Existing Behavior
No shared consent management solution exists. Each application implements its own banner, storage, and gating logic.
Current Limitations
No standardized consent preference model across applications.
No shared banner component; each app builds its own with varying accessibility quality.
Analytics scripts often load unconditionally or rely on ad-hoc gating.
No SSR-compatible consent check; server-rendered pages cannot adapt to consent state.
Existing Workarounds
Developers copy consent banner implementations between projects.
Some apps use third-party CMP tools (OneTrust, CookieBot) but these are heavyweight and inconsistently configured.
Analytics gating is done with manual if checks scattered through initialization code.
Proposed Solution
Summary
Ship a TypeScript + React library (@dmwd/consent) providing a ConsentBanner component, a PreferenceCenter component, a ConsentProvider context, a useConsent() hook, cookie-based persistence, and an isConsentGranted() gating function.
Key Capabilities
ConsentBanner component with accept-all, reject-all, and customize buttons.
PreferenceCenter component with per-category toggles and save/cancel actions.
ConsentProvider wrapping the app to provide consent context.
useConsent() hook returning current preferences and update functions.
isConsentGranted(category) for programmatic checks (works on server and client).
ConsentGate component for conditionally rendering children based on consent.
Cookie persistence with configurable name, TTL, domain, and SameSite attribute.
User Experience
On first visit, users see a consent banner at the bottom of the viewport. They can accept all, reject all (keeping only necessary cookies), or open the preference center to choose categories individually. Their choice persists across sessions. Returning users see no banner unless consent has expired.
Developer Experience
Developers wrap their app in ConsentProvider, place ConsentBanner in their layout, and wrap analytics scripts in ConsentGate category="analytics". The useConsent() hook provides the current state for custom logic.
Requirements
ID
Requirement
Priority
Notes
FR-001
The library must export a ConsentBanner component
Must
Primary UI
FR-002
The library must export a PreferenceCenter component
Must
Granular control
FR-003
The library must export a ConsentProvider context
Must
State management
FR-004
The library must export a useConsent() hook
Must
Programmatic access
FR-005
The library must export an isConsentGranted(category) function
Must
Gating logic
FR-006
The library must export a ConsentGate component
Must
Declarative gating
FR-007
Consent must persist in cookies with configurable TTL
Must
GDPR requires re-consent
FR-008
The necessary category must always be enabled and not toggleable
Must
Legal requirement
Priority Definitions
Priority
Meaning
Must
Required for this feature to ship.
Should
Important, but can be deferred if needed.
Could
Nice to have. Not required for initial release.
Functional Requirements
ID
Requirement
User Benefit
Priority
FUNC-001
ConsentBanner renders with accept-all, reject-all, and customize buttons
Users have clear choices
Must
FUNC-002
Clicking accept-all grants all categories and dismisses the banner
Quick opt-in
Must
FUNC-003
Clicking reject-all grants only necessary and dismisses the banner
Quick opt-out
Must
FUNC-004
Clicking customize opens the PreferenceCenter
Granular control
Must
FUNC-005
PreferenceCenter shows a toggle for each non-necessary category
Users can choose individually
Must
FUNC-006
PreferenceCenter has save and cancel actions
Users confirm or discard changes
Must
FUNC-007
ConsentGate category="analytics" renders children only when analytics consent is granted