javascript - 在同意之前设置 Cookie

标签 javascript wordpress cookieyes

我试图将 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/

相关文章:

php - 将使用支票付款方式制作的订单状态更改为 "processing"状态

css - 页面顶部的空白区域(有时)

php - 如何在 WordPress 中所有其他脚本之前的 <head> 标记开头添加脚本

javascript - 使用 head.js 以正确的顺序正确加载脚本和依赖项?

javascript - jQuery Ajax - 仍在重新加载页面 - Laravel 分页

javascript - 执行 'post' 时,表中的 Selectmenu 正在发送所有选项而不是选定的选项

javascript - JS 在类中隐藏损坏的图像

wordpress - 如果在服务器上关闭魔术引号,wordpress 会做什么?