Drupal 8 Google Analytics

Posted onby admin

Even though installing Google Tag Manager (GTM) adds a layer of complexity, it is far more flexible (and powerful) than Google Analytics (GA) alone:

  • GTM can be set up to track advanced analytics, like Scroll Depth, Link Clicks, & Video Playback information.
  • GTM makes it easy to install custom tracking, like LinkedIn Insights or Facebook Pixel, without developer help.
  • GTM makes it easier to track transaction data, like order amount, which is essential for ROI calculations for your ad campaigns.

Google Analytics is one of the essential modules to have for any website, see: Building Drupal 8 Website From Scratch - Part 3, Essential Modules (Pathauto, Google Analytics, Disqus) I have been using Google Analytics to track my website performances more than 10 years ago, and without it, I would be like blind. In this tutorial, I will take you through the process of setting up Google Analytics on Drupal 8 website. While embedding Google Analytics on a standard website is a pretty straight-forward process, things could get a bit complicated in the case of a feature-rich CMS Drupal. Here is the list of steps involved in the process. Understand integrated analytics conceptually and get concrete implementation ideas. Learn the fundamental concepts behind the Drupal 8 Statistics API Concrete API implementation details Get updated on API completion and ways to contribute, both big and small. The Drupal Google Analytics Module supports Drupal 8 as well as Drupal 9 websites. With Drupal analytics, you can track single and multiple domains. You can easily select the web pages or user roles you want to track.

While not difficult, it does take a little time and effort to complete. Below are the steps Volacci goes through to do a Google Tag Manager install on all our clients’ Drupal websites.

Except in very special cases, you do not want to have both the Google Analytics and Google Tag Manager modules (or embedded code snippets) enabled on your site at the same time -- it can skew your Analytics. We recommend coordinating the Google Tag Manager installation & configuration with disabling your Google Analytics module. Contact your developer if you have questions on how Google Analytics is currently installed on your website -- or if you have multiple GA codes deployed, which can complicate things further.

Google Account Sign Ups

While we offer top level instructions in this section, you may need to find additional resources on the exact steps for signing up for these accounts. Google tends to change things periodically, so it’s best to find their step by step instructions. We've included links to their current instructions in this section.

  1. If you don’t already have one, sign up for a free Google Account.
    This will include a gmail account. If your company already uses Gmail for email, then you can use that Google Account. You’ll use this account for all the sign ups that follow.
  2. Sign up forGoogle Analytics for your website. When you complete this process, you will have created a property for your website on the GA admin Tracking Info > Tracking Code page. There will be a tracking code there that looks something like this:
    We recommend opening a text editor and copying and pasting this tracking ID so you have it handy for your GTM set up. You’ll be using this text document again later, so leave it open.
  3. Create a Google Search Console (GSC) account for your website. This account will track organic (search) traffic to your website and can also be integrated into your Google Analytics (GA) account.
    For information on integrating GSC into your GA account, go here for their detailed instructions.
  4. Set up your website’s Google Tag Manageraccount.
  5. Fill out the Account Name and Container name fields with your organization’s and website’s information, and select “Web” under Target platform.
  6. Click Create, agree to the terms of service and GDPR rules, and you should be presented with a pop up window containing two different code snippets. The top one will look like this:
  7. Highlight the GTM-XXXXXXX number as we have in the example above.
  8. Copy and paste that number into the same text editor you placed your Google Analytics tracking ID.
  9. Deploy Google Analytics using Google Tag Manager by following Google's instructions. NOTE: You’ll need the UA-XXXXXXX-1 number you pasted into your text document for this step.
  10. Submit your XML Sitemap to Google by following Google's instructions.
Drupal 8 Google AnalyticsAnalytics

Install The Google Tag Manager Module

You may need to get help from your developer with this process. Contact them should you have any questions or issues. Sending along a link to this page could help speed things up.

  1. Make a backup of your website. If something goes wrong, you’ll need to restore your website from a backup.
  2. Install the Google Tag Manager module available here: https://www.drupal.org/project/google_tag
    NOTE: Drupal module installation instructions can be found here: https://www.drupal.org/docs/extending-drupal/installing-modules
  3. Once the module is installed, make sure it’s enabled by going to the Extend page of your website: Click Manage > Extend or visit https://yourdrupalwebsite.com/admin/modules.
    Note: if you are using Drupal 7, you may need to consult the D7 specific instructions.

  4. In the search box, enter “google tag” to find the Google Tag Manager module.
    • If the check box next to the module is checked, then the module has been enabled and is ready for configuration. Move on to Configure The Google Tag Manager Module.
    • If the check box next to the module is not checked, it will need to be enabled.

      If you have permissions to enable a module, you can select the check box next to the module, and click the Install button at the bottom of the page.

      NOTE: If you do not have permissions to enable the module, you’ll need to contact your web developer to enable it and give you the appropriate permissions to install and configure the GTM module.

Configure The Google Tag Manager Module

Make sure you have that text document handy that contains the GTM container ID that was generated above.

Drupal 8 Google Analytics Opt Out

  1. On your Drupal site, go to Manage > Configuration > System > Google Tag Manager or visit http://<www.yourdrupalwebsite.com>/admin/config/system/google-tag in your browser.
    This will take you to the Google Tag Manager containers page.

  2. Click on the + Add container button. This will take you to the Add container page.
  3. Enter a relevant name in the Label field.
  4. In the Container ID field, enter the Container ID (GTM-XXXXXXX) you copied from Google Tag Manager.
  5. Leave all other settings at their default.
  6. Click the Save button at the bottom of the page.
Drupal 8 google analytics module

Testing Your Installation

We recommend testing to make sure your Google Tag Manager is properly installed and configured. Here at Volacci, we test in several different ways using the Chrome browser. If you use a different browser, some of these methods may not work.

  1. Go into the Google Tag Manager workspace for your website and follow Google's instructions for testing with Preview mode.
  2. Install Google Tag Assistant within your Chrome browser.
    For additional information on how to use Google Tag Assistant for testing and troubleshooting your Google product installations, visit Google's support page

There you have it. You should be all set to gather Google Analytics data and make deployment of 3rd party scripts to your website much easier.

We always try to make sure our posts are as accurate and up to date as possible. If you find something is wrong, or you have a question, please feel free to contact us with any questions or feedback you might have.

Drupal 8 Webform Google Analytics

And remember, Volacci stands ready to help you implement your Google Tag Manager and Google Analytics should you need us to.

Drupal 8 Google Analytics

Did you like this walkthrough? Please tell your friends about it!

Are you a Drupal website owner? Are you a content marketer? Are you a digital marketer or a Drupal developer? If your answer to any of these questions is true, then you might know how important it is to be able to keep track of the statistics of your websites. One tool that stands out and probably beats all others in terms of popularity when it comes to website analytics is Google Analytics.

The case for Google Analytics’ popularity stands even when you look at its usage amongst Drupal sites only. As is the case with most of Drupal’s extendable functionality, there’s a module for integration of Google Analytics with Drupal called simply Google Analytics, and when you check out the module’s usage statistics report, you’ll come to know that over 400,000 Drupal sites in total use Google Analytics.

While the popularity of Google Analytics in the Drupalsphere itself is a solid reason to use the tool for your website’s tracking and statistics, it isn’t the only one. Google’s tool itself is so vast and it holds so much of functionality that there are entire courses dedicated to learning Google Analytics itself on the web.

So now that we’ve established some pretty solid reasons to use Google Analytics for our Drupal sites, it might be good to know how using a module helps. The way the tool works is that it gives you a tracking code which you can put an on a web page to track it. This works well if you’ve got a site with few pages, but becomes a headache if you’ve got a complex site with a lot of pages. This is where the Google Analytics module comes to save you, as it only requires you to paste the tracking code in a single place and enables tracking of every page on your website - WIN!!

Now, let’s take a look at how you can integrate Google Analytics with Drupal, specifically Drupal 8.

Create or Login to Google Analytics Account

Google Analytics Costs

First, if you don’t already have a Google Analytics account, create one.

Basic Google Analytics

Enter the appropriate details. In website URL, enter the URL of the website you wish to track. After you are done, scroll down to the bottom and click the blue Get Tracking ID button. Accept the terms and services, after which you will be taken to the page in the screenshot below, containing your Tracking ID.

Install and Configure Google Analytics Module

Now, navigate to your Drupal 8 site and install the Google Analytics Module. After enabling the module, navigate to admin -> configuration -> Google Analytics. Here, you will see all the settings for the module. This is also where you will paste the tracking ID you got from the last step.

Drupal 8 Google Analytics

Paste the tracking code under the Web Property ID and you’ll be all set to start tracking your site. If you want to, you can also set further settings like tracking specific domains, blacklisting specific pages etc.


That’s it! You should have successfully integrated Google Analytics with your Drupal site if you followed this tutorial correctly. For a tool that offers so much functionality, it truly is amazing how easy it is to integrate it to Drupal thanks to the amazing community behind it.