Effortless Google Tag Manager Setup for Drupal

  • Last updated
  • 1 minute read


With this tutorial you will be able to install and configure the Google Tag module for Drupal


Being able to know what your users are doing on your website is a critical component of maintaining and running your Drupal website.  For years, site maintainers have relied on Google Analytics to gather that information and with the recent launch of GA4 it's important to make sure your site is setup for success.  The Acquia Drupal Integration Team has worked closely to upgrade the Google Tag Manager module as part of the GA4 transition and it is better than ever.  Leveraging the latest GTag script and supporting GTM all from within the same module eliminates confusion for developers and maintainers.  During this tutorial we will step you through how to install the new Google Tag Manager module and some basic configuration items you need to consider.

  1. Install the Google Tag Manager module

    Add the Module

    Depending on how your Drupal site is setup, there are different ways to add the module to your codebase.  The most popular was is through Composer and that can be accomplished using the following command:

    composer require 'drupal/google_tag:^2.0'

    If you would like additional information about installing modules on your Drupal site, you can reference the Acquia Docs page on this topic.

    Enable the Module

    Navigate to Extend in the Admin Toolbar, when you get to the Module listing page you can filter the list by typing "Google" which will shorten the list of modules so you can find the one you are looking for.

  2. Configure the Google Tag Manager Module

    After the Metatag module has been successfully installed you can navigate to Configuration > Search and Metadata > Metatag

    Configure Google Tag Module

    This configuration page let's you configure the Google Tag module, like your Tag ID, Custom Dimensions & Metrics, Events and Conditions.  They allow you to configure the module for any of your own use cases or needs.


The Google Tag ID is unique to each site you want to track separately, and is in the form of UA-xxxxx-yy, G-xxxxxxxx, AW-xxxxxxxxx, or DC-xxxxxxxx. To get a Web Property ID, register your site with Google Analytics, or if you already have registered your site, go to your Google Analytics Settings page to see the ID next to every site profile. Find more information in the documentation.

Additional Configuration Options

  1. Custom Dimensions & Metrics

    Within GA you are able to define and outline your custom dimensions and send this data to GA through Events or other actions that you users take on your website.  Within the Google Tag module you are able to define what those additional metrics and dimensions are, and by using the powerful Token module in Drupal, easily send additional information over with that request.

    Google Tag Dimensions

    You can click the "Browse available tokens" link to see the Tokens available to you.  Don't forget you need to follow the Google standard for Custom Dimension names here as well.

  2. Events

    The Drupal Google Tag module has configured some common Events which can be tracked out-of-the box.  You are also able to configure the names of these events in case you want to change them to better fit your use-case.

  3. Conditions

    By default, the Google Tag module enables the tag to display on every page (except for some default conditions) but you might want to have more control over where and when the tag is added to your pages.  Using the Conditions section of the module configuration you can set different configuration values.  For example, you can exclude it for certain roles or for authenticated users or disable it for content editors.

  4. Advanced Settings

    The advanced settings provide some additional settings for the configuration of the Google Tag. If you have a different name for your dataLayer or you want additional classes added to the dataLayer or you want to enable more development variables you can do that as well

    In most instances you shouldn't need to change these values, so they can be mostly left as the defaults.

Acquia has worked closely with Google to make sure that the new Google Tag module for Drupal is optimized to work with the latest version of the Google Tag script and Google Tag Manager.  By consolidating other implementations of Google Tags in Drupal we are able to standardize on the optimal way to added this functionality to your Drupal site.  Stay tuned for other great Drupal and Acquia tutorials on the Acquia Developer Portal to help you optimize your Drupal site and your code.

Frequently Asked Questions

    The Google Tag module acts as a bridge between your Drupal website and Google Tag scripts (GA, GTM, etc), simplifying the process of adding the necessary tracking code to your site's pages. With this module, you can configure and customize various tracking options directly from your Drupal admin interface, eliminating the need to manually insert the tracking code into your site's template files.

    A Google Tag ID is a unique identifier assigned to a specific property or website within your Google Analytics account. It's used to track and collect data about user interactions and behavior on your website. This ID is typically in the format of "UA-XXXXXXX-X" (for Universal Analytics) or "G-XXXXXXXXXX" (for Google Analytics 4). By integrating this tag ID into your website's code, you enable Google Analytics to gather insights into user activity, helping you make informed decisions about your website's performance and optimization.

    In Google Analytics 4 (GA4), custom dimensions are a way to collect and categorize additional data beyond the default parameters provided by the platform. They allow you to tailor your analytics tracking to your specific business needs and gain deeper insights into user behavior and interactions on your website or app.

    In Google Analytics 4 (GA4), events are user interactions or actions that are tracked on your website or app. Events provide valuable insights into how users engage with your digital property, helping you understand user behavior, measure conversions, and evaluate the effectiveness of your content and marketing strategies.