cookieconsent
:cookie: Simple cross-browser cookie-consent plugin written in vanilla js
Top Related Projects
A free solution to the EU, GDPR, and California Cookie Laws
Klaro Privacy Manager. An open-source, privacy-friendly & compliant consent manager for your website.
Quick Overview
CookieConsent is a lightweight JavaScript library for managing cookie consent on websites. It provides a customizable and user-friendly interface for obtaining user consent for various types of cookies and tracking technologies, helping website owners comply with privacy regulations such as GDPR and CCPA.
Pros
- Highly customizable appearance and behavior
- Supports multiple languages and easy localization
- Lightweight and fast-loading (less than 5KB gzipped)
- No dependencies, pure JavaScript implementation
Cons
- Limited built-in styling options (requires custom CSS for advanced designs)
- May require additional configuration for complex consent scenarios
- Documentation could be more comprehensive for advanced use cases
- No built-in integration with popular analytics platforms
Code Examples
- Basic initialization:
CookieConsent.run({
categories: {
necessary: {},
analytics: {}
},
language: {
default: 'en',
translations: {
en: {
consentModal: {
title: 'We use cookies',
description: 'This website uses cookies to enhance your browsing experience.'
}
}
}
}
});
- Checking consent status:
if (CookieConsent.acceptedCategory('analytics')) {
// Initialize analytics
}
- Updating consent preferences:
document.querySelector('#open-settings').addEventListener('click', function() {
CookieConsent.showSettings();
});
Getting Started
- Include the CookieConsent script in your HTML:
<script src="https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@v3.0.0/dist/cookieconsent.js"></script>
- Initialize CookieConsent with basic configuration:
CookieConsent.run({
categories: {
necessary: {},
analytics: {}
},
language: {
default: 'en',
translations: {
en: {
consentModal: {
title: 'We use cookies',
description: 'This website uses cookies to enhance your browsing experience.'
},
categories: {
necessary: {
title: 'Necessary cookies',
description: 'These cookies are essential for the website to function properly.'
},
analytics: {
title: 'Analytics cookies',
description: 'These cookies help us understand how visitors interact with the website.'
}
}
}
}
}
});
This basic setup creates a consent modal with two categories: necessary and analytics. Customize the content and add more categories as needed for your website.
Competitor Comparisons
A free solution to the EU, GDPR, and California Cookie Laws
Pros of Cookieconsent (Osano)
- More established project with a larger community and longer history
- Offers additional features like geolocation support and automatic language detection
- Provides a user-friendly interface for customization without coding
Cons of Cookieconsent (Osano)
- Larger file size, which may impact page load times
- Less flexible for advanced customization compared to the lightweight alternative
- Requires more setup and configuration for complex use cases
Code Comparison
Cookieconsent (Osano):
window.cookieconsent.initialise({
"palette": {
"popup": { "background": "#000" },
"button": { "background": "#f1d600" }
},
"content": { "message": "This website uses cookies." }
});
Cookieconsent (Orestbida):
CookieConsent.run({
guiOptions: {
consentModal: {
layout: "box",
position: "bottom right",
equalWeightButtons: true,
flipButtons: false
},
preferencesModal: {
layout: "box",
position: "right",
equalWeightButtons: true,
flipButtons: false
}
},
categories: {
necessary: {}
}
});
The Osano version focuses on simple color customization and content, while the Orestbida version offers more detailed configuration options for layout and functionality.
Klaro Privacy Manager. An open-source, privacy-friendly & compliant consent manager for your website.
Pros of Klaro
- More extensive customization options for UI and functionality
- Built-in support for multiple languages and translations
- Better integration with popular content management systems (CMS)
Cons of Klaro
- Larger file size and potentially slower load times
- Steeper learning curve due to more complex configuration options
- Less frequent updates and maintenance compared to CookieConsent
Code Comparison
CookieConsent:
cookieconsent.run({
categories: {
necessary: {},
analytics: {}
},
language: {
default: 'en',
translations: {
en: {
consentModal: {
title: 'We use cookies',
description: 'Cookie description'
}
}
}
}
});
Klaro:
var klaroConfig = {
apps: [
{
name: 'analytics',
title: 'Analytics',
purposes: ['analytics']
}
],
translations: {
en: {
consentModal: {
title: 'We use cookies',
description: 'Cookie description'
}
}
}
};
Both libraries offer similar basic functionality for managing cookie consent, but Klaro provides more granular control over individual services and their purposes. CookieConsent's configuration is generally simpler and more straightforward, while Klaro offers more advanced features at the cost of increased complexity.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
CookieConsent v3
A lightweight & gdpr compliant cookie consent plugin written in plain javascript.
Demo
Check out the playground.
There are also a few examples available on Stackblitz.
Documentation
Docs. available at cookieconsent.orestbida.com.
Contributing
Please read the contribution guide.
Thanks to all the people who already contributed!
A special thanks goes Till Sanders for creating and maintaining the npm package!
License
Distributed under the MIT License. See LICENSE for more information.
Top Related Projects
A free solution to the EU, GDPR, and California Cookie Laws
Klaro Privacy Manager. An open-source, privacy-friendly & compliant consent manager for your website.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot