Top

The Blog


  1. 5
    Mar
    2010

    Disabling Google Analytics for front-end Administrators in Joomla

    A good question, raised by Jack Bremer, prompted the writing of this brief post in case it’s of use to somebody else at some point (including myself). The GA plugin in WordPress has this option, which is great for larger sites with loads of front-end admins all working on the site – you don’t want to be diluting your Analytics with all that noise.

    So, how can the same be acheived in Joomla? Well, quite easily actually. Read on to find out how…

    Google Analytics

    Modify the Template

    For this to work we will need to make a simple logic change in the site’s template index.php file, which you can find in template/your_template directory of your site. First we’ll need to get the $user variable loaded into the template, so, near the top, add the following line of PHP:

    $user =& JFactory::getUser();
    

    This will load an array of variables into $user that we can use to determine who’s currently logged-on to the front-end of your website. The particular value we’re looking for is the User ID, contained in $user->gid (the current user’s Group ID) – this value is zero (false) if a guest is browsing the site, but will be a specific figure depending on which group they are assigned to when logged-on.

    Add the logic code

    Next step is to locate your GA tracking code, which should be right at the bottom of your index.php file, just before the tag. We need to wrap this in some PHP test code to selectively load the tracking script based on the outcome of our condition, so first locate your tracking code which will look like this:

    
    
    

    Then add the PHP test to selectively load the scripts, which looks like this:

    <?php if (!$user->gid == 25) : ?>
    
    
    
    
    <?php endif; ?>
    

    This example above will disable the GA tracking code only for Super Administrators logged-on to the front end. You can add your own test conditions depending on your requirements, by using the list below as a reference for the group to test:

    • 18 – Registered
    • 19 – Author
    • 20 – Editor
    • 21 – Publisher
    • 23 – Manager
    • 24 – Administrator
    • 25 – Super Administrator

    Disable tracking for anyone who isn’t a guest user (not logged-on):

    if (!$user) :
    

    Disable tracking for all back-end users:

    if (!$user == 23 || !$user == 24 || !$user == 25) :
    

    Disable tracking for all registered users:

    if (!$user == 18) :
    

    I’m sure you get the gist!

    Got a better idea or know of a plugin that can do this for you? Please share it in the comments, we’d love to hear your ideas!


  2. 2
    Comments

    Something to say? Leave a reply!

    1. Comment by Dan Luton — March 5, 2010 @ 3:43 pm [Link]

      For those looking for a solution without changing the template:

      http://extensions.joomla.org/extensions/site-management/site-analytics/3356

      It won’t be as lightweight as the above solution, but an alternative nontheless (via @JacquesRentzke).

    2. Pingback by Disabling Google Analytics for front-end Administrators in Joomla … | SFWEBDESIGN.com — March 6, 2010 @ 4:22 am [Link]

      [...] See more here:  Disabling Google Analytics for front-end Administrators in Joomla … [...]

    [TrackBack URL]

    Leave a comment