WordPress.org

Ready to get started?Download WordPress

Forums

Google analytics logged in users ignore :) (1 post)

  1. opo
    Member
    Posted 5 years ago #

    This a little trick I discovered just a few minutes ago. I have been using WP.com stats plugin in my site for a while but suddenly the plug stopped working.

    So I installed GA in my site to keep track of it as I cannot relly on WP stats system as it failed updating. So I wanted to ommit logged in users from appearing in the GA stats and I think I found the way to do so, by using the same function/tag the comments template usera to differenciate from loggedin users of regular visitors:

    <?php if ( $user_ID ) : ?>
    <!-- you are logged in -->
    	<?php else : ?>
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("<blockquote>YOUR-GA-ACCOUNT-CODE-HERE</blockquote>");
    pageTracker._trackPageview();
    } catch(err) {}</script>
    <?php endif; ?>

    I'm just gessing it works just fine, does anyone knows if this is true?
    does the GS stats depend on the script load?

    My tests indicate that the script absolutely does not load when a logged in user views a page in the site, on the other hand the GA script DOES load for regular users.

    Check it out! :D

    Note: as always, this code must be put before the 'head' section ends.

Topic Closed

This topic has been closed to new replies.

About this Topic