How to disable tracking of administrator and registered users of wordpress by google analytics

Google  analytics is a power tool for tracking your webpages. It provide seamless integration with static as well as dynamic pages. WordPress generates pages dynamically using php. Integration of Google Analytics with wordpress is quick and easy. Moreover a number of plugins are available to meet this needs for inexperienced users.



Other people just put the code in header.php or footer.php file instead of using plugins. This is a good practice to use the least of plugins on your blog, since you do not always know what else code they run in the background. Now this code tends to track all visitors and even you, that is the administrator. You do not want to see your own visits in your analytics report. So, to disable your own and your blog registered users tracking by google put this code just above the tag in your header.php file. This will not display analytics code for logged in users and hence they will not be tracked.

//Your header.php file

<?php if ( is_user_logged_in() ) {
echo ''; 
} else {
echo '<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'Your analytics ID']);       //put your id here like UA-1192xxxx-x
_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>';
}; ?>

</head>

Tags: , , , , , , , , , , ,

1 Response to "How to disable tracking of administrator and registered users of wordpress by google analytics"

Leave a Comment