Skip to main content

Adding Google Tag Manager / Analytics to Joomla

While Google Tag Manager is probably the worst thing you can do to your site regarding privacy and GDPR, it is also a convenient and free tool to track your users and their behavior.

Installing the Google Tag Mananger code is just adding a few lines of code and should be pretty simple.

However, the code should go into the <head> section and the upper part of the <body>, parts you can't access directly. 

Although google prefers the code in the <head> of your document, it will work as good in any other place. It's loaded asynchronous with the document anyway. So shouldn't make a difference if it's in the footer of your page.

Adding the Google Tag Manager

Inserting Google Tag Manager into your Joomla website requires either editing your template file(s) or using a plugin to insert the container in the correct locations.

There are pros and cons for both approaches. Inserting into the template requires you to edit the code of some files. However, it means it's not easy to remove or unpublish accidentally. Using a plugin is fast en easy if you are not into editing HTML code or the template is updated frequently from an external source.

Adding to the template

If your template isn't updated  (automaticity), for example because it's custom-made, the best method to add the GTM-code is directly into the templates code. Most likely into the file template/<template>/index.php. No plugin needed. Although the plugin below isn't large, it adds code-loading and database queries to processing of your page.

Add the code to the error.php, and depending on the use the component.php, files as well. 

Adding to a templates configuration

Some templates allow adding custom code through their configuration. If so, add the <script> part of the GTM-code. It's probably safe to omit the <noscript> part.

Using the GTM 4 Joomla plugin

The solution that should work on any Joomla installation is using the plugin for download on this page.

Install it, add your GTM-id and you are done.

The plugin will add both the <script> and <noscript> parts in the recommended locations.

Script noscript iframe

The Google Tag Manager code has two parts. The first part is the <script> and should be added, otherwise your visitors will not be tracked correctly.

The other part is the <noscript>/<iframe> part. This code is used to track the accidental user with JavaScript disabled.

There isn't any good relevant data regarding how many people browse the web without JavaScript, but it can't be that many of them. Just try to disable JavaScript for a while and browse your websites. Take a closer look at what happens. The internet is that broken without JavaScript.

Thus, the <noscript> code will not add a lot to the tracking and could be omitted. Unless you have some obscure reason to use it. 

If you plan to validate your website for the Google Search Console using GTM the iframe might be needed.  Search Console has several other validation method's, 

Both the <script> and <noscript> tracking are blocked by ad blockers.



  • simple installation and configuration
  • possibility to change the name dataLayer
  • disable/enable code for  logged in user
  • enable/disable code for the administration interface
  • free download
  • Native Joomla 4.4+ / Joomla 5 plugin

Looking for Matomo?