How do disable Google Analytics JS code in wordpress when the admin is logged in

    <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>

Google analytics provided me this script to put up on my website to track the visitors of my website, but i have observed that my own visits are also counted into the analysis. How do I disable this script if the admin is logged in to the wordpress account as the current user?

Related posts

Leave a Reply

2 comments

  1. This is one of the alternatives I can think of. Using this code the GA code won’t execute for any Author, Contributor nor Admin, but In case your site allows Subscribers to log in you will track em.

    <?php if ( !current_user_can('edit_posts') ) { ?>
    GA code
    <?php } ?>