Adding Google Analytics to a Joomla site

Google Analytics is one of the first things you should enable if you’re planning to run a serious website, as the information you get is very rich and thorough. It will definitely help you with seeing what your users want and what changes to make to better meet their needs. In this article, we’ll show you how to add Google Analytics to your Joomla site.

  • What is Google Analytics?

    Google Analytics is the most popular service to track website traffic. With it, you can easily see info like session duration, opened pages per session, bounce rate, in which country is your site most popular…the list is endless. You get a dashboard with all the general info, presented neatly and accurately. You can click on each of the sections and get much more detailed info. It’s all very modular and you can set it up to your liking. Add charts, graphs, whatever floats your boat. It works by adding a tag, a snippet of code which is made for your site.

    Adding Google Analytics on my Joomla page

    There are a few ways to enable Google Analytics on your paga. Let’s start with the easy way:

    Install a plugin responsible for embedding Google Analytics

    A simple search in the Joomla Extensions Directory will reveal a plethora of plugins that can help you in adding Google Analytics to your site. For this article, I will be using Advanced Google Analytics by Alin Marcu. The general idea is the same, whichever plugin you use.

    If you have trouble installing extensions, you can always check out our How to find & install a Joomla extension article.

    So, after installing the plugin, you need to enable it.

    1. Go to Extensions -> Plugins
    2. Find your newly installed plugin
    3. Open it and set the Status to Enabled
    Image of Advanced Google Analytics plugin settings.
    Plugin settings

    Enter your Google Analytics ID and your Domain name in the relevant fields and hit Save.

    That was it! You can check if Analytics are working by searching for a code snippet in the <head> of your site.

    <script type="text/javascript">
    
    (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', '', 'auto'); ga('require', 'displayfeatures');
    
    ga('send', 'pageview');
    
    </script>

    Do it manually

    To implement Google Analytics manually, you need to edit the template and include the code required for Analytics to function. One thing to note is that there is no standard way to do this, it depends on the template you are using.

    Since Protostar is the default template on all Joomla 3.x sites, these steps will be explained for that template in mind.

    1. Log to the Administrator part of your site
    2. Go to Extensions -> Templates -> Templates
    3. Click on Protostar Details and Files
    4. Open index.php and paste the code snippet just below <head>
      Image of adding code snippet into head section of index.php file.
      Code snippet in the <head>
    5. Click Save

    That should be it. Refresh your site and check if everything is present in your code.

    There are some templates that have dedicated fields for adding Analytics code. You don’t need to manually paste the code in index.php, simply paste it in the relevant field. It all depends on the template you use. Snoop around the Template options and you might find a lot of fields that help your workflow.

    In a few days, you will get some great insight into your sites performance and you can act accordingly.

    This concludes this article. Hopefully you learned something new and are going to make the most of the newly found information about your site.

    After adding Google Analytics, you might want to add Google Tag Manager to your site. Those two work in conjunction and offer even more information. Read our article on Adding Google Tag Manager.

    Further Insights