Home

Awesome

⚠️ WARNING: This is an old project and the law has now changed. Do not use it in production as it may not be compliant with the new regulation! ⚠️


Helping webmasters comply with the EU cookie law

Why?

The EU passed a law some years ago that required all websites to warn about the dangers of cookies. I'm not going to comment on it here; if you want my opinion, please read this blogpost

It is now being enforced and some people are being fined, so it requires urgent action

What does this mean for me?

What this law means for developers is that some Analytics cookies can't be set unless the user grants consent. Every country has a different interpretation of the EU directive, but in Spain, just displaying a "cookie banner" is not enough. No cookies can be set until the user takes action. This is a real PITA, especially for small sites.

This script helps webmasters track user action. Using the Spanish interpretation (page 22), consent is either:

By using this script, webmasters can add all their cookie-dependent code in just one place: doConsent()

Does it affect me?

The directive affects all websites which are based in the EU or have a significant amount (vague legal term) of visits coming from the EU.

The Spanish interpretation of the directive establishes that personal pages which do not offer commercial services are not affected by the law. I, however, prefer to include the banner nevertheless.

I am not a lawyer, so this is not legal advice.

Demo

  1. Clone this project
  2. Open demo.html in your browser
  3. Open your javascript console
  4. See how the cookie is set when the user closes the box, scrolls or clicks on a link

Tip: Chrome does not allow local files to set cookies, so this demo won't work on Chrome.

You can see an online demo at my own page, which uses this same javascript

To implement it in production

Optional:

How does it work?

The cookie div is hidden by default with CSS and will be displayed, if needed, by consent.js. The script:

How to grant consent?

The law establishes the following user actions:

These two actions can be derived from the former:

What does not grant consent?

Pull requests and comments will be very welcome!

Donations

If this project saved you some time, please donate to the EFF so they can fight against stupid laws.

License

ISC License

Copyright (c) 2014-2016, Carlos Fenollosa (carlos.fenollosa@gmail.com)

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.