Categories
WordPress

Don’t track internal visits to a WordPress site

Here’s a quick way to reduce the number of internal site visits showing up in Google Analytics from logged in internal users.

This code was for a WooThemes based site using the woo_head hook. It won’t be available in other themes.
[php]<?php
add_action(‘woo_top’, ‘my_analytics’, 5);
function my_analytics() {

//Don’t track admins (editors, or publishers…)
if( current_user_can(‘edit_posts’)) {
echo "\n<!– Internal User. Not counted –>\n";
return;
}

echo <<<EOD
(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-YOUR-TRACKING-ID-HERE’, ‘example.com’);
ga(‘send’, ‘pageview’);

EOD;
}[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *