How to disable Google Analytics tracking for logged in users

disable Google analytics tracking for logged in usersGoogle Analytics is an effective data analysis tool which gives precise traffic statistics on your website. It is a must to use tool for every website and you know what setting up analytics on a website is very simple. We have discussed a lot about Google Analytics, we have covered about setting up Analytics on Blogger and just a day back we also covered about installing Google Analytics on wordpress, hope you have started to track your visitor’s details. The problem with the tracking code is that it tracks everything, so do not conclude your site’s traffic before you exclude yourself from analytics reports. Here we will show you how to disable Google Analytics tracking for logged in users.

As a blogger most of the time you will be doing some process at your site’s back-end like posting content, editing comments, tweaking settings, testing etc. Google Analytics includes all your own tasks in its traffic report. Also as a designer and developer you will be having the copy of your live wordpress site in local machine for further designing and development. If that cloned site has tracking code installed then analytics even starts counting every single hit from your local computer. Tracking your own stats and especially if you running a multi author blog then tracking their activities will be very critical. So to acquire exact real traffic stats of your blog it is necessary to exclude logged in users that is excluding your own traffic from Google Analytics reports.

Disable analytics on localhost

How to disable Google Analytics for logged in users

In order to exclude internal traffic from analytics report you can use the data filter tool in which you can filter traffic using users IP address, but this will be useful only if your broadband has a static IP address. Similarly there are several other filters which can help you to modify and limit the traffic data of your website. Login to your Google Analytics account, go to admin menu at the top and beneath all website data you will see filters. You can create and apply as many filters for your domain for example you can filter out specific geographical locations, specific devices etc.

Code to exclude tracking for logged in users

In this tutorial we have mentioned you to add the Google Analytics JS code just above the </head> tag that is by going to dashboard >> appearance >> editor, header.php. Now just above the code paste this line <?php if ( !is_user_logged_in()) { ?> and just below the tracking code add this line <?php } ?>. So your Google Analytics JavaScript code should technically lie in between those two lines like this.

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

Your Google Analytics tracking code

<?php } ?>

<?php if ( !is_user_logged_in()) { ?>
<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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-9797987987', 'auto');
  ga('send', 'pageview');
</script>
<?php } ?>

Once the file is saved it excludes all logged in users from the analytics report. If you wish to just exclude a particular user then you have to use if($user_id) { .

blocking google analytics for logged in users wordpress

Or if you are using Google Analytics for wordpress plugin then there is an option called logged in users, just check that. It allows you to easily remove logged in users from your reports.

Hope this helped you to disable Google analytics for logged in users. If you have any other question please comment below.