Without any shadow of doubt, one of the very first things you should have in place if you are serious about your website - is Google Analytics. Not only if you want to monitor your traffic, Google Analytics has information which is so rich, you'd be really missing out if you did not avail yourself of all the tools there are available for monitoring the traffic coming to your website.
The easy way: Using a Google Analytics Plugin
To make your life easier, rather than messing about with the index.php file, you can choose the easy way out of doing this via a Joomla extension. It is recommended that you choose a plugin rather than a module, which would allow the generation of the code to be done automatically without you having to worry about publishing the module to each page.
The following is a list of Google Analytics extensions for Joomla which are available on the Joomla Extensions Directory, including one by CollectiveRay.com
The manual way: How do I do it?
Basically what we need to do is edit the template (because this is what outputs the content of the pages) in such a way that each page includes the Google Analytics tracking code.
One of the important things to consider is that the way you do it is really and truly dependent on the Joomla template you are using. There is no one universal, identical way to do this across any template. Having said that, it's not impossibly difficult to do it, you just need to get a few pointers. The thing is, that since all templates are different in the way that they are built, you'll need to tweak the procedure according to the template you are using.
So what does Google say about implementing Google Analytics. The instructions are very simple:
"This is your tracking code. Copy and paste it into the code of every page you want to track."
Well that seems simple enough. Google does not specify whether this code should go in the <head>, the <body> or wherever. It simply does not make any difference. The most important part is that it is present in every page. Great, that should make things simpler. So we just need to find a php file in our template which is executed on each and every request. That should be simple.
Let's do this for a number of templates
Joomla 2.5template. To add Google Analytics to the Beez 20 template, in the Administrator of your Joomla website go to Extensions > Template Manager, click on Templates, click Beez_20 Details and Files > Edit main page template.
Find the closing </head> tag and insert the Google Analytics code there and press Save and Close . (Refer to the image below) and You can choose to this also manually. Go to the /templates folder in the root folder of your website using an FTP client, and open the index.php file. Find the closing </head> tag and insert the Google Analytics code there. See the picture below.
Simply out, this procedure can be applied for any Joomla template! As long as you find the closing </head> tag and insert the Google Analytics tag there, you should be able to add the Google Analytics code.
The procedure for doing this in Joomla 3.0 is identical. The only difference is that the default Joomla 3 template is called Protostar rather than Beez. Therefore, the path to arrive to the main page template is:
Extensions > Template Manager > Templates > Protostar Details and Files > Click on index.php
Once again find the closing </head> and insert the Google Analytics tracking code there and click Save and Close and refresh your website.
If you are using a Joomlart template, it is usually recommended to place the Analytics code in a specific block in the template. For example, let's take the ja_purity III template.
This template has a specific place where you should put the Google Analytics code. Go to Extensions > Template Manager > Templates > Purity III Details and Files > tpls > blocks > head.php
Right at the bottom of the head.php file you will find the following:
<!-- You can add Google Analytics here or use T3 Injection feature -->
Simply add the script here and click Save and Close.
You can add the Google Analytics code to any Joomlart templates using the above technique. Always make sure you are using the head.php file.
RocketTheme templates have an inbuilt feature which does not require you to mess around with files. There is a feature which allows you to simple enable Google Analytics using a switch. We are going to this in the AfterBurner template
To enable Google Analytics in a RocketTheme template: Extensions > Template Manager > AfterBurner2. This will bring you to Templates Manager. From here go to Features and find Google Analytics. Flick the switch to On and enter the UA-XXXXXXXX part of your Google Analytics code. See the final result below. Obviously make sure you enter your own UA code from Google Analytics.
To add Google Analytics to a JoomlaShack template, it is slightly different from the others we have seen, but not too much. We are going to do this using JS_Wright. Go to
Extensions > Template Manager > Templates > JS_Wright Details and Files > template.php.
Here you can find the closing </head> tag and you can insert your Google Analytics code right before the </head> tag once again.