在同意之前设置 Cookie

Sar*_*G.P 5 javascript wordpress cookieyes

我试图将 cookieyes GDPR 解决方案集成到 WP 网站。以下是网站中添加的 GTM 和 cookieeyes 的代码。但饼干

(_ga、_gid 和 gat_gtag_UA_xxxxxxxxxxxx_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>
Run Code Online (Sandbox Code Playgroud)

小智 3

要使用 CookieYes 阻止 GTM cookie,您需要做的是将数据属性“data-cookieyes”添加到 GTM 脚本标记中。将属性的值设置为相应的 ('cookieyes-{category-name}') 类别。

例如,由于 GTM 脚本属于“Analytics”类别,因此该值将为“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>
Run Code Online (Sandbox Code Playgroud)

这已在此处详细解释,如何使用 Cookie 实现事先同意