Google Analytics is the web's most favorite tracking application used by millions. They are also rolling out real-time analytics. But if you're the admin of a site and you're testing several features of a site, you probably won't want to a track your visits. Here's how you can do that in Wordpress.
Google Analytics' tracking code is inserted inside the <head> tag. So, you can restrict this insertion using the following codes in your theme's header.php file:
var _gaq = _gaq || ;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script'); s.parentNode.insertBefore(ga, s);
<?php endif; ?>
This is pretty simple: it checks whether the logged in user is admin. If not, it inserts the tracking codes. You can find more about Roles and Permissions in Wordpress
Do change UA-XXXXXX-X
with correct values.
Labels: Tips, Wordpress