Custom Joomla module for Google Analytics

This guide applies to:
Joomla 1.5.X

How to Create a custom module for Google Analytics in Joomla 1.5

Define the new module position

Open your template XML configuration file (/templates/<templatename>/templateDetails.xml). Locate the <positions> tag in your XML file. It looks something like this:


Add your own position (googleanalytics). The end result will be something like this:


Save the changes.

Create the position

Navigate to 'Extensions > Template Manager' and click on your default template name. In the 'Template: [ Edit ]' view, click on the 'Edit HTML' button. Now you see the PHP code for your tempate.

Locate the </head> tag and insert the position code (<jdoc:include type="modules" name="googleanalytics" />) immediately before it. The end result will be something like this:

<jdoc:include type="modules" name="googleanalytics" />

Save the changes.

Create the module

Before you create the module, go to Site > Global Configuration and change the default WYSIWYG editor to 'No editor' (don't forget to change it back when you are done).

Go to Extensions > Module Manager and click on the 'New' button. Select 'Custom HTML' as the module type and click 'Next'.

In the details section, change the module settings to the following:

Title: Google Analytics
Show Title: No
Position: googleanalytics

Insert your Google Analytics Tracking Code (urchin.js or ga.js) in the 'Custom Output' field. It will look something like this:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-12345678-1']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

Click on 'Save'.


Use this guide at Google Analytics Help to verify:


Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer