CookieBanner component provides a privacy-compliant cookie consent system with geographic detection, granular permission controls, and Global Privacy Control (GPC) support.
Features
- Privacy Compliance: GDPR, CCPA, CPA, LGPD, and PIPEDA compliant
- Geographic Detection: Only shows banner in regions requiring consent
- Global Privacy Control: Automatically respects GPC browser signals
- Granular Controls: Essential, analytics, and personalization categories
- Compact & Expanded Views: Clean UI with detailed settings panel
- Analytics Integration: Automatically loads/unloads Google Analytics
- Settings Persistence: Saves preferences for 365 days
Installation
Usage
Typically included in the main layout:src/layouts/Layout.astro
Props
This component does not accept any props. All configuration is internal or environment-based.Cookie Categories
Required cookies for basic site functionality. Cannot be disabled.
- Session management
- Security tokens
- Basic preferences
Anonymous usage data collection via Google Analytics.
- Page views and navigation
- Anonymous IP addresses
- Performance metrics
- GA ID:
G-T4PD8XC0SC
Remembers user settings and preferences.
- Accessibility settings
- UI preferences
- Saved form data
User Interface
Compact Bar
Initial view shown to users:Expanded Settings Panel
Detailed controls accessible via “Settings” button:- Individual toggles for each cookie category
- GPC detection notice (if applicable)
- Privacy policy link
- “Decline All”, “Save”, and “Accept All” buttons
Geographic Detection
The component uses the geolocation API to determine if consent is required:- GDPR: European Union countries
- CCPA: California, USA
- CPA: Colorado Privacy Act
- LGPD: Brazil
- PIPEDA: Canada
- If in a regulated jurisdiction: Shows banner after 1.5 seconds
- If not regulated: Automatically accepts all cookies
- If API fails: Shows banner after 2 seconds (fail-safe)
Global Privacy Control (GPC)
Automatic detection and respect for GPC browser signals:- Shows green notice in settings panel
- Defaults to minimal tracking
- Respects user’s privacy preference
Analytics Integration
The component automatically manages Google Analytics loading:Load Analytics
Unload Analytics
Cookie Storage
Preferences are stored in a browser cookie:- Name:
cookie-preferences - Expiration: 365 days
- Path:
/(site-wide) - SameSite:
Strict - Format: JSON object
API Integration
The component integrates with other components:AccessibilityMenu Integration
Programmatic Access
Show settings from elsewhere in your app:Keyboard Navigation
Tab: Navigate through controlsSpace/Enter: Toggle switches and click buttonsEscape: Close expanded panel
Responsive Design
Mobile-specific adjustments:Privacy Commitments
The banner includes privacy statements:- “We do not sell or share your personal information”
- Links to privacy policy
- Clear category descriptions
- Opt-in by default (except essential)
Customization
Change Analytics ID
Update the Google Analytics ID:Modify Timing
Change when the banner appears:Add Cookie Categories
Extend the preferences interface:Testing
Test Geographic Detection
Use VPN or modify the API response:Test GPC Detection
Enable GPC in browser settings (Brave, Firefox with extension):Clear Saved Preferences
Accessibility
- ARIA roles and labels
- Keyboard navigation
- Focus management
- Clear, plain language
- High contrast toggle styles
Related Components
- AccessibilityMenu: Uses cookie consent to determine if settings can be saved
- Layout: Where CookieBanner is typically included