Cookie Control, now it's the time to make money. I've searched for some free scripts that would allow some sort of configuration. Didn't find any, but it's a big internet.
Maybe the cookieconsent script will be updated to give this option.
I'm using foundation has a base template. I've added a link "Configure" to the cookie consent that will use the foundation reveal "module" ( a popup), a form using the foundation switch module. So it's mix of php and jscritp and cookies
But it all can be done using jscritp, but I don't have the knowledge to do that neither the time.
https://cookieconsent.insites. com/documentation/disabling-cookies/
In the cookie consent script I created another status ( Config) , basically a copy from the "allow" status. More or less you can get the idea, just check where the cc.status.allow is used.
// valid cookie values
cc.status = {
deny: 'deny',
allow: 'allow',
dismiss: 'dismiss',
config: 'config'
};
In the configuration ( window.addEventListener("load", function () { ) ( has to be set to add the new status ( When I say has, please read maybe )
"content": {
"allow": "Allow",
"config": '<i class="ic_settings_white_1x_small"></i>Configure'
},
"revokable": "true",
"type": "opt-in",
Then all is going to be on the
onPopupOpen: function onPopupOpen(status, chosenBefore, options, utils) {
onStatusChange: function onStatusChange(status, chosenBefore) {
The only reason I don't paste here the complete code, it's because I know that makes the job for me, but it's a quick bandage, and it's using foundation base modules, and it's cookies strategies to configure cookies ( a paradox )
To be a general scritp , a lot of JavaScript knowledge is required.
But what was the more complicated part for me, was this.
The rest is a form, with input checkboxes, etc... With PHP i'm checking the cookie config , and allowing or not analytics etc....
Again, this is not a copy paste, but a general idea.
"use strict";
function delete_cookie(name, domain) {
document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Domain=' + domain;
}
window.addEventListener("load", function () {
var host = window.location.hostname;
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#000"
},
"button": {
"background": "#f1d600"
}
},
"layout": "basic",
"theme": "edgeless",
"content": {
"message": "bla bla bla:",
"dismiss": "ok",
"allow": "Aloow Cookies",
"link": "Privacy Link",
"href": "thelinink . com ",
"config": '<i class="ic_settings_white_1x_small"></i>Configure'
},
"revokable": "true",
"type": "opt-in",
onPopupOpen: function onPopupOpen(status, chosenBefore, options, utils) {
var type = this.options.type;
var hasConsented = this.hasConsented(); // allow, dismiss, deny, config
var didConsent = hasConsented;
var cfgCookiesAnalytics = '';
var cfgCookiesExternal = '';
// to check if analytics is GDPR compliant
var isAnalyticsChecked = document.getElementById('c-analytics');
var isExternalChecked = document.getElementById('c-external');
function updateState(input) { //This is update the input buttons state
var inputName = input.name == 'secondaryC-switch' ? 'secondaryC-switch' : 'secondaryC-switch-external';
if (inputName == 'secondaryC-switch' && input.checked) {
cfgCookiesAnalytics = 'active';
} else if (inputName == 'secondaryC-switch' && !input.checked) {
cfgCookiesAnalytics = 'inactive';
isExternalChecked.checked = false;
cfgCookiesExternal = 'inactive';
}
if (inputName == 'secondaryC-switch-external' && input.checked) {
cfgCookiesExternal = 'active';
isAnalyticsChecked.checked = true;
cfgCookiesAnalytics = 'active';
} else if (inputName == 'secondaryC-switch-external' && !input.checked) {
cfgCookiesExternal = 'inactive';
}
return false;
}
var cookieForm = document.getElementById("ccForm");
// listen to input events
cookieForm.addEventListener("click", checkInputState, false); // It's going to listen to the INPUT buttons
function checkInputState(e) {
if (e.target.nodeName == "INPUT") {
var listen = updateState(e.target);
}
e.stopPropagation();
}
// console.log('ce: ' + cfgCookiesExternal + ' - ca ' + cfgCookiesAnalytics);
var saveConfig = document.querySelector('[aria-label="config cookie"]');
// define cookie
var cname = this.options.cookie.name;
var expiryDays = this.options.cookie.expiryDays;
var path = this.options.cookie.path;
var domain = this.options.cookie.domain;
var allDomains = '.' + document.location.hostname;
if (saveConfig.addEventListener) {
saveConfig.addEventListener("click", function (checkInputState) { // On save will get the Input Buttons State
//event.preventDefault();
if (cfgCookiesAnalytics == 'active' && cfgCookiesExternal == 'active') {
didConsent = 'config';
var set = cookieconsent.utils.setCookie(cname, 'allow', expiryDays, domain, path);
setTimeout(function () {window.location.reload(true);}, 100);
} else {
didConsent = 'config'; // flag some user interaction
delete_cookie('_ga', allDomains);
delete_cookie('_gid', allDomains);
var set = cookieconsent.utils.setCookie(cname, didConsent, expiryDays, domain, path);
setTimeout(function () { window.location.reload(true);}, 100);
}
var getCookieName = '';
if (cfgCookiesAnalytics == 'active') { // Analytics is good to go
var set = cookieconsent.utils.setCookie('cc_analytics', 'allow', expiryDays, allDomains, path);
} else {
getCookieName = cookieconsent.utils.getCookie('cc_analytics');
if (getCookieName) {
delete_cookie('cc_analytics', allDomains);
}
}
if (cfgCookiesExternal == 'active') {
// review this bit, if it's active, analytics cookie is also active
var set = cookieconsent.utils.setCookie('cc_allowSocial', 'allow', expiryDays, allDomains, path);
} else {
getCookieName = cookieconsent.utils.getCookie('cc_allowSocial');
if (getCookieName) {
delete_cookie('cc_allowSocial', allDomains);
}
}
}, false);
}
},
onInitialise: function onInitialise(status, chosenBefore) {
var type = this.options.type;
var hasConsented = this.hasConsented();
var hasAnswered = this.hasAnswered();
//console.log( 'onInitialise' + hasConsented + hasAnswered + type);
if (type == 'opt-in' && hasConsented == true) {
// enable cookies
}
if (type == 'opt-out' && !hasConsented) {
// disable cookies
}
},
onStatusChange: function onStatusChange(status, chosenBefore) { // The user revoke his choice
var type = this.options.type;
var hasConsented = this.hasConsented();
var hasAnswered = this.hasAnswered();
if (this.hasAnswered() && this.hasConsented()) {
setTimeout(function(){ window.location.reload(true) }, 100);
// Put Your Google Analytics Tracking Code here ( Not using this, but this is the way to go )
}
if (!hasConsented || !hasAnswered) {
setTimeout(function(){ window.location.reload(true) }, 100);
// Put Your Google Analytics Tracking Code here
}
},
onRevokeChoice: function onRevokeChoice() {
var type = this.options.type;
var hasConsented = this.hasConsented();
if (type == 'opt-in' && hasConsented) {
// enable cookies
}
if (type == 'opt-out' && !hasConsented) {
// disable cookies
}
}
});
});