我试图实现GoogleAnalytics选择退出的可能性,因为德国的数据保护法强迫我这样做。
我使用以下代码:
<script type="text/javascript">
var gaProperty = 'UA-XXXXXXXXX-X';
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
}
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC;
path=/';
window[disableStr] = true;
}
</script>如果我查看控制台,就会得到以下错误:
未登录的SyntaxError:无效的或意外的令牌
错误在这一行。
function gaOptout() {标记是{
我试过几次了,有时是这个支架,有时是另一个{。
怎么啦?有什么想法吗?我搜索了半天,从网络上尝试了这么多的解决方案。但什么都没用..。
如果这很重要,我用硬编码的Global标记(gtag)实现google分析
谢谢你帮忙!
发布于 2018-02-15 22:29:05
后面的“输入”是解决方案。
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC;它应该是
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC;path=/';谢谢你的快速帮助!
https://stackoverflow.com/questions/48816299
复制相似问题