joomla-templatemgr

Using Google Analytics with Joomla!

Google Analytics is an indispensable tool for webmasters.  Joomla! is a very popular content management system.  It makes perfect sense for Joomla! to have a method of integrating the Google Analytics reporting tool into its framework.  Using Joomla!’s template system, administrators can insert the necessary script for the Analytics system to track visitors to each page contained on the site.

Here’s how it works.  To use Google Analytics, you have to set up an account through Google.  You can access Analytics by going to http://www.google.com/analytics.  After setting up an account, you are given a block of JavaScript code that you’re supposed to include on each page of your website – at least those for which you want to track traffic.

Once you’ve obtained the Analytics script from Google, you need to paste it into your current Joomla! setup.  To do so, access your currently active Joomla! template by going to Extensions->Template Manager. 

From the Template Manager page, click on the name of the currently active template.  The currently active template is marked by a star icon in the Default field. 

Next, click on the Edit HTML icon.  Doing so will take you to a screen that will allow you to edit your template’s index.php file.  Each time someone visits a Joomla!-based website, the page request is directed through the index.php file for the active template, so that’s the file you need to edit.

Once you’ve pulled up the index.php file for your Joomla! site’s active template, you need to paste the Analytics script in a place where it won’t interrupt other parts of the code.  I typically place mine just before the closing body tag, as shown below.  Many webmasters prefer to put the code in the header section of their template’s index.php file.  As long as you place the code where it doesn’t interfere with other sections of the page, you’ll be fine.

One important thing to note with regard to Joomla! templates is that more than one template file can be used on a website at a time.  For instance, you may have assigned an alternate theme to articles pages in a particular category of your Joomla! site.  For this reason, it’s a good habit to go ahead and put the Google Analytics script in the index.php file for each of the templates you have installed, even if you don’t currently have pages assigned to use any template other than the default.  If you later install another Joomla! template, you should go ahead and put the Analytics script in that one as well.  If you don’t have the script in each of your template files, your Analytics stats won’t account for visitors who might come to one of the pages on your site on which the tracking code does not exist.

Leave a Reply

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