您好研究员,
我正在研究一个可以控制GA是否可以跟踪用户的解决方案。我正在使用Insites和Google Dev文档的Cookie同意。来自Insites的代码非常容易理解,但我使它变得更加容易:
onInitialise: function (status) {
var gaID = 'UA-125314688-1';
var type = this.options.type;
var didConsent = this.hasConsented();
console.log("Dal souhlas?");
console.log(didConsent);
if(didConsent){
window['ga-disable-UA-XXXXX-1'] = false;
}else{
window['ga-disable-UA-XXXX-1'] = true;
}
},
onStatusChange: function(status, chosenBefore) {
var type = this.options.type;
var didConsent = this.hasConsented();
if(didConsent){
window['ga-disable-UA-XXXXXX-1'] = false;
}else{
window['ga-disable-UA-XXXXXX-1'] = true;
}
},
onRevokeChoice: function() {
var type = this.options.type;
if (type == 'opt-in') {
// disable cookies
console.log("OPT-in");
}
if (type == 'opt-out') {
// enable cookies
console.log("OPT-out");
}
},
让我们看一下这段代码:
onStatusChange:函数(状态,selectedBefore){
var type = this.options.type;
var didConsent = this.hasConsented();
if(didConsent){
window['ga-disable-UA-XXXXXX-1'] = false;
}else{
window['ga-disable-UA-XXXXXX-1'] = true;
}
},
如果didConsent变量返回true,则表示用户已授予我使用Cookie的权限,因此我正在使用window ['ga-disable-UA-XXXXXX-1'] = false; ->此处描述:https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out
不幸的是,出于某些令人讨厌的原因,当didConsent返回false时,Google Analytics(分析)仍会跟踪我网站上的所有放屁行为,因此将Disable(禁用)设置为true。
所以我实际上有两个简单的问题: