Google Tag

The 2.0.x branch supports Google Tag and Google Tag Manager. Users of Google Analytics should be using the 2.x version of this module.

This project integrates the site with the Google Tag Manager (GTM) application. GTM allows you to deploy analytics and measurement tag configurations from a web-based user interface (hosted by Google) instead of requiring administrative access to your website.

To use the module, sign up for GTM and obtain a "container ID" for your website. For development purposes, create a GTM environment for your website.

CRITICAL NOTES for releases 8.x-1.3+
If the site enables other modules that implement condition plugins (e.g. ctools, rules, webform), then it will most likely be necessary to apply the core patch from issue '3114467' (link intentionally omitted).

If Drush commands are run as a user other than the web user, then do NOT enable the recreate snippets on cache rebuild module setting unless the web user has permission to delete files created by the Drush user. This setting will be disabled by default beginning with release 8.x-1.6.

Features in 8.x and 7.x-2.x branches
These branches support multiple containers. From the container management page, add a container and enter the "container ID" and "environment ID" on the container form. You may also configure the conditions on which the tags are inserted on a page response. Conditions exist for: request path, user role, response status, domain, and language. The latter two require the domain and language (8.x) or locale (7.x) modules, respectively.

In addition, other modules may also define and implement additional conditions using the condition plugin architecture in 8.x or the exposed hooks in 7.x (see the api.php file). Alternatively, other modules can implement hook_google_tag_insert_alter() to apply additional conditions on the containers inserted on a page response.

Additional features in 7.x-2.x branch
The 7.x-2.x branch also provides a variable realm condition. The realm condition may be used to filter the containers by realm, such as language and domain. This feature requires the variable_realm and variable_store modules to be enabled and configured.

Features in 7.x-1.x branch
This branch implements the Variable API, so that settings may be separately configured by realm, thus enabling support for multiple languages and domains.

False positives from Google Search Console
If you attempt to verify your site for GTM using the Google Search Console, be aware the Google tool will return false positive results. For example, the tool will indicate the "noscript" snippet needs to be placed "immediately" after the opening body tag. (NOTE: The module places the snippet as close to the body tag as can be done using standard Drupal hooks.) Verification using this tool may fail but the JavaScript works properly and tags will be added to the page and fired as defined in your GTM account. If you want this snippet immediately after body tag, then modify the theme template file (html.tpl.php for Drupal 7, html.html.twig for Drupal 8), as it controls how close the snippet will be to the body tag.

Supporting organizations: 
Development of 2.0.x
Development of 2.0.x

Project information

Releases