Я тестирую сценарий cookieconsent на моем веб-сайте с опцией "opt-in" (файлы cookie не загружаются по умолчанию).
Включение и отключение работает, но когда я хочу отозвать (маленькая кнопка внизу слева), ничего не происходит.Это мои функции для включения / выключения файлов cookie:
function enableCookies() {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-17530048-4');
}
function disableCookies() {
window['ga-disable-UA-17530048-4'] = true;
}
при «включении» я просто активирую скрипт Google Analytics и при «отключении» я использую функцию «ga-disable», но она не работает.
Это весь сценарий:
function enableCookies() {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-17530048-4');
}
function disableCookies() {
window['ga-disable-UA-17530048-4'] = true;
}
window.addEventListener("load", function(){
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#222",
"text": "#fff"
},
"button": {
"background": "#ccc",
"text": "#222"
},
},
"type": "opt-in",
"revokable": "false",
"animateRevokable": "false",
"content": {
"message": "Message",
"deny": 'No - Cookies are bad',
"allow": "YES - I love cookies",
"link": "More info",
"href": "https://www.google.de"
},
onInitialise: function (status) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
enableCookies()
}
if (type == 'opt-out' && !didConsent) {
disableCookies()
}
},
onStatusChange: function(status, chosenBefore) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
enableCookies()
}
if (type == 'opt-out' && !didConsent) {
disableCookies()
}
},
onRevokeChoice: function() {
var type = this.options.type;
if (type == 'opt-in') {
disableCookies()
}
if (type == 'opt-out') {
enableCookies()
}
},
})
});