Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Google Tag

Security covered Under active development 138,247 sites

This module integrates your site with Google Tag Manager, allowing you to deploy analytics and measurement tags through a web interface without directly editing your website's code. It supports multiple containers and allows you to specify conditions for inserting tags, such as by path, user role, or domain.

Which version should I use?

  • 2.x (2.1.0 and later) is the current branch. It supports Drupal 10.3, 11 and 12, and both Google tag (gtag.js) and Google Tag Manager. Use it for Google Analytics 4, Google Ads and Tag Manager.
  • 8.x-1.x supports Drupal 8.8 to 10 and Google Tag Manager only. New features are added to 2.x only.
  • 7.x branches are for Drupal 7, which reached end of life in January 2025.

Google Tag adds Google Tag Manager and the Google tag (gtag.js) to your site, so you can run Google Analytics, Google Ads and other measurement tags. You choose which pages, roles and responses the tags load on, and the module can send common events, such as logins, searches and Commerce purchases, without any custom JavaScript.

Features

  • Google tag and Tag Manager IDs in one place. Add any mix of Google tag IDs (G-, AW-, DC-, GT-) and Tag Manager container IDs (GTM-), and order them by weight.
  • Insertion conditions. Load tags only on certain paths, for certain user roles, or for certain response status codes. Any condition plugin on your site can be used, including ones from other modules, and a language condition appears on multilingual sites.
  • Multiple tag containers. Most sites need one. If different tag IDs need different conditions or events, turn on multiple containers in the module settings. The container list is drag-and-drop: the first enabled container whose conditions match is used.
  • Events. Send GA4 recommended events automatically (see below). Each event can be turned off per container.
  • Custom dimensions and metrics. Add custom parameters to the Google tag configuration, with token support.
  • Consent Mode. "Enforce Privacy Consent Policy" sets Google's default consent state to denied, so a consent management tool can grant it once the visitor agrees.
  • Tag Manager options per container ID. Data layer name, allowed and blocked tag classes, environment ID and token, and whether to add the <noscript> fallback iframe.
  • Content Security Policy. Works with the CSP module, which adds Google's domains to your policy.
  • Drush. drush google_tag:create --id=GTM-XXXXXXX creates a container and makes it the default, for provisioning scripts. It needs Drush 13.7 or later.

Events

Events are sent with gtag.js, which also adds them to the data layer for Tag Manager. Events that depend on another module appear only when that module is installed.

  • Core: login, sign_up and search (core Search and Search API views).
  • Commerce: view_item, view_item_list, add_to_cart, remove_from_cart, begin_checkout, add_shipping_info, add_payment_info, purchase and refund, plus add_to_wishlist with Commerce Wishlist.
  • Webform: a webform handler that sends a purchase event when a submission is saved.
  • Your own code: the google_tag.event_collector service can send generate_lead or any custom event. Use addDelayedEvent() for events that happen before a redirect, so they are sent on the next page.

Getting started

  1. Install the module with composer require drupal/google_tag and enable it.
  2. Go to Configuration » Web services » Google Tag (/admin/config/services/google-tag).
  3. Enter your Google tag ID or Tag Manager container ID. Add more IDs if you need them.
  4. Review the events, conditions and advanced settings, then save.

Upgrading

  • From 8.x-1.x: update the code to 2.x and run database updates (drush updatedb). Existing containers and their settings are converted. Run the database updates before importing configuration, so the old settings are not removed before they are converted.
  • From the Google Analytics module: when Google Tag is installed, it imports the Google Analytics module's settings into a new container and stops that module from adding its own script, so tags are not sent twice. You can uninstall Google Analytics afterwards.

Placement and Google Search Console

The Google tag and Tag Manager scripts load asynchronously at the end of the page, and the Tag Manager <noscript> iframe is added at the top of the body using standard Drupal hooks. Search Console's Tag Manager verification may report that the snippet is not "immediately after the opening body tag". This does not affect tracking. If you need it there for verification, move it in your theme's html.html.twig, or verify the site another way.

Support

Report bugs and feature requests in the issue queue. Please include the module and Drupal versions, and which tag IDs and events you use.

Ask your assistant about Google Tag

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

3 tracked projects depend on this one

Activity

Tracked releases
18
Tracked since
Mar 2023
Latest release
1 week ago
Releases (12 mo)
2 ▼ from 5
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
2.x-dev Dev 10–11 Nov 17, 2026
2.1.0 Stable 10–11 Nov 17, 2026
2.0.9 Stable 9–11 Aug 25, 2025
2.0.8 Stable 9–11 Jan 29, 2025
8.x-1.8 Stable 8–10 Jan 28, 2025
7.x-2.3 Stable Jan 28, 2025
2.0.7 Stable 9–11 Dec 2, 2024
2.0.6 Stable 9–11 Jul 25, 2024
2.0.5 Stable 9–10 PHP ^7.4 || ^8 May 21, 2024
8.x-1.7 Stable 8–10 Mar 19, 2024