Drupal 8 Google Analytics & Google Analytics Report

In today’s world, when every business(e-commerce site, blogs, etc) is having its online presence, it’s always a good idea to give special attention to the site visitors/customers. In order to do that we need some stats that give us details of visitors activity on our site.

Google Analytics is one of the most popular analytics systems that provide the statics and in-depth details of the site visitors, using that we can give a better experience to site visitors.

The most common feature provided by Google Analytics are :

  • Most trending/visited pages
  • Top searched keywords
  • Number of active users
  • Most active traffic in the day
  • Top devices to be used for your sites and many more feature.

To achieve this feature in Drupal 8, we use Google Analytics Module, which provides all the functionalities mentioned above ootb.

Download and enable the module.

Navigate to “/admin/config/system/google-analytics“.

Admin UI for google analytics

In order to allow GA to monitor the site activities, we have to create one google analytics account by visiting Google Analytics and register our site to get the “Web property Id” as stated in the screenshot under “general settings.

There are a few steps to be performed to configure our site with Google Analytics.

These steps are defined in readme.txt of Google Analytics Report module, that we will discuss later.

In the above screenshot, lots of settings can be configured as per our requirement.

Below is a brief description of the settings.

  1.  Domain: Single, multiple or multiple top-level domains.
  2. Pages: Add specific pages to tracking.
  3. Roles: Which users roles to be tracked.
  4. Users: Allow users to customize tracking on their account page.
  5. Links and downloads: Provide file extensions to be tracked, inbound, outbound mail tracking.
  6. Messages: Track message of type- status, warning, error.
  7. Search and Advertising: Track internal search, track Adsense(in enabled).
  8. Privacy: Track anonymize visitors IP address.


Custom Dimensions and Custom Matrices: A very good document is provided to understand dimension and matrices are here

Advanced Settings: Provide the option to put custom javascript code(if any).

Once everything is configured from both end Drupal and google account, visit the google analytics site

Login into the account and the see the stats.

There are so many options available to change the view of the analytics page by creating your own custom dashboards.

Google Analytics Reports

In case if we want to get all the reports of the Google Analytics inside Drupal, we can use Google Analytics Reports module.

This module provides the GUI, where we can find the same reports, what we have seen in google analytics site.

This module comes up with Google Analytics Report API, which provides the flexibility to integrate this stats result with Drupal view and render them on our site as a page or a block.

In order to achieve this block/page, we have to create a view of type google analytics.

Note: Before working on the view, first we have to import all the available fields and filter from Google.To do that navigate to

“/admin/config/services/google-analytics-reports-api” and click on import field button.

This will import all the fields and filter using a batch process.

Now we have all the fields and view from Google analytics report API module, we can create a page or block as per our requirements and place it on our site.


Using these two modules we can create custom reports related to activities on our sites like pages/keywords search, what kind of users are coming to our site and what is the average time a user spent on the site, at what time the traffic is more.

In this blog, I tried to give a brief overview of Google Analytics, Google Analytics Report module. There is one more module come up with GA Reports module Google Analytics Report API, which provides the API to create custom reports using Google API.

By using such reports we can analyze the user behavior and take appropriate actions to improve the user experience and site performance.




About The Author