最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to disable google tag manager and google analytics - Stack Overflow

programmeradmin2浏览0评论

Hi I used following code for disable google analytics and google tag manager but its not worked.

<script>
var gaoop_property    = 'UA-xxxxxxxx-x';
var gaoop_disable_str = 'ga-disable-' + gaoop_property;
function gtmOptOut() {
    document.cookie = gaoop_disable_str + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';       
    window[gaoop_disable_str] = true;        
    window.location.reload();
}
</script>

Does anyone know how I can fix this? Thank you.

Hi I used following code for disable google analytics and google tag manager but its not worked.

<script>
var gaoop_property    = 'UA-xxxxxxxx-x';
var gaoop_disable_str = 'ga-disable-' + gaoop_property;
function gtmOptOut() {
    document.cookie = gaoop_disable_str + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';       
    window[gaoop_disable_str] = true;        
    window.location.reload();
}
</script>

Does anyone know how I can fix this? Thank you.

Share Improve this question edited May 23, 2018 at 12:38 Rushil K. Pachchigar asked May 22, 2018 at 9:41 Rushil K. PachchigarRushil K. Pachchigar 1,3212 gold badges22 silver badges40 bronze badges 2
  • 1 Where did you get this code from? It would be useful to look at the originating documentation – vinoaj Commented May 22, 2018 at 10:08
  • I got that code from this link blog.marketing-factory.de/datenschutz/google-analytics-opt-out – Rushil K. Pachchigar Commented May 22, 2018 at 10:11
Add a ment  | 

1 Answer 1

Reset to default 11
<script>
   var gaoop_property = 'UA-XXXXXXXX-X';
   var gaoop_disable_str = 'ga-disable-' + gaoop_property;
   console.log(gaoop_disable_str + '=true');
   if (document.cookie.indexOf(gaoop_disable_str + '=true') > -1) {
       window[gaoop_disable_str] = true;
   }

   function gtmOptOut() {
       delete_cookie("_ga");
       delete_cookie("_gat_gtag_UA_43169816_3");
       delete_cookie("_gid");
       document.cookie = gaoop_disable_str + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
       window[gaoop_disable_str] = true;
       window.location.reload();
   }

   function delete_cookie(name) {
       var expires = new Date(0).toUTCString();
       var domain = location.hostname.replace(/^www\./i, "");
       document.cookie = name + "=; expires=" + expires + "; path=/; domain=." + domain;
   }
</script>

Add this script and Add Below Condition in the Header

<?php if(empty($_COOKIE['ga-disable-UA-43169816-3'])){ ?>
//google analytics script
<?php } ?>
发布评论

评论列表(0)

  1. 暂无评论