Drupal
min read

Setting up Google Tag Manager and Google Analytics in Drupal

Setting up Google Tag Manager and Google Analytics in Drupal
Table of contents

Google Tag Manager (GTM) and Google Analytics (GA) are widely used for monitoring user behavior and performance on websites. They allow us to create tracking tags and triggers without coding to follow how users interact with a site. This provides actionable data to optimize web design and functions.

Together, these tools enable website owners and marketers to gain valuable insights into user website activity. The analytics and tracking capabilities inform data-driven decisions to improve visitor experience.

Google Tag Manager (GTM)

Google Tag Manager (GTM) is a tag management system that helps to easily update tracking code fragments (known as tags) on websites and apps. It works by creating tags, triggers, and variables that help gather data and analytics on web user activity.

Learn how to use Google Tag Manager and create tags and triggers here.

Google Analytics (GA-4)

Google Analytics (GA) is an analytics service used to measure traffic and engagement on websites and apps. We can generate reports on tracked web activity using dimensions and metrics. While real-time and debug views show current data, report generation can take 24-48 hours to process.

Note:  Google has announced that starting from July 2023, GA-UA (Universal Analytics) will be replaced by GA-4, and standard Universal Analytics properties will stop processing new data.

Differences between GA-UA and GA-4

Features GA-UA GA-4
Data Model Treats each interaction as a particular outcome, anything from page views to events to transactions. Hit-based Event-based
Reporting Model Analyze and visualize data collected from websites or apps. Sessions and Pageviews-based Events and User-centric
Event Tracking Captures all kinds of information about how people behave/interact on a site. Limited Advanced
User ID Tracking A special reporting view that only displays data from sessions sent from unique ID to Analytics. Requires custom implementation Native support
Cross-device Tracking Allows unification of separate sessions from the same user into one journey. Limited Enhanced
Audience Creation Audiences in Google Analytics are a group of users who perform similar actions. Using segments Using custom dimensions and events
Integration Is designed to work seamlessly with other Google solutions and partner products, saving time and increasing efficiency. Limited Enhanced with Google Ads, Google Adsense, and more
Machine Learning Brings Google machine-learning expertise to process datasets and predict the future behavior of users. Basic features Advanced ML capabilities for insights and predictions
E-commerce Tracking Allows to track e-commerce websites. Standard e-commerce tracking Enhanced e-commerce tracking
Data Control: Allows to control how Google may use Analytics data shared with Google through the Data Sharing Settings. Limited control over data More control over data retention and handling
Data Reporting API Provides programmatic methods to access report data. Core Reporting API Enhanced Measurement API
Data Analysis Tools Tools that have unique abilities for managing, visualizing, integrating, storing, sharing, and presenting data. Limited Improved data exploration and analysis tools
Data Visualization Allows data view in an interactive, customizable, and shareable dashboard. Standard charts Enhanced data visualization with Google Data Studio

Integrating GTM in Drupal

  1. Install the GTM module.
  2. Enable the module and click on the Configure button.
GTM module in Drupal

3. Click on the containers tab to add a new container.

Containers tab in Drupal

4. Label the container and add a container ID. You can find the container ID in GTM.

Adding a container

5. Find a container ID starting with GTM-XXXXX, copy the ID, paste it into the container ID input field in Drupal (step 4), and click Save to integrate the tag manager with your Drupal site.

Finding the container ID in GTM

Integrating GA4 in Drupal

  1. Install and enable the GA module.
  2. Go to the GA configuration page on Drupal by typing admin/config/services/google-analytics to add a property ID.
  3. To get the property ID, go to the GA account and search for measurement ID. Copy and paste it in the Web Property field and save the configuration.
Property ID of GA account

4. Connect Tag Manager with Google Analytics. Find out how to do it here.

Integrating GA reports module in Drupal

After integrating GTM with GA to enable tracking and report generation, we can display the data directly on the Drupal site using the Google Analytics Reports module.

  1. Install the module and enable it.
  2. Create a new project in Google Developers Console to access the data from Google Analytics.
  3. Go to Google Cloud and click on the Enabled API’s and services tab.
Google Cloud APIs

4. Enable Google Analytics Data API.

Analytics Data API

5. Go to credentials and create a Service account. Fill up all the details, like service account name, account ID, etc. Skip the optional fields and click on Save.

6. Click on the created service account, find a KEYS tab on the top, and click on it. Then click on ADD KEY → Create a new key → JSON type and → Create to download a JSON file.

7. Go to the Google Analytics reports module config page on Drupal - admin/config/services/google-analytics-reports-api,  and upload the downloaded JSON file, and add a property ID. Search for the Property ID in Google Analytics and paste it into the GA reports config. Save the configurations.

8. Go to the configurations page of GA reports and click on the import field to import the fields from Google Analytics. The GA reports module is now configured in the Drupal site.

9. To display the GA data, create a new view page, select Google Analytics in views settings, and click on the Save and Edit button. Add dimensions and metrics in field sections and save the view.

GA reports view
Page paths in GA

Resources

Set up and install Google Tag Manager

Configure Google Analytics 4 in Google Tag Manager

Summing up

Google Tag Manager and Google Analytics offer robust website tracking and analytics. With seamless integration in Drupal and easy configuration, businesses can access meaningful data analytics and insights to optimize experiences, operations, and performance.

Publish date
December 5, 2023
Last update
December 5, 2023
Written by
Artwork by
No art workers.
We'd love to talk about your business objectives