Posted on March 5, 2010 4 comments
Learn how to setup a live development environment using CodeKit & LESS.
Discover how to add a Media Queries toggle button to your site using jQuery.
Having Magento problems? This solution may help get you up and running again!
Learn how to make Polaroid-style images complete with 3D shadows using only CSS.
Discover how to make your own 3D box using gradients and shadows with the power of CSS.
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…
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.
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:
<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 type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-12345678"); pageTracker._trackPageview(); } catch(err) {}</script>
Then add the PHP test to selectively load the scripts, which looks like this:
<?php if (!$user->gid == 25) : ?> <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("UA-12345678"); pageTracker._trackPageview(); } catch(err) {}</script> <?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:
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!
Previous: Advanced WordPress sub-navigation using wp_list_pages
Next up: Advanced Techniques: The Joomla Parent Menu ItemID
Dan Luton - March 5, 2010 at 3:43 pm
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).
Disabling Google Analytics for front-end Administrators in Joomla … | SFWEBDESIGN.com - March 6, 2010 at 4:22 am
[…] See more here: Disabling Google Analytics for front-end Administrators in Joomla … […]
real estate Canandaigua Lake - February 10, 2011 at 10:30 pm
I passed this along to one of our programmer to a membership site and this has greatly improved the stats we are able to get with google analytics. Thanks for the post
auto news - May 29, 2012 at 7:54 am
Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a bit, but instead of that, this is wonderful blog. A great read. I’ll certainly be back.