How to install Google Analytics in Joomla
- by Daniel Morell
- on Tutorials
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
- Start by going to https://analytics.google.com
- If you are not signed in with a Gmail account, you will be prompted to sign in.
- Once you have signed in, you will need to sign up for Google Analytics. Start by clicking the Sign Up button.
- 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.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.
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.
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.
- Copy the Global Site Tag from Google Analytics.
- Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
- Select the Custom Code tab.
- Paste the Global Site Tag script into the Before </html> field.
- 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.
- Copy the Global Site Tag from Google Analytics (as shown for Helix 3 Templates).
- Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
- Click the big florescent green Template Options button. Trust me you can’t miss it!
- Select the Custom Code tab in the vertical menu.
- Paste the Global Site Tag script into the Before </html> field.
- 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.
- Copy the Global Site Tag from Google Analytics (as shown for Helix 3 Templates).
- Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
- Select the Page Settings tab.
- Click the Custom Content check box, then paste the Global Site Tag code in the Custom Content box.
- 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.
- Copy the Tracking ID from Google Analytics.
- Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
- Select the Page Settings tab, then scroll to the Atoms section at the bottom.
- You will need to check the box on the right hand of the Drop atoms here… box.
- Then grab the Google Analytics atom and drag it with your mouse into the Drop atoms here… box.
- Click the gray gear in the Google Analytics atom.
- Enter your Google Analytics Tracking ID into the UA Code box, then click Apply and Save.
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.
- Copy the Global Site Tag from Google Analytics (as shown for Helix 3 Templates).
- Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
- Select the Custom Code tab.
- Paste the Global Site Tag script into the After <html> field.
- 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.
- Copy the Global Site Tag from Google Analytics (as shown for Helix 3 Templates).
- Edit your template style (Joomla backend menu Extensions > Templates > Styles then select your template from the list.
- Select the Advanced Features tab on the left side.
- Select the Developer Tools tab.
- Paste the Global Site Tag script into the Code injection field.
- 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.
- Copy the Global Site Tag from Google Analytics (as shown for Helix 3 Templates).
- 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.
- 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.
- Find <head> in the code. In our case it is on line 5.
- Create a new line by hitting Enter on your keyboard.
- Paste the Global Site Tag from Google Analytics on the new line you created. It should look like the image below.
- 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.