 

Drupal・4 min read・Last update on December 5, 2023

# Setting up Google Tag Manager and Google Analytics in Drupal

 

 

 

 ![Setting up Google Tag Manager and Google Analytics in Drupal](/sites/default/files/remediation-media/656dc4e096b1d8224bc38f7b_image.avif) 

 



 

   Table of contents  - [Google Tag Manager (GTM)](#google-tag-manager-gtm)
- [Google Analytics (GA-4)](#google-analytics-ga-4)
- [Differences between GA-UA and GA-4](#differences-between-ga-ua-and-ga-4)
- [Integrating GTM in Drupal](#integrating-gtm-in-drupal)
- [Integrating GA4 in Drupal](#integrating-ga4-in-drupal)
- [Integrating GA reports module in Drupal](#integrating-ga-reports-module-in-drupal)
- [Resources](#resources)
- [Summing up](#summing-up)
 
  

 

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***](https://support.google.com/tagmanager/answer/3281060)) 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](/insights/introduction-to-google-tag-manager-gtm).

## 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-basedEvent-based**Reporting Model** Analyze and visualize data collected from websites or apps.Sessions and Pageviews-basedEvents and User-centric**Event Tracking** Captures all kinds of information about how people behave/interact on a site.LimitedAdvanced**User ID Tracking** A special reporting view that only displays data from sessions sent from unique ID to Analytics. Requires custom implementationNative support**Cross-device Tracking** Allows unification of separate sessions from the same user into one journey.LimitedEnhanced**Audience Creation** Audiences in Google Analytics are a group of users who perform similar actions.Using segmentsUsing custom dimensions and events**Integration** Is designed to work seamlessly with other Google solutions and partner products, saving time and increasing efficiency. LimitedEnhanced 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 featuresAdvanced ML capabilities for insights and predictions**E-commerce Tracking** Allows to track e-commerce websites.Standard e-commerce trackingEnhanced e-commerce trackingData Control: Allows to control how Google may use Analytics data shared with Google through the Data Sharing Settings.Limited control over dataMore control over data retention and handlingData Reporting API Provides programmatic methods to access report data.Core Reporting APIEnhanced Measurement API Data Analysis Tools Tools that have unique abilities for managing, visualizing, integrating, storing, sharing, and presenting data. LimitedImproved data exploration and analysis toolsData Visualization Allows data view in an interactive, customizable, and shareable dashboard.Standard chartsEnhanced data visualization with Google Data Studio

## Integrating GTM in Drupal

1. Install the GTM [module](https://www.drupal.org/project/google_tag).
2. Enable the module and click on the Configure button.

  ![GTM module in Drupal](/sites/default/files/c3-body-media/308945a146fe7c2302dce712.avif) 3\. Click on the containers tab to add a new container.

  ![Containers tab in Drupal](/sites/default/files/c3-body-media/bcde368f756d67f779201ad2.avif) 4\. Label the container and add a container ID. You can find the container ID in GTM.

  ![Adding a container](/sites/default/files/c3-body-media/44451b2a7cfe37d92f252263.avif) 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](/sites/default/files/c3-body-media/472e0e0ca07426b02bdf2484.avif) ## Integrating GA4 in Drupal

1. Install and enable the GA [module](https://www.drupal.org/project/google_analytics).
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](/sites/default/files/c3-body-media/e7aa5d8c0353c04626973da0.avif) 4\. Connect Tag Manager with Google Analytics. Find out how to do it [here](https://support.google.com/tagmanager/answer/9442095?hl=en).

## 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](https://www.drupal.org/project/google_analytics_reports).

1. Install the [module](https://www.drupal.org/project/google_analytics_reports/releases/4.0.0-alpha4) and enable it.
2. Create a new project in Google Developers Console to access the data from Google Analytics.
3. Go to [Google Cloud](https://console.cloud.google.com/) and click on the Enabled API’s and services tab.

  ![Google Cloud APIs](/sites/default/files/c3-body-media/f487da97bd26a382a51f0625.avif) 4\. Enable Google Analytics Data API.

  ![Analytics Data API](/sites/default/files/c3-body-media/cb10d5ba4ec32390440942f6.avif) 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](/sites/default/files/c3-body-media/f69f5942c42e79fc53876c3a.avif)   ![Page paths in GA](/sites/default/files/c3-body-media/d125431a625ac29170ea2845.avif) ### Resources

[**Set up and install Google Tag Manager**](https://support.google.com/tagmanager/answer/6103696?hl=en)

[**Configure Google Analytics 4 in Google Tag Manager**](https://support.google.com/tagmanager/answer/9442095?hl=en)

### 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.

 



Written by

Libbna Mathew

Full Stack Engineer

 

 

 

 

 

 

 ## We'd love to talk about your business objectives

 [ Contact Us  ](/contact)