Wordpress dFactory Cookie通知插件

时间:2017-12-08 21:58:04

标签: javascript php wordpress cookies plugins

关于GDPR,在德国DSGVO,我想使用dFactory的插件Cookie通知我的Wordpress网站。如果您拒绝使用Cookie,则可能无法再存储非功能性Cookie(例如Google Analytics)。

Documentation of Cookie Notice by dFactory

你们有没有人告诉我要写哪些代码?不幸的是,我在互联网上找不到任何指示。也许有人已经实现了类似的东西。

提前谢谢。

3 个答案:

答案 0 :(得分:2)

我尝试了多件事后找到了解决方案。我只需将谷歌分析的javascript代码放在php async条件之间,如下所示:

if

答案 1 :(得分:1)

还有另一种方法使用插件Code Snippets

只需创建一个新代码段并使用Wordpress wp_head操作挂钩调用一个函数,如果接受了Cookie,将执行Google Analytic代码。

示例:

function do_google_analytics() {

  if ( function_exists('cn_cookies_accepted') && cn_cookies_accepted() )
  {      
    ?>
        <!-- Global site tag (gtag.js) - Google Analytics -->
        <script async src="https://www.googletagmanager.com/gtag/js?id=UA-999"></script>
        <script>
          window.dataLayer = window.dataLayer || [];
          function gtag(){dataLayer.push(arguments);}
          gtag('js', new Date());

          gtag('config', 'UA-999');
        </script>
    <?php      
  }      
}

add_action('wp_head', 'do_google_analytics');

答案 2 :(得分:1)

以上答案对我不起作用,这个答案对我有用。

我将其放置在“ Cookie Notice”插件的“脚本阻止”编辑框中(请确保将UA-xxxxxxx替换为您自己的Google Analytics(分析)帐户中的ID)

<script>
 (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-xxxxxx', 'auto');
ga('set', 'forceSSL', true);
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>