我试图将 cookieyes GDPR 解决方案集成到 WP 网站。以下是网站中添加的 GTM 和 coookieyes 的代码。但是 cookies
( _ga , _gid and gat_gtag_UA_xxxxxxxxxxx_1)
即使没有点击接受按钮也会设置。
<?php wp_head(); ?>
</head>
<!-- Start cookieyes banner -->
<script id="cookieyes" type="text/javascript" src="https://app.cookieyes.com/client_data/714e8fa9e198d23xxxxxxxxxx.js"></script>
<!-- End cookieyes banner -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxxx-1" ></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-xxxxxxxxx-1');
</script>
最佳答案
要使用 CookieYes 阻止 GTM cookie,您需要做的是将数据属性“data-cookieyes”添加到 GTM 脚本标签。 将属性的值设置为相应的 ( 'cookieyes-{category-name}' ) 类别。
例如,由于 GTM 脚本属于“分析”类别,因此该值将为“cookieyes-analytics”。 在这种情况下,要在事先同意的情况下阻止代码,请将 GTM 脚本标记更改为:
<script async data-cookieyes="cookieyes-analytics" src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxxx-1" ></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-xxxxxxxxx-1');
</script>
这已在此处详细解释,How to Implement Prior Consent Using CookieYes .
关于javascript - 在同意之前设置 Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58077299/