How to install Google Analytics in Joomla

Do you want to understand who is visiting your Joomla website? Google Analytics is a powerful tool that provides information about how people interact with your website. One of the best parts about Google Analytics is that it is provided for free.

In this tutorial, we will show you step-by-step how to install Google Analytics on your Joomla website.

What is the Advantage of Using Google Analytics?

You have a beautiful website that brings value to the people who visit it. Now, you need to bring more people to your website. The advantage of using Google Analytics is that you can understand how people use your website.

You can see what pages drive traffic, articles that were flops, who visits your website, how people find your website, and much more.

This allows you to make informed decisions about how to make your website more engaging, impactful, and profitable.

How to Get a Google Analytics Tracking Code

  1. Start by going to https://analytics.google.com
  2. If you are not signed in with a Gmail account, you will be prompted to sign in.

    gaj-sign-in

  3. Once you have signed in, you will need to sign up for Google Analytics. Start by clicking the Sign Up button.gaj-sign-up
  4. You will need to create a Google Analytics Account and Property. A Google Analytics Account is a separate entity from your Gmail account. It is essentially a bucket that you can place up to 50 properties into. A property is a website or mobile app that you are tracking with Google Analytics.gaj-create-new-account
    You now have a Google Analytics tracking code. All that is left is to install it on your Joomla website.

Ways to install Google Analytics in Joomla

Asynchronous Google Analytics Plugin

The free Asynchronous Google Analytics plugin created by Peter Bui is a simple way to add Google Analytics to your website. There is also a Pro version that provides some extra features.

You need to download and install the plugin. Once the plugin is installed, you will need to change the status to Enabled.

gaj-ga-plugin

Once the plugin is enabled, you should enter your Google Analytics Tracking ID into the Google Analytics Web Property ID field. And enter your domain into the Domain field. Be sure to include www. or any other subdomain you are using.

gaj-ga-tracking-code

Use Your Joomla Template to add Google Analytics

The second way to place the Google Analytics tracking code on your Joomla website is to place a custom code in the HTML head via the template style parameters.

Many templates designers and frameworks allow custom HTML code to be added to the site via custom code fields. You can edit your template style in the Joomla Backend. The template style options can be found in the main menu Extensions > Templates > Styles then select your template.

There are several template frameworks for Joomla that are popular. We will cover how to add Google Analytics with some of these.

Helix 3 Based Templates – Custom Code

If you have a template that was developed on the Helix 3 framework, like JD Atlanta, adding Google analytics is simple.

  1. Copy the Global Site Tag from Google Analytics.

    gaj-global-site-tag-copy

  2. Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
  3. Select the Custom Code tab.
  4. Paste the Global Site Tag script into the Before </html> field.

    gaj-global-site-tag-paste

  5. Click the Save button in the top-left corner.

Helix Ultimate Based Templates – Custom Code

If you have a template that was developed on the Helix Ultimate framework, like the Helix Ultimate template from JoomShaper, adding Google analytics is similar to Helix 3 templates.

  1. Copy the Global Site Tag from Google Analytics (as shown for Helix 3 Templates).
  2. Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
  3. Click the big florescent green Template Options button. Trust me you can’t miss it!
  4. Select the Custom Code tab in the vertical menu.
  5. Paste the Global Site Tag script into the Before </html> field.

    gaj-global-site-tag-paste-helix

  6. Click the Save button at the bottom of the left sidebar.

Gantry Based Templates – Custom Code

If you have a template that was developed on the Gantry framework, like Helium from Gantry, adding Google analytics is not quite as intuitive as some other frameworks. There are two ways. I will show you the second way in the next section.

  1. Copy the Global Site Tag from Google Analytics (as shown for Helix 3 Templates).
  2. Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
  3. Select the Page Settings tab.

    gaj-gantry-page-settings

  4. Click the Custom Content check box, then paste the Global Site Tag code in the Custom Content box.

    gaj-gantry-global-site-tag

  5. Click the Save Page Settings button in the top-right corner.

Gantry Based Templates – Atoms

There is another way to add Google Analytics to your Joomla website using a Gantry template. You can use the Google Analytics Atom.

  1. Copy the Tracking ID from Google Analytics.

    gaj-ga-tracking-id-copy

  2. Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
  3. Select the Page Settings tab, then scroll to the Atoms section at the bottom.

    gaj-gantry-page-settings

  4. You will need to check the box on the right hand of the Drop atoms here… box.
  5. Then grab the Google Analytics atom and drag it with your mouse into the Drop atoms here… box.

    gaj-ga-atom-drag

  6. Click the gray gear in the Google Analytics atom.

    gaj-ga-atom-click-gear

  7. Enter your Google Analytics Tracking ID into the UA Code box, then click Apply and Save.

    gaj-ga-atom-enter-tracking-id

T3 Based Templates – Custom Code

If you have a template that was developed on the T3 framework, like Purity III from JoomlArt.com, adding Google analytics is very simple.

  1. Copy the Global Site Tag from Google Analytics (as shown for Helix 3 Templates).
  2. Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
  3. Select the Custom Code tab.
  4. Paste the Global Site Tag script into the After <html> field.

    gaj-t3-global-site-tag-paste

  5. Click the Save button in the top-left corner.

EF4 Based Templates – Custom Code

If you have a template that was developed on the EF4 framework, like JM Services from Joomla-Monster.com, adding Google analytics is simple, but it can be hard to find if you don’t know what you are looking for. It took me a few minutes the first time.

  1. Copy the Global Site Tag from Google Analytics (as shown for Helix 3 Templates).
  2. Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
  3. Select the Advanced Features tab on the left side.
  4. Select the Developer Tools tab.
  5. Paste the Global Site Tag script into the Code injection field.

    gaj-ef4-global-site-tag-paste

  6. Click the Save button in the top-left corner.

Templates Without Custom Code and Google Analytics Fields

If you are using a template that does not come with the option to add HTML via a custom code field or it does not have a Google Analytics field, you will need to edit the template files. The Varianto template from TemplateMonster is one of these templates.

If you are not a coder, this can sound intimidating. However, it is not as scary as it sounds.

There are two ways to edit the template files. You can access the files directly on the server or developer environment, or you can access them from the Joomla Template component.

If you chose to edit the files directly on your server, they are located in /templates/your-template/.

I will show you how to do this with the Joomla Template component.

Warning:

If you use a template that receives updates from the template developer, any changes to the files can be overwritten with an update. You may want to check with the developer to determine how to create changes that persist after updates.

  1. Copy the Global Site Tag from Google Analytics (as shown for Helix 3 Templates).
  2. Go to your template files (Joomla backend menu Extensions > Templates > Templates then select your template from the list. You should see something like the image below.

    gaj-template-select

  3. If your template was built according to the standard practices of most Joomla template developers, you should find the HTML <head> tag in the index.php file. Click index.php in the list of directories and files on the left.
  4. Find <head> in the code. In our case it is on line 5.

    gaj-template-customize

  5. Create a new line by hitting Enter on your keyboard.
  6. Paste the Global Site Tag from Google Analytics on the new line you created. It should look like the image below.

    gaj-template-global-site-tag-paste

  7. Click the Save button in the top-left corner.

A few Other Methods

There are countless ways to add Google Analytics to your Joomla site. I would like to share just a few more.

There are many plugins that allow you to insert the Google Analytics tracking code into your Joomla website. You can find them by searching the Joomla Extension Directory for Google Analytics.

You can use the popular JSitemap component. Simply paste your Tracking ID in the Code for Google Analytics field under JSitemap > Configuration > Google Webmasters & Analytics.

Finally, you can add Google Analytics with Google Tag Manager.

Google Analytics Tips for Joomla

Put your Google Analytics code just after the opening <head> tag

One of the important things to know is that the higher the tracking script is on the page the more accurate the data will be. You will have more accurate hit and bounce numbers. The reason is that the JavaScript file needs to be loaded into the visitor’s browser. If the network is slow or the user bounces quickly, you want to be able to count the hit.

To track these interactions, you will need to load the tracking script quickly. Placing the tracking code in the top of the HTML file, just after the opening <head> tag will ensure that it is loaded as soon as physically possible.

Don’t Load the Google Analytics Code for Joomla Admin users

If you spend a lot of time on your site, it is easy to artificially increase the number of hits, page views, time on site, etc. To correct this, you can create a filter in Google Analytics so that your own traffic is not included in the displayed data.

However, if you are like me, you don’t want your own traffic sent to Google Analytics at all. If you add Google Analytics to the Index.php file this is simple. Just use the following code instead of the code supplied by Google Analytics.

<?php 
    $user   = JFactory::getUser();
    $isroot = $user->authorise('core.admin');
    if ($isroot) { ?>
        <!-- Joomla Admin - Google Analytics not loaded -->
    <?php } else { ?>
        <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X">
        <script>
            window.dataLayer = window.dataLayer || [];
            function gtag() { dataLayer.push(arguments); }
            gtag('js', new Date());
            gtag('config', 'UA-XXXXXXXXX-X');
        </script>
    <?php } ?>
?>

Be sure to replace both instances of UA-XXXXXXXXX-X with your tracking ID.

This will load the Google Analytics tracking code on pages that are viewed by anyone who is not logged in as an Administrators or Super Users. This allows you to log in and avoid including your own browsing activity in Google Analytics.

Summary

Google Analytics is a powerful tool to help SEOs, marketers, webmasters, and bloggers understand their users and readers. It can help you understand your audience.

There is a lot of ways to add Google Analytics to your Joomla website. You can use a plugin like Asynchronous Google Analytics. You can also use your template to add the tracking code.

Depending on template framework or options you may be able to add the tracking code as HTML custom code. However, you may need to edit your template’s index.php file. This is an easy change and is definitely a good place to start for a beginner.

I hope that this tutorial has been helpful. You can get more awesome tips and tutorials like this straight to your inbox by signing up for our Newsletter.

About the Author
Joomla Author Daniel Morell

Daniel Morell

Daniel is a web developer, digital marketer, and Joomla enthusiast. He has been using Joomla to help businesses grow online since 2013. He enjoys spending his free time educating new webmasters about SEO and marketing. You can find him on twitter @dancmorell.
Sign up to our Joomla Newsletter
Get awesome content delivered straight to your inbox twice a month

Comments

Powered by EngageBox