How to Implement Google Analytics in Drupal

Posted: March 24, 2017 at 12:16 pm, Last Updated: August 29, 2017 at 2:51 pm

The most common way to implement Google Analytics in Drupal is by using the Drupal Google Analytics module. (Note that this Drupal module comes pre-installed on Drupal websites created by the Office of Communications and Marketing.)

This module provides an interface within your Drupal administration area which allows you to integrate the Google Analytics script in your website’s pages automatically, while providing a number of customization options.

Configuring the Drupal Google Analytics Module

Step 1: Access the Drupal Google Analytics Module

Step 2: Provide the Google Analytics Web Property ID

Provide the Google Analytics Web Property ID to which you would like the website to send its tracking data.

You can find the web property ID in your Google Analytics administration setting.

Step 3: Include Additional JavaScript Code to Implement Additional ‘Roll-Up’ Properties

You can include additional code in the “Additional JavaScript code (after tracker initialization)” field to also implement the George Mason University Google Analytics Roll-Up Property and, optionally, any department-level roll-up property for your department. The use of a department-level roll-up property is optional but highly recommended if your department is responsible for more than one website. Be sure to include the property ID for your department-level roll-up in place of the Xs in the code snippet below.

//Implement George Mason University Analytics Roll-Up Property
	ga('create', 'UA-1007599-1', 'auto', 'rollUp_Mason');
	ga('rollUp_Mason.send', 'pageview');

//Implement department-level roll-up
	ga('create', 'UA-XXXXXXXX-X', 'auto', 'rollUp_department');
	ga('rollUp_department.send', 'pageview');