Don’t Track Analytics for Admin

By mike on October 10, 2011 in Snippet
w0
k 0

I often run into situations where I am editing a site, or checking my pages, but do not want to count the time i spend on my own site to count towards my Analytics Tracking. To fix this, I only display my analytics code when the user is not logged in, or is logged in as someone other than the administrator.

<?php   
global $user_ID;   
if( $user_ID ){    
 if( !current_user_can('level_10') ){
  //logged in as someone other than admin
  //place analytics
 }
} else {
 //not logged in
 //place analytics
}
?>

This code checks for a user ID, if it cant find one it displays the tracking code. If there is an ID, then the user is logged in. If the user level is at 10, then it is an administrator and should not show the code. We use the exclamation point (the NOT logical operator) to verify that the user is NOT an admin. As a general rule of thumb, you should not have more than one administrator account on a site.

0 Comments

Leave a reply

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>