If you are sticking with the default Protostar Template for Joomla 3+, you need to either install a 3rd party extension that attaches the Google Analytics <script> code to each page of your site or you can edit the index.php file to include this code. Some 3rd party templates have functionality in Template Manager where you can add this code from Google Analytics into a text box.

We are assuming that you have a Google Analytics account and know how to get your Google Analytics code.

The Code will look something like this:

<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', 'UA-XXXXXXXXXXX', 'yourdomainname.com');
    ga('send', 'pageview');
</script>

Per the instructions on the Google Analytics site, this code needs to be placed in the <head> section, right before the <body> tag, of each and every page on your website.

Joomla uses the index.php page from your template to create every page on your site. Joomla 3 makes editing this file quite an easy task. Unfortunately, we have not seen that Joomla 3 has made it an easy task to make a backup copy of this file before you edit it. This is an important step in case you mess up your editing to the point that is causes problems for the site.

Using FTP access for your site, or the file manager that comes with your hosting company, such as cPanel, copy the index.php file and save the copy with a logical name such as index4-13-14.php. That way if you have multiple old copies, you instantly know which one is the most recent. The save date is not always reliable.

Open the original index.php file in a text editor on your own computer or use the new features in Joomla 3's Template Manager to edit it in the text editor available there.

Scroll down through the index.php and find the closing </head> tag. Paste the Google Analytics code just before this tag. 

Open up your site in a browser and look at the Source Code - be sure the Google Analytics code is showing up on every page.

Remember that if you upgrade your Joomla site, the index.php file will be overwritten. You will need to repeat these steps for adding the Google Analytics code with each upgrade.


Has BJ.Zemplate.com helped you with understanding Joomla?

If you would like to make a small contribution to help fund this resource, that would be great, but do not feel obligated in any way.

Donation Amounts


Still not finding a special topic?

Use Google's Search function below for search the content of bj.zemplate.com.