Sign inSign up

timdoddcool/cookiedialog

By timdoddcool

•Updated about 1 year ago

CookieDialog Documentation - GDPR Cookie Consent Library

Image
0

1.1K

timdoddcool/cookiedialog repository overview

CookieDialog Logo

⁠CookieDialog

A lightweight, customizable GDPR cookie consent dialog with built-in geolocation support. Zero dependencies, easy integration via CDN or NPM.

npm version Bundle Size License: MIT

⁠Features

  • šŸš€ Lightweight - Less than 20KB gzipped
  • šŸ“ Geolocation Detection - Automatically detect if GDPR compliance is required
  • šŸ’¾ Local Storage - Persistent consent management
  • šŸŽØ Customizable - Multiple themes and full translation support
  • šŸ“± Responsive - Mobile-friendly design
  • šŸ”§ Zero Dependencies - Pure JavaScript, no external libraries required
  • ⚔ Easy Integration - Simple CDN or NPM installation

⁠Quick Start

⁠CDN Installation

Add these lines to your HTML:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/cookiedialog.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cookiedialog.min.js"></script>

<script>
  CookieDialog.init({
    enableLocation: true,
    privacyUrl: '/privacy',
    onAccept: (consent) => {
      console.log('Consent given:', consent);
    }
  });
</script>
⁠NPM Installation
npm install cookiedialog
import CookieDialog from 'cookiedialog';
import 'cookiedialog/dist/cookiedialog.min.css';

const dialog = new CookieDialog({
  enableLocation: true,
  theme: 'dark',
  position: 'bottom'
});

dialog.init();

⁠Configuration Options

OptionTypeDefaultDescription
enableLocationbooleanfalseEnable geolocation detection for GDPR regions
autoShowbooleantrueAutomatically show dialog on page load
positionstring'bottom'Dialog position: 'bottom', 'top', or 'center'
themestring'light'Theme: 'light' or 'dark'
privacyUrlstringundefinedURL to your privacy policy
cookiePolicyUrlstringundefinedURL to your cookie policy
expiryDaysnumber365Consent expiry in days
forceShowbooleanfalseAlways show dialog regardless of consent
categoriesarray[...]Cookie categories configuration
translationsobject{...}Custom translations
onAcceptfunctionundefinedCallback when user accepts (includes reason and location data)
onRejectfunctionundefinedCallback when user rejects
onChangefunctionundefinedCallback when settings change
onLocationNotRequiredfunctionundefinedCallback when geolocation determines consent not needed

⁠API Methods

const dialog = CookieDialog.init(config);

// Show/hide dialog
dialog.show();
dialog.hide();

// Get consent status
const consent = dialog.getConsent();
// Returns: { 
//   timestamp: 123456789, 
//   categories: { necessary: true, analytics: false }, 
//   version: '1.0.0',
//   reason: 'user_accept' | 'user_reject' | 'location_not_required',
//   locationData?: { country: 'US', region: 'California', inEU: false, detectionMethod: 'ip_geolocation' }
// }

// Check if consent exists
const hasConsent = dialog.hasConsent(); // boolean

// Get specific category consent
const analyticsConsent = dialog.getCategoryConsent('analytics'); // boolean

// Reset consent
dialog.resetConsent();

// Destroy dialog
dialog.destroy();

⁠Custom Categories

CookieDialog.init({
  categories: [
    {
      id: 'necessary',
      name: 'Essential Cookies',
      description: 'Required for the website to function',
      required: true
    },
    {
      id: 'analytics',
      name: 'Analytics',
      description: 'Help us understand how you use our site',
      required: false
    },
    {
      id: 'marketing',
      name: 'Marketing',
      description: 'Used for targeted advertising',
      required: false
    }
  ]
});

⁠Custom Translations

CookieDialog.init({
  translations: {
    title: 'Cookie Preferences',
    description: 'We use cookies to improve your experience',
    acceptButton: 'Accept All',
    rejectButton: 'Reject All',
    settingsButton: 'Manage Settings',
    privacyLink: 'Privacy Policy',
    // ... more translations
  }
});

⁠Geolocation Detection

When enableLocation is enabled, the dialog will automatically detect if the user is in a GDPR-required region (EU/EEA) and only show the dialog if necessary.

CookieDialog.init({
  enableLocation: true,
  geolocationEndpoint: 'https://your-api.com/location', // Optional custom endpoint
  onLocationNotRequired: (locationData) => {
    console.log('GDPR not required for:', locationData);
    // User is not in EU/EEA - all cookies automatically accepted
  },
  onAccept: (consent) => {
    if (consent.reason === 'location_not_required') {
      console.log('Auto-accepted due to location:', consent.locationData);
    } else if (consent.reason === 'user_accept') {
      console.log('User manually accepted cookies');
    }
  }
});

⁠Browser Support

  • Chrome/Edge 88+
  • Firefox 78+
  • Safari 14+
  • Opera 74+

⁠Development

# Install dependencies
npm install

# Development build with watch
npm run dev

# Production build
npm run build

# Run tests
npm test

⁠License

MIT License - see LICENSE⁠ file for details.

⁠Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

⁠Documentation

šŸ“š Full documentation available at:

Docker (Self-hosted):

docker run -p 8080:80 timdoddcool/cookiedialog:latest
# Visit http://localhost:8080

Online: cookiedialog.com⁠

See DOCKER.md⁠ for detailed deployment instructions.

⁠Support

For issues and feature requests, please use the GitHub issues page⁠.

Tag summary

Content type

Image

Digest

sha256:a57c48431…

Size

22 MB

Last updated

about 1 year ago

docker pull timdoddcool/cookiedialog