当管理员登录时,如何在wordpress中禁用Google Analytics JS代码 var _gaq=_gaq | |[]; _gaq.push([''设置帐户','UA-123456789-1']); _gaq.push([''u trackPageview']); (功能(){ var ga=document.createElement('script');ga.type='text/javascript';ga.async=true; ga.src=('https:'==document.location.protocol?'https://ssl' : 'http://www“)+”.google analytics.com/ga.js'; var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s); })();

当管理员登录时,如何在wordpress中禁用Google Analytics JS代码 var _gaq=_gaq | |[]; _gaq.push([''设置帐户','UA-123456789-1']); _gaq.push([''u trackPageview']); (功能(){ var ga=document.createElement('script');ga.type='text/javascript';ga.async=true; ga.src=('https:'==document.location.protocol?'https://ssl' : 'http://www“)+”.google analytics.com/ga.js'; var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s); })();,wordpress,google-analytics,Wordpress,Google Analytics,Google analytics为我提供了这个脚本,用于在我的网站上跟踪我网站的访问者,但我观察到,我自己的访问量也被计入分析中。如果管理员以当前用户身份登录wordpress帐户,如何禁用此脚本 如果有用户登录 <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-123456789-1']); _gaq.push(['_trackPagevie

Google analytics为我提供了这个脚本,用于在我的网站上跟踪我网站的访问者,但我观察到,我自己的访问量也被计入分析中。如果管理员以当前用户身份登录wordpress帐户,如何禁用此脚本

如果有用户登录

    <script type="text/javascript">
   var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-123456789-1']);
  _gaq.push(['_trackPageview']);
 (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 })();
</script>

遗传密码


要选择特定的用户,您需要使用
if($user_id){

这是我可以想到的备选方案之一。使用此代码,GA代码不会对任何作者、贡献者或管理员执行,但如果您的站点允许订阅者登录,您将跟踪他们

 <?php if ( !is_user_logged_in()) { ?>

<script type="text/javascript">

GA code    

</script>

  <?php } ?>

遗传密码
<?php if ( !current_user_can('edit_posts') ) { ?>
GA code
<?php } ?>