Skip to content

joseba-mirena/cookie-guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cookie Guard ๐Ÿ›ก๏ธ

GDPR/CCPA compliance Cookies Consent Management.

Version License Size

A GDPR/CCPA 2026 compliance, simple and customizable Cookies Management system.

๐Ÿ’ก The Truth About Cookie Consent

Cookie consent compliance is NOT as complicated as some companies want you to believe.

Many "compliance solutions" charge hundreds or thousands of euros per year, claiming you need:

  • โŒ Complex backend databases to store consent
  • โŒ IP tracking and user accounts
  • โŒ Expensive legal teams
  • โŒ Monthly subscription fees

They are lying and fear-mongering to scare you into paying.

The Reality (Backed by GDPR/CCPA):

What you DON'T need What you ACTUALLY need
Backend database Cookie stored in user's browser โœ…
IP address logging Timestamp in the cookie โœ…
User accounts Consent/Reject buttons โœ…
Monthly subscription Free tools like Cookie Guard โœ…
Legal team on retainer Clear privacy policy + contact info โœ…

Cookie Guard Does Everything Required:

  • โœ… Blocks third-party scripts until consent
  • โœ… Stores consent preferences (with timestamp)
  • โœ… Provides granular controls (Analytics/Marketing)
  • โœ… Offers easy opt-out (Reject All button)
  • โœ… Works across 22 languages
  • โœ… Completely FREE and open source

Don't Be Scared. Be Informed.

Cookie consent compliance is about respecting user privacy - not about complex systems or expensive subscriptions.

See the compliance table below for exactly what GDPR/CCPA requires.


โš ๏ธ Warning: While cookie consent is manageable, non-compliance CAN result in fines (up to โ‚ฌ20 million or 4% of global revenue). However, a proper implementation like Cookie Guard + a simple privacy policy is perfectly sufficient to be compliant.

Don't let fear-mongering companies trick you. You've got this. ๐Ÿ’ช


MAIN FEATURES

  • Legal Compliance: Fully GDPR/CCPA compliant workflow (2026 standards).
  • Hybrid Modes: Supports both full third-party consent and "no-cookies" informational mode.
  • Smart Execution: Auto-activates Analytics/Marketing scripts (handles type="text/plain").
  • Zero Dependencies: Pure Vanilla JavaScript; no jQuery or external libraries required.
  • Privacy Focus: Optional persistent "Privacy" floating button to re-open settings.
  • Legal Terms: Optional acceptance and Legal URL smart handling.
  • Global Reach: Support for 22 languages (LTR & RTL) with automatic browser detection.
    • Locales: en, es, ca, eu, gl, et, ar, pt, pl, vi, fr, de, it, ru, zh, ja, id, ko, tr, nl, hi, bn.
  • Performance: Ultra-lightweight architecture (~13 kB minified).
  • Accessibility: Implements ARIA standards for screen readers.
  • Encapsulation: Built within an IIFE to ensure no global namespace pollution.
  • UI/UX: Dynamic CSS/HTML injection with a fully responsive, mobile-first design.
  • Customization: Flexible configuration for expiration, link colors, and button border-radius.
  • Developer API: Public toggle, open, and reset methods for external control.

๐Ÿ“ฆ Installation

Add the minified version before the closing </body> tag:

<script 
    src="https://opensource.josebamirena.com/cookie-guard/3.4.0/dist/cookie-guard.min.js" 
    integrity="sha384-dRLgdAlVcDUp1BQffo1IH08fUouMfMdVCOZBZEEGD9uI+Nw6wWtNLLw+7p8U1bYD" 
    crossorigin="anonymous">
</script>

โš™๏ธ Configuration

Cookie Guard default Initialization

<script>
    document.addEventListener('DOMContentLoaded', () => CookieGuard.init());
</script>

Initialization default variables and values

Property Type Default Description
locale string auto 'auto' or 2-letter language ISO code.
consent boolean true true for 3rd party scripts, false for info-only banner.
url string null Relative URL to your legal/cookies policy page.
reopen boolean true Renders the floating privacy button.
radius integer 12 Buttons border-radius in pixels.
delay integer 800 Modal entrance delay in milliseconds.
link string #3b82f6 Primary link color.
hover string #10b981 Link hover color.
separator string โ€ข Modal footer links separator
expiration integer 365 Consent cookie expiration in days.
<script>
    const defaults = {
        locale: 'auto', // @string 'auto' or 2-letter ISO code.
        consent: true, // @bool true for 3rd party scripts, false for info-only banner.
        url: null, // @null|string Relative URL to your legal/cookies policy page.
        reopen: true, // @bool Renders the floating privacy button.
        radius: 12, // @int Buttons border-radius in pixels.
        delay: 800, // @int Modal entrance delay in milliseconds.
        link: "#3b82f6", // @string Primary link color.
        hover: "#10b981", // @string Link hover color.
        separator: "โ€ข", // @string Modal footer links separator
        expiration: 365, // @int Consent cookie expiration in days.
    };
</script>

Cookie Guard Customized Example

<script>
    document.addEventListener('DOMContentLoaded', () => 
        CookieGuard.init({
            locale: 'en', // fixed language
            url: "/legal", // legal relative url
            link: "#ff0000", // red links
            radius: 8, // buttons radius
        })
    );
</script>

Cookie Guard non third party cookies mode

<script>
    document.addEventListener('DOMContentLoaded', () => 
        CookieGuard.init({
            locale: 'auto', // auto detect language
            consent: false, // no third party cookies mode
        })
    );
</script>

๐Ÿ› ๏ธ Script Implementation

To let Cookie Guard manage your scripts, add the type attribute text/plain and add the data-cg-category attribute (analytics|marketing):

Test script example

<script 
    type="text/plain" 
    data-cg-category="analytics">
    console.log('Analytics script executed');
</script>

Analytics script example

<script 
    type="text/plain" 
    data-cg-category="analytics" 
    src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXX-Y">
</script>

Marketing script example

<script type="text/plain" data-cg-category="marketing">
    console.log("Facebook pixel is legally enabled.");
    fbq('init', '123456789');
    fbq('track', 'PageView');
</script>

๐Ÿ•น๏ธ Developer API

Toggle Modal

<a href="javascript:void(0)" onclick="CookieGuard.toggle()">Privacy</a>

Force Open

<a href="javascript:void(0)" onclick="CookieGuard.open()">Open Privacy</a>

Hard Reset:

Debug Shortcut: CTRL + SHIFT + X to reset state instantly.

<a href="javascript:void(0)" onclick="CookieGuard.reset()">Reset Privacy</a>

๐Ÿ“‹ Legal Compliance

Cookie Guard is fully compliant with both GDPR (EU) and CCPA/CPRA (California) requirements.

Requirement GDPR CCPA Cookie Guard
Consent Model โœ… Opt-in โœ… Opt-out Reject All button + Privacy button
Default State โœ… Blocked โœ… No selling Analytics/Marketing default to false
Pre-ticked Boxes โœ… Forbidden โœ… N/A* All non-essential toggles start unchecked
Essential Cookies โœ… No consent needed โœ… No consent needed Essential category locked & pre-checked
Accept All Button โœ… Required โœ… Recommended One-click accept all categories
Reject All Button โœ… Required โœ… Recommended One-click reject non-essential
Granular Controls โœ… Required โœ… Recommended Separate toggles for Analytics & Marketing
Persistent Access โœ… Required โœ… Required Floating privacy button for settings
Consent Records โœ… Required โœ… Recommended Cookie stores preferences + timestamp
Easy Withdrawal โœ… Required โœ… Required Reset method + reconfigure anytime
Cookie Information โœ… Required โœ… Recommended Built-in modal explains each category

๐Ÿ”’ Compliance Summary

  • GDPR: Full opt-in consent for all non-essential cookies
  • CCPA/CPRA: Easy opt-out mechanism + no data selling
  • Global: Respects user privacy across 22 languages
  • Audit Ready: Consent records stored with timestamps

๐Ÿ“– Required Website Documentation

For complete legal compliance, website owners must provide:

  1. Privacy Policy - How you collect, use, and protect personal data
  2. Contact Information - Clear way for users to exercise their rights

๐Ÿ“Œ Note: Cookie Guard includes built-in Cookie Policy with category descriptions. Only a separate Privacy Policy page (with contact information) is needed for personal data handling.


โš ๏ธ Important Disclaimer for Website Owners

Cookie Guard is a free, open-source tool that provides the technical framework for cookie consent management. It does NOT constitute legal advice.

As a website owner using Cookie Guard, you are responsible for:

  1. Maintaining your own Privacy Policy that accurately reflects your data handling practices
  2. Providing a contact method (email, contact form, or page) for users to exercise their GDPR/CCPA rights
  3. Ensuring your legal terms accurately describe your specific data collection and processing activities
  4. Complying with all applicable laws in your jurisdiction

Cookie Guard helps you implement consent management, but you must:

  • โœ… Inform users about YOUR specific data practices
  • โœ… Provide YOUR contact information for privacy requests
  • โœ… Maintain YOUR own privacy policy and legal terms

This tool is provided "as is" without warranty of any kind. Consult a legal professional for advice on your specific compliance requirements.


๐Ÿš€ Ready to Use

Cookie Guard gives you the technical foundation. Add your privacy policy and contact information, and you're fully compliant!

๐ŸŒ Supported Languages (22)

Code Language Direction
ar ๐Ÿ‡ธ๐Ÿ‡ฆ Arabic RTL
bn ๐Ÿ‡ง๐Ÿ‡ฉ Bengali LTR
ca ๐Ÿด๓ ฅ๓ ณ๓ ฃ๓ ด๓ ฟ Catalan LTR
de ๐Ÿ‡ฉ๐Ÿ‡ช German LTR
en ๐Ÿ‡ฌ๐Ÿ‡ง English LTR
es ๐Ÿ‡ช๐Ÿ‡ธ Spanish LTR
et ๐Ÿ‡ช๐Ÿ‡ช Estonian LTR
eu ๐Ÿด๓ ฅ๓ ณ๓ ฐ๓ ถ๓ ฟ Basque LTR
fr ๐Ÿ‡ซ๐Ÿ‡ท French LTR
gl ๐Ÿด๓ ฅ๓ ณ๓ ง๓ ก๓ ฟ Galician LTR
hi ๐Ÿ‡ฎ๐Ÿ‡ณ Hindi LTR
id ๐Ÿ‡ฎ๐Ÿ‡ฉ Indonesian LTR
it ๐Ÿ‡ฎ๐Ÿ‡น Italian LTR
ja ๐Ÿ‡ฏ๐Ÿ‡ต Japanese LTR
ko ๐Ÿ‡ฐ๐Ÿ‡ท Korean LTR
nl ๐Ÿ‡ณ๐Ÿ‡ฑ Dutch LTR
pl ๐Ÿ‡ต๐Ÿ‡ฑ Polish LTR
pt ๐Ÿ‡ต๐Ÿ‡น Portuguese LTR
ru ๐Ÿ‡ท๐Ÿ‡บ Russian LTR
tr ๐Ÿ‡น๐Ÿ‡ท Turkish LTR
vi ๐Ÿ‡ป๐Ÿ‡ณ Vietnamese LTR
zh ๐Ÿ‡จ๐Ÿ‡ณ Chinese LTR

๐Ÿ“ Changelog from 3.0.0

v3.4.0 - Performance Release

  • Minified size 13 kB.

Added

  • Added wording localStorage cache (eliminates redundant network requests)

Updated

  • Wording files optimized
  • Code weight optimization
  • Updated main buttons accessibility
  • Updated default consent to false
  • Updated main documentation

Previous Changes (v3.2.0)

Added

  • Added aria-label to legal acceptance checkbox for better screen reader support

Fixed

  • Fixed missing aria-labelledby attribute in minified version (modal dialog now properly labeled)
  • Fixed "uncrawlable link" for policy link

Previous Changes (v3.0.0)

  • โœ… 2026 GDPR/CCPA compliance workflow.
  • โœ… Added support for sites not using 3rd party cookies.
  • โœ… i18n 22 languages, LTR & RTL, with dynamic JSON loading.
  • โœ… Optimization: Minified size reduced from 38.8 kB to 12.8 kB.
  • โœ… Added reset Cookies public method and Shortcut (CTRL+SHIFT+X).
  • โœ… UX: Improved modal animations and RTL support.
  • โœ… Performance improvements.
  • โœ… Security improvements.
  • โœ… Proprietary to MIT license.
  • โš ๏ธ Version 2.0.0 deprecated.

๐ŸŽฏ Live Demo

Try Cookie Guard live on my website:
๐Ÿ‘‰ Cookie Guard Demo

See how it handles consent, 22 languages, and third-party script blocking in action.

About

Open Source lightweight cookie consent manager for GDPR/CCPA compliance. Vanilla JavaScript, 22 languages, RTL support, zero dependencies. No jQuery. No dark patterns.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors