If you are a website owner then I need not explain the importance of integrating Google Analytics in a website. I would go to the extent of saying that if there is a website, it has to include Google Analytics tracking code because that’s the best analytics tool ever and is available to everyone free of cost.
In the two approaches mentioned above, adding the tracking code via extensions is clearly better since you need not worry if upgrading template might result in loss/overwriting of your tracking code. But even with this approach, there are few issues mentioned below.
- A good many number of (specially free) Joomla extensions are one-off efforts by individual developers where they create it, make it available for anyone to use and then forget about it. Such extensions are rarely, if at all, upgraded to keep up with Joomla upgrades. At some point, such extensions fail to work because they no longer support the latest Joomla version which results in Google Analytics not working on your website.
- Most of the Joomla extensions for Google Analytics integration typically require your tracking ID only and hardcode rest of the tracking code within their extension. Now if Google makes any changes to their tracking code then the extension would stop working unless,
- extension developer updates the extension,
- you uninstall the old version and install the latest version.
Google doesn’t update such things very often but they did that when they replaced the (now legacy) ga.js tracking code with analytics.js. In short, it’s always a possibility and you would want to be on the safer side.
- As mentioned in previous point, such extensions generally require only tracking ID, which looks something like UA-1234567-89, and hardcode rest of the tracking code in their extension using default tracking code. Though most of the webmasters would be happy with default tracking settings/code, Google Analytics allows you to customize your tracking settings. For example, you can track the activities of individual users by including user identifier in their tracking code and such changes may require additional code which is most likely missing in these extensions. And if you would like to benefit from such capabilities of Google Analytics then you might find yourself in trouble if you rely on such Joomla extensions.
One possible option could be to use a commercial extension which provides you all the features and customization flexibility for Google Analytics integration with good support and roadmap for upgrades/updates. But when Google Analytics itself is free (not talking about the Enterprise version folks), why would you want to pay for an extension to just integrate it in your website?
So what’s the cleanest and future-proof way to integrate Google Analytics in your Joomla website which also doesn’t cost anything?
Here is what I do if I need to integrate Google Analytics in a Joomla site.
- Make sure that Sourcerer plugin is enabled.
- Now go to Module Manager and create a new Custom type module.
- Give any name to the module you like, select Hide option for “Show Title” and “Position” as debug as shown in the image above.
- Change to Menu Assignment tab and select “On all pages” as shown below.
- Save the module and you’re done. Open your website in any browser and view the page source to verify that analytics code that you added is present. If you aren’t sure how to do that, you can just wait for sometime and check your Google Analytics data for same day. It should show at least one visit (you) assuming you visit the website at least once after making all the changes.
With this approach you’re in full control of the Google Analytics code and it doesn’t require any more efforts than any of the two approaches (adding tracking code in template or using an extension). Further, it’s future proof from Joomla upgrades and template upgrades since custom module type is a native Joomla module. If you ever make any customization to your tracking code or if Google asks you to upgrade your tracking code, all you need to do it copy and replace the tracking code in the module that we created.
The only dependency that we have here is on Sourcerer but I have known that extension since I know Joomla (more than 7 years) and it has been free since then. I don’t see any reason why it would be made paid or discontinued if that hasn’t happened so far.
So now you know the best way to add Google Analytics tracking code to your Joomla website 🙂