Easily add a Cookie consent banner, upon the user’s first visit to the site, to alert the users about the cookies and get consent for setting them.
Add this line to your application's Gemfile:
gem 'cookiesalert'
And then execute:
$ bundle
Add in "application.js":
//= require cookiesalert/cookie
//= require cookiesalert/cookies_alert
Run Javascript check when load/ready:
$( document ).ready(function() {
cookies.check();
});
Javascript optional parameters to select "#text_div" and add listener in "#button_confirm" to accept cookies:
cookies.check({
div : '#cookies',
btn : '#cookies .accept',
denyBtn: "#cookies .deny",
expires : 7 //Days
});
Add optional styles in "application.css":
*= require cookiesalert/cookies_alert
Import optional view layout:
<%= render "cookies/alert", advice: "Cookies Text", policy_cookies: "Link Advice", button: "Button", gtm_code: "GTM-XXXX" %>
Render optional parameters:
<%= render "cookies/alert", advice: "Cookies Text", policy_cookies: link_to('Link Advice', root_path, target: '_blank'), button: image_tag('cross_cookies.svg'), gtm_code: "GTM-XXXX" %>
ESLint file config ".eslintrc.js":
module.exports = {
"env": {
"browser": true,
"commonjs": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-undef" : 0
}
};
Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
cookiesalert
is Copyright © 2018 CodiTramuntana SL. It is free software, and may be redistributed under the terms specified in the LICENSE file.
Maintained by CodiTramuntana.
The names and logos for CodiTramuntana are trademarks of CodiTramuntana SL.
We love open source software!