How to Insert Google Analytics Code in Joomla 3

Cody Schneider••8 min read

Getting Google Analytics set up on your Joomla 3 website is one of the first, most important steps in understanding your audience. This article will guide you through connecting Joomla 3 and Google Analytics using two straightforward methods. We'll cover how to add the code manually and how to use a simple extension, so you can choose the approach that works best for you.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Before You Begin: Get Your Google Analytics Tracking Code

Before you can add analytics to Joomla, you need a free Google Analytics account and the specific tracking code for your website. If you already have this, feel free to skip to the next section. If not, here’s how to get it quickly.

We'll be focusing on Google Analytics 4, which is the current standard. Its tracking code looks a bit different from the older Universal Analytics version you might have seen in the past.

  1. Create or Access Your Google Analytics Account: Go to the Google Analytics website. You can either sign in with your existing Google account or create a new one for free.
  2. Set Up a New Property: After logging in, you'll need to create an "Account" (usually your business name) and a "Property" (your website).
  3. Create a Data Stream: A "data stream" is simply the source of your data. For a website, this is pretty simple.
  4. Find Your Global Site Tag (gtag.js): Once the stream is created, a window will pop up with installation instructions. You need the full code snippet for one of the methods below.

Your code will look something like this, but with your unique "Measurement ID" instead of G-XXXXXXXXXX:

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [],
  function gtag(){dataLayer.push(arguments),}
  gtag('js', new Date()),

  gtag('config', 'G-XXXXXXXXXX'),
</script>

Keep this code handy. Now you're ready to add it to your Joomla site.

Method 1: Manually Adding the Code to Your Joomla Template

This method involves directly editing your website template's main file. It’s a great option if you're comfortable with editing a tiny bit of code and want to avoid installing extra extensions on your site.

Pros: No extra plugins to manage, complete control over the code placement. Cons: If you update your template, your changes might get overwritten. It can also be intimidating for beginners.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Step-by-Step Instructions

1. Log into Your Joomla Administrator Panel

Navigate to your Joomla login page (usually yourwebsite.com/administrator) and log in with your username and password.

2. Navigate to Template Manager

From the main control panel, go to the top menu and click on Extensions > Templates. Be sure to click "Templates" on the left, not "Styles." This will show you a list of the template files, not just the visual styles.

3. Open Your Active Template

You'll see a list of installed templates. You need to edit the one that's currently active on your website. Under the "Template" column, click on the name of your default template (it will usually have a star next to it in the template styles view).

4. Locate and Edit the index.php File

After clicking your template name, you'll see a file editor with a list of the template's files on the left. The file you need to edit is almost always named index.php. Click it to open it in the editor on the right.

5. Paste the Google Analytics Tracking Code

This is the most important step. You need to paste the Google Analytics code you copied earlier in the correct spot. Scroll through the index.php file until you find the closing head tag, which looks like this: </head>.

Paste your entire Google Analytics tracking script on a couple of lines right before that </head> tag.

Placing it here ensures the script loads on every single page of your website, which is exactly what you want for accurate tracking. It also helps it load early, so it can capture data from visitors who might leave the page before it fully loads.

6. Save Your Changes

Once you’ve pasted the code, click the “Save & Close” button at the top of the page. That's it! The tracking code is now live on your website.

A Quick Warning: If you ever update this Joomla template in the future, the template developer's update may overwrite the index.php file, removing your Analytics code. If that happens, you’ll just need to repeat these steps to add it back.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Method 2: Using a Joomla Extension for Easy Integration

If editing code isn't your cup of tea, or you want a method that’s safe from being overwritten by template updates, using an extension (a Joomla plugin) is the perfect solution. There are many extensions available, both free and paid, that make this process incredibly simple.

Pros: Very user-friendly, survives template updates, and sometimes offers extra settings. Cons: Adds another extension to your site, which you'll need to keep updated.

For this tutorial, a great, lightweight option is the "JExtBOX Easy Google Analytics" plugin. It's free and gets the job done perfectly for Joomla 3.

Step-by-Step Instructions

1. Go to the Joomla Extension Installer

First, log in to your Joomla administrator panel. Then, navigate to Extensions > Manage > Install from the top menu.

2. Find the Extension

When you arrive, click on the "Install from Web" tab. This accesses the official Joomla Extensions Directory. Use the search bar to find "Easy Google Analytics." You should see the one by JExtBOX in the results.

3. Install the Extension

Click on the extension name in the search results, and on the next page, click the green "Install" button. Joomla will automatically handle the download and installation process. You should see a message confirming the installation was successful.

4. Go to the Plugin Manager

Now that the extension is installed, you need to configure it. From the top menu, navigate to Extensions > Plugins.

5. Find and Open the Plugin

In the Plugin Manager, use the search bar to find "Easy Google Analytics." Once you find it, click its name to open its settings page.

6. Configure the Plugin with Your ID

Inside the plugin settings, you'll find everything you need:

  • Status: Make sure this is set to Enabled. If it's disabled, the plugin won't do anything.
  • Tracking Code Type: Ensure this is set to use the "gtag.js (For GA4 Property)."
  • GA4 Measurement ID: This is where you enter your tracking ID. You only need the ID, not the entire script. It's the string that starts with "G-" (for example, G-XXXXXXXXXX).

You can optionally configure the plugin to exclude tracking for administrators, which is a great way to keep your own activity from skewing your data.

7. Save and You're Done!

After you've set the status and entered your Measurement ID, click the "Save & Close" button. The extension will now automatically insert the correct Google Analytics tracking code onto every page of your site.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

How to Verify Your Google Analytics Setup is Working

After installing your tracking code with either method, it's wise to double-check that it's working properly. There are a couple of very simple ways to do this.

1. Use Google Analytics Realtime Reports

This is the most reliable way to confirm data is being sent and received correctly.

  • Log into your Google Analytics account.
  • In the menu on the left, navigate to Reports > Realtime.
  • Open your Joomla website in a new browser tab or on your phone. Browse a few different pages.
  • Look back at the Realtime report in Google Analytics. Within a minute or so, you should see yourself appear as an active user, usually on a world map and a card titled "Users in last 30 minutes".

If you see your activity, congratulations! Your Joomla 3 site is successfully tracking visitors.

2. Check Your Website's Page Source

This is a more technical check, but it’s fast and easy. It confirms that the code exists on your page, even if Google's analytics server is slow to respond in the Realtime report.

  • Go to any page of your Joomla website.
  • Right-click anywhere on the page and select "View Page Source" (the wording might vary slightly between browsers).
  • A new tab will open with your website's HTML source code.
  • Press Ctrl + F (on Windows) or Cmd + F (on Mac) to open a find dialogue box.
  • Search for "gtag.js" or your Measurement ID (e.g., "G-XXXXXXXXXX").

If the search finds a match in your code, you can be sure the tracking script has been successfully inserted.

Final Thoughts

Connecting your Joomla 3 site to Google Analytics is now complete. Whether you chose to insert the code manually into your template or use a handy extension, your site is now gathering valuable information that can help you understand your audience and grow your online presence.

Now that your data is flowing, the next challenge is turning all those numbers into actionable insights. Sifting through reports in Google Analytics, then logging into Google Ads, Facebook Ads, and a dozen other platforms to connect the dots can become a full-time job. With Graphed, we eliminate that hassle. You can connect all your sources, including Google Analytics, and just ask questions in plain English, like "Show me a dashboard comparing my top landing pages by traffic and conversions from Google Ads." Instantly, you get real-time dashboards that help you see the complete picture and make smarter marketing decisions faster.

Related Articles