Skip to main content
Image
Google Analytics

Google Analytics in Drupal 8

Google Analytics is a very powerful tool from Google that allows us to monitor and analyze data from our website. Charts, real-time data, visits, locations, audience... are just some of the utilities that Google Analytics provides us, in addition, from a fully customizable and friendly modular panel.

With Drupal 8 we have included in the core the β€œ Statistics ” module, which can be useful in blogs or simple pages or those that do not require so many statistics. But when it comes to working on a larger project, we will fall short, and for this there is the Google Analytics module , which is currently with version 8.x.2.3 stable.

To begin, we will need to have composer in our project, which I explain how to obtain from the post Utilities for Drupal I. Once installed and ready, we will download the module with composer.

composer require drupal/google_analytics

Once downloaded, we will have to enable it in our Drupal 8. To do this we have two options:

  • Do it through the interface from Extend > Mark the β€œGoogle Analytics” module > Press the β€œInstall” button .
  • Do it using the drush tool, which I explain here how to install .

The command would be the following:

drush en -y google_analytics

Once enabled, we can access its settings from the administration interface in Configuration > System > Google Analytics .

The only configuration that we must edit will be the β€œWeb Property ID” which normally begins with β€œUA-XXXXX” . To obtain this code it is mandatory to register with Google and create a Property. The property will be the website which will be assigned the Web Property ID, that is, our website. Once we have registered our account and the property, Google will provide us with a tracking ID, which will be the one we must enter in our Drupal. When we save the configuration, Google Analytics will already track visits, active users, etc...

Tracking scope

The module also offers us the ability to configure the scope of the tracking, that is, to what extent Google Analytics will capture data (clicks, visits...) from our website.

  • Domains. We can indicate which domains Google Analytics will track.
  • Pages. We can add exceptions to pages that we do not want to be tracked.
  • Roles. We can assign tracking to a particular role or roles.
  • Users. Allows tracking/monitoring of users.
  • Links and downloads. Allows you to track files or download files through URLs
  • Messages. Allows you to track warning, error or status messages.
  • Search and Advertising. Allows you to track internal searches and Google Adsense ads.
  • Privacy. Allows you to hide the last octet of the tracked IPs. By default it is enabled.

Below we have 3 more settings:

  • Custom dimensions and Custom metrics: allows us to segment and measure specific information on our website. Google explains it in more detail here.
  • Advanced settings. They are the most customizable and advanced settings of the module. There is also the debug option.

So don't hesitate, take advantage of this powerful Google tool to get raw information from your website.

Tags

Join the Drupal Sapiens Community

Save content that interests you, connect with others in the community, contribute to win prizes and much more.

Login or create an account here

Latest posts

Featured

Last news