Don’t Display Your Google Analytics Code While Logged In

I sometimes find myself developing or adding new features on live sites and these sites nearly always have some tracking software installed such as Google Analytics or Clicky etc. When you develop websites, you find yourself refreshing web pages constantly to see your new changes and this is seen by tracking software and not good as it skews the stats.

A simple way to hide these page views is to use use the is_user_logged_in() function in WordPress. This hides the tracking code to people who are logged in and you won’t see an extra 100 page views, simple. 🙂

<?php if(!is_user_logged_in()): ?>
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write("%3Cscript src='" + "' type='text/javascript'");
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-0000000-0");
<?php endif; ?>

Leave a Reply