对于Grosse European Komission的无意义cookie法,我已经建立了这个小脚本来选择退出GA跟踪代码。结果是一个弹出窗口在会话中询问OK和CANCEL GA。你觉得怎么样?
(function() {
var message = "GOOGLE ANALYTICS COOKIE\nCookie or not cookie, that is the question\n\nI opt for Google Analytics pageview anonymous tracking.\n\nJe consens au suivi d'audience anonyme Google Analytics.";
if (!sessionStorage['key_name']) {
if (confirm(message) == true) {
sessionStorage.setItem('key_name', 'gaOK');
}
else {
sessionStorage.setItem('key_name', 'gaOut');
}
}
if (sessionStorage['key_name'] == 'gaOK') {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-N', 'auto');
ga('send', 'pageview');
}
})();