GithubHelp home page GithubHelp logo

infinum / cookies_eu Goto Github PK

View Code? Open in Web Editor NEW
267.0 19.0 89.0 239 KB

Gem to add cookie consent to Rails application

License: MIT License

Ruby 17.93% JavaScript 15.17% HTML 7.26% SCSS 9.16% Haml 50.48%

cookies_eu's Introduction

Gem Version

CookiesEu

Gem to add cookie consent to rails application

Supported languages

  • Albanian
  • Basque
  • Bulgarian
  • Catalan
  • Croatian
  • Czech
  • Danish
  • Dutch
  • English
  • Estonian
  • Finnish
  • French
  • German
  • Greek
  • Hebrew
  • Hungarian
  • Italian
  • Lithuanian
  • Norwegian
  • Polish
  • Portuguese
  • Romanian
  • Russian
  • Slovenian
  • Spanish
  • Swedish
  • Turkish
  • Ukrainian

Screenshot

Cookies eu screenshot

Installation

Add this line to your application's Gemfile:

gem 'cookies_eu'

And then execute:

$ bundle

Run the installation generator:

$ bundle exec rails g cookies_eu:install

Or manually add in application.js:

//= require cookies_eu

And in application.css:

*= require cookies_eu

Or, if you have application.scss:

@import "cookies_eu";

Remember to restart your server!

Usage

In your view add

= render 'cookies_eu/consent_banner'

You can add a link parameter to link to your cookies explanation page (you have to create the page and controller for this)

= render 'cookies_eu/consent_banner', link: '/cookies'

You can add a target parameter to the link to open in a new tab

= render 'cookies_eu/consent_banner', link: '/cookies', target: '_blank'

If you wish to customize the style of the div the classes are:

.cookies-eu                 /* main div */
.cookies-eu-content-holder  /* content holder */
.cookies-eu-button-holder   /* button holder */
.cookies-eu-ok              /* button */
.cookies-eu-link            /* link */

If you wish to customize the HTML, create a folder cookies_eu, create a partial _consent_banner.html.erb and paste the HTML from here

If you wish to run some arbitrary code when the user acknowledges the cookie message, you can register a callback. This is useful if you wish to persist the user's preference to the database.

document.addEventListener('cookies-eu-acknowledged', function() {
  // The user has acknowledged cookies! If they're logged in, make an api call
  // so we remember their preference.
  fetch('...');
});

Cookies used

This gem uses a cookie called cookie_eu_consented to track whether a user has accepted the cookie notice and whether it needs to be shown again or not.

Turbolinks 5+

Is supported out of the box, just require it before cookies_eu

//= require turbolinks
//= require cookies_eu

Sample of cookie info (in haml form)

COOKIES

Cookies are small text files which are downloaded to your computer, tablet or mobile phone when you visit a website or application. The website or application may retrieve these cookies from your web browser (eg Internet Explorer, Mozilla Firefox or Google Chrome) each time you visit, so they can recognise you, remember your preferences and provide you with a more secure online experience.

Generally, cookies are very useful and are a common method used by almost every website you visit because they help to make your online experience as smooth as possible. For security reasons, many websites will not function at all without the use of cookies (or other similar technologies, such as "web beacons" or "tags").

Cookies generally do not hold any information to identify an individual person, but are instead used to identify a browser on an individual machine.

If you prefer, you can restrict, block or delete cookies by changing your browser settings but that may mean that the website won't work properly

For more information about cookies and their impact on you and your browsing visit www.aboutcookies.org.

TYPES OF COOKIES

Necessary cookies

These cookies are essential in helping you to make use of the features and services we offer on the #{INSERT SITE HERE} website. Without these cookies, the services you want to use cannot be provided. These cookies do not gather information about you that could be used to identify you, and they do not monitor or remember where you have been on the internet.

Functional cookies

These cookies allow us to provide you with a better online experience when you use our website. They do not gather or store any information which would allow us to identify you personally.

Performance cookies

Performance cookies help us to understand how our customers use our site, so we can keep our products and services relevant, easy to use and up to date. For example, we can see which products and services are most popular, identify when and where errors occur, and test different versions of a page in order to provide an improved online experience.

Sometimes, the services we use to collect this information may be operated by other companies on our behalf. They may use similar technologies to cookies, known as "web beacons" or "tags". These are anonymous and, as they are only used for statistical purposes, they do not contain or collect any information that identifies you.

Targeting cookies

We have relationships with carefully selected and monitored suppliers (third parties) who may also set cookies during your visit. The purpose of these cookies is "behavioural advertising" (also known as "behavioural targeting" or "remarketing"), which is a means of showing you relevant products and services based on what you appear to be interested in. Although these cookies can track your visits around the web they don't know who you are. Without these cookies, online advertisements you encounter will be less relevant to you and your interests.

MANAGING COOKIES

Most internet browsers allow you to erase cookies from your computer hard drive, block all cookies (or just third-party cookies) or warn you before a cookie is stored on your device.

Please note, if you choose to block all cookies, our site will not function as intended and you will not be able to use or access many of the services we provide. If you have blocked all cookies and wish to make full use of the features and services we offer, you will need to enable your cookies. You can do this in your browser (see below).

Rather than blocking all cookies, you can choose to only block third-party cookies which will still allow our website to function as intended.

How to manage cookies on your PC

To enable cookies on our website, follow the steps below.

Google Chrome
  1. Click "Tools" at the top of your browser and select "Settings".
  2. Click "Show advanced settings", scroll down to the section "Privacy" and click "Content Settings."
  3. Select "Allow local data to be set". To only accept first-party cookies, check the box next to "Block all third-party cookies without exception"
Microsoft Internet Explorer 6.0, 7.0, 8.0, 9.0
  1. Click "Tools" at the top of your browser and select "Internet Options", then click the "Privacy" tab.
  2. Check that the level of your privacy is set to Medium or lower, which will allow the use of cookies in your browser.
  3. If set above medium level it will prevent the use of cookies.
Mozilla Firefox
  1. Click "Tools" at the top of your browser and select "Options".
  2. Then select the "Privacy" icon.
  3. Click the "Cookies" and select "Allow pages to create a cookie."
Safari
  1. Click the gear icon at the top of your browser and select "Settings".
  2. Click the "Privacy" tab, then select the option "Disable the use of cookies by third parties and advertising cookies."
  3. Click "Save".

How to manage cookies on your Mac

To enable cookies on our website, follow the steps below.

Microsoft Internet Explorer 5.0 on OSX
  1. Click on "Explorer" at the top of your browser and select "Settings".
  2. Scroll down to the "Cookies" section in the "Received Files".
  3. Select "Do not ask."
Safari on OSX

1 Click "Safari" on the top of your browser and select "Settings". 2 Click the "Privacy" and then "Enable cookies." 3 Select "only the pages you have visited."

Mozilla and Netscape on OSX

1 Click "Mozilla" or "Netscape" at the top of your browser and select "Settings". 2 Scroll down to the "Cookies" under "Privacy & Security". 3 Select "Allow cookies only to the original site."

Opera

1 Click "Menu" on the top of your browser and select "Settings". 2 Then select "Options" tab and the "Advanced". 3 Select "Enable cookies."

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Credits

Maintained and sponsored by Infinum.

cookies_eu's People

Contributors

0xd7ba952ce8a0976e8d9852b7649bf01c30146 avatar alexshapalov avatar anacar avatar badmanski avatar bjosip avatar d4be4st avatar danielmorosan avatar davidhrbac avatar davidwessman avatar esaborit4code avatar frostblooded avatar gabskoro avatar haffla avatar isbatak avatar itayariely avatar jfly avatar karlosmid avatar kirvv avatar modreoci avatar mruokojo avatar niklasgronblom avatar olsigjeci avatar paulmwatson avatar paulslaby avatar scarroll32 avatar tagliala avatar tcgumus avatar tradziej avatar vilola avatar wjdhamilton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cookies_eu's Issues

pleas upgrade the gem

the master code works but the gem is broken because the ok button has not the class js-cookies-eu-ok

Button OK not working

Hello

I am trying to click on the OK button to consent but it's not doing anything (local + production)
I have nothing in my console...

Could you help me with that please?

Thanks a lot

<%= render 'cookies_eu/consent_banner' %> doesn't render any view

I think there is sth wrong with "<%= render 'cookies_eu/consent_banner' %>". I've put it inside my application.html.erb, I can see ' Rendered /Users/damiankulig/.rvm/gems/ruby-2.3.0/gems/cookies_eu-1.6.3/app/views/cookies_eu/_consent_banner.html.erb (1.2ms)' in logs but rendered HTML is empty.
Any advise?

Doesn't Work. Click "OK"... Nothing Happens

Don't really understand how this issue hasn't been fixed. Click "OK"... absolutely nothing happens. YES I am requiring cookies_eu in the application.js... It just isn't doing anything.

No errors in the console. No errors in the logs.

Add Arabic locale

I am not personally fluent in Arabic, but am involved in web development that would utilize Arabic locale text.

Is this gem working on Rails 4.1.5?

Hi I've just installed the gem using bundler and following the steps in the readme and I'm getting some errors couldn't find file 'cookies_eu' in application.js, it seems that the gem did not added the required files to the project. I tried to install the gem using

gem 'cookies_eu',git: 'git://github.com/infinum/cookies_eu.git'

but this did not solved the issue, what am I doing wrong?
any suggestion?
Thx.

Turbolink support is missing

Great gem! :)

However, it doesn't work well with Turbolinks in Rails 4. When you switch to another page, the .click() event handler is lost and not bound again.

The JS code should be rewritten to listen for the "page:load" event as follows:

readyFunc = ->
    $(".cookies-eu-ok").click (e) ->
        e.preventDefault();
        $.cookie('cookie_eu_consented', 'true', {path: '/', expires: 365});
        $('.cookies-eu').remove();

$(document).ready(readyFunc)
$(document).on("page:load", readyFunc)

Webpacker / Rails 6

Hi this gem doesn't work with Rails 6 in the default configuration as the asset pipeline has been replaced with Webpacker (at least for Javascript). Is there any chance you could add a package.json and load to NPM? I can't figure out how else to get it to work with Webpacker!

Support for persisting acknowledgement with a user account?

If someone is logged in when they acknowledge the banner, it would be nice to store that acknowledgement in the database so we don't keep hounding the same person to re-acknowledge the same thing over and over again as they log into different devices.

I understand that this wouldn't make sense to implement in a turnkey way, but it would be nice if this gem provided a hook to run some arbitrary javascript code when someone clicks the "ok" button. Then we could do something like make an API call to record the user's preference in the database and not render the banner if the user is logged in and has already acknowledged the cookie law.

Would you be open to a PR adding a callback to the cookiesEu.init method, or is that out of scope for this package?

Allow this to work with page caching

The banner is shown/hidden while rendering the page in Rails. I think it's preferable as plain javascript solution that would work with page caching or similar activated. Meaning the banner should always be rendered by rails (but set to hidden). Then we check for the cookie via javascript and unhide the banner when necessary.

Overwrite text

Thank you for developing this gem!

How can I overwrite the text to display?

jquery-turbolinks gem does not work with Rails 5+

Looking at issue #4, it appears a decision was made not to support turbolinks because the addition of of the jquery-turbolinks gem allows cookie_eu to work with turbolinks.

However, jquery-turbolinks is now deprecated, in particular it does not work with rails 5+.

I have implemented cookie_eu with rails 5.1.4 and the jquery-turbolinks gem and find that cookie_eu does not function properly. If you go directly to a page that is meant to show the cookie, then clicking on the OK button does hide the cookie warning. However, if you to click to the same page by following a link from another page, although the cookie warning message is displayed, clicking on the OK button does nothing. If I am correct, this will also happen for existing users of cookie_eu who upgrade to rails 5+.

I am hoping this can be fixed as I think this a useful gem, particularly with the imminent need to comply with the GPDR.

generator appended on last line not new line

Hello, just to signal that on lastest Rails 5.2.2, the generator appended both for js and scss on the last line, not a new line. Like so:

@import '@fortawesome/fontawesome-free/css/all.min.css';@import 'cookies_eu';

click on button does nothing

hi,

since recently, the text and button display still well, but clicking on button does nothing
Using js_cookie_rails 2.1.3
Using cookies_eu 1.5.0

thanks

ActionView::Template::Error cookies is nil in _consent_banner under rails 5.0.2

Hi,

I have been using this gem up to rails 3. Recently I started on a rails 5 application and just tried to use the gem. It fails with an exception from the consent banner view as the cookies hash is not present so the code fails trying to index into a nil.

  Rendered vendor/bundle/ruby/2.4.0/gems/cookies_eu-1.6.1/app/views/cookies_eu/_consent_banner.html.erb (3.3ms)
Completed 500 Internal Server Error in 384ms (ActiveRecord: 6.3ms)



ActionView::Template::Error (undefined method `[]' for nil:NilClass):
    1: <% if cookies['cookie_eu_consented'] != 'true' %>
    2:   <div class="cookies-eu js-cookies-eu">
    3:     <span class="cookies-eu-content-holder"><%= t('cookies_eu.cookies_text') %></span>
    4:     <span class="cookies-eu-button-holder">

app/views/layouts/application.html.erb:119:in `_app_views_layouts_application_html_erb___417550730079423151_69817583861080'
  Rendering vendor/bundle/ruby/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout
  Rendering vendor/bundle/ruby/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
  Rendered vendor/bundle/ruby/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (4.8ms)
  Rendering vendor/bundle/ruby/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
  Rendered vendor/bundle/ruby/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.7ms)
  Rendering vendor/bundle/ruby/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
  Rendered vendor/bundle/ruby/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.6ms)
  Rendered vendor/bundle/ruby/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout
(22.5ms)

SCSS file name deprecation warning

The extra .css extension is no longer needed.


DEPRECATION WARNING: Extra .css in SCSS file is unnecessary. Rename .../app/assets/stylesheets/cookies_eu.css.scss to .../app/assets/stylesheets/cookies_eu.scss. [...]

Thanks! :-)

Make the view customizable

It would be great if you could make the view customizable like in the Devise gem, where you can optionally change the HTML code.

Show cookie banner text in French

Hi, many thanks for this gem.

Just a quick question: is there a readme file that explains what configuration should be made to have the text shown in French?

Many thanks.

Rails 6, turbolinks 5 Cannot find module 'cookies_eu'

Gem doesn't work with latest version of RoR

rails g cookies_eu:install

helper doesn't work as well, it expects application.js to be in /app/assets/javascripts/application.js

and generates error

/app/assets/javascripts/application.js does not appear to exist

After that, when loading page, banner can't be dismissed because of

application.js:1 Uncaught Error: Cannot find module 'cookies_eu'
    at webpackMissingModule (application.js:1)
    at Module.<anonymous> (application.js:1)
    at Module../app/javascript/packs/application.js (application.js:41)
    at __webpack_require__ (bootstrap:19)
    at bootstrap:83
    at bootstrap:83

partial naming

what about renaming the cookies_eu/cookies_eu partial to something more clear like cookies_eu/consent_banner or similar?

Errors if a different version of jQuery is already loaded

Some jquery plugins in my pages stopped working after I added cookies_eu. I eventually realized that the first line in cookies_eu.js was loading jquery (v 1.11.2 from its jquery-rails dependency). However I already loaded jquery v 2.0.2 and the plugins don't seem to like it. I tried to moved cookies_eu at the top of application.js to no avail or switching to //= require jquery2. I eventually commented out //= require jquery and everything worked, but this was unsatisfactory.

I had to include directly jquery directly in application.html.erb to be able to do something like

<!--[if (!IE)|(gt IE 8)]><!-->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<!--<![endif]-->

<!--[if lte IE 8]>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<![endif]-->

So another solution was to remove those lines and add //= require jquery2 in your gem and at the top of application.js. That worked too but I'm losing support for IE8, which is required in this project.

Furthermore with both solutions I'll have to fork your gem to be able to deploy it.

If I have to fork it I'll go for the first solution and remove the dependency from jquery-rails. Could you suggest a better solution? Thanks.

not working async script

if is generally advise to load script asynchronously to display the page faster, but it you do, them the gem is not working anymore

Does this disable turbolinks cache?

Looking at the code for init function there is a line:

windowIsTurbolinked && window.Turbolinks.clearCache();

which runs on every page load. Doesn't this just disable the Turbolinks page cache? Shouldn't you do something like the following:

$(document).on("turbolinks:before-cache", function() {
  ... REMOVE PROMPT IF CONSENTED ...
}

instead?

GDPR compliance

This gem is ok with the new law?
The cookies should be disabled for rails if user declines their use.
It would also be a good feature to be able to be more strict, not allowing cookies until the user clicks OK.
I'll see if I can help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.