Step by Step guide to installing the Drupal module Google Analytics

The Google Analytics module for Drupal does exactly what you would expect… it lets you add the Analytics code to your site without having to get dirty in any code!

In addition to standard Google Analytics tracking this module lets you track users by profile fields & file downloads which can be really powerful.

The steps to get Google Analytics working are simple:

  1. Download the module and unzip the file into your /sites/all/modules or /sites/{yoursitename}/modules.
  2. Log into your drupal site with an account that has access to add modules.
  3. Go to Administer -> Modules (or just type in the url of admin/build/modules)
  4. Scroll down to the “Other” section and click on the “Enabled” checkbox next to Google Analyitcs.

Now make sure you have already signed up for a Google Analytics account and have your UA code ready.

To configure the module:

  1. Go to the administration section -> Site Configuration -> Google Analytics
  2. Enter in your UA number. If you don’t know where to get your UA user id: Log into Google Analytics, click on Edit to the right of the site profile you setup. Click on Check Status and then click on Legacy Tracking Code or New Tracking Code (both will give you the same UA id). Now just copy the UA-#####-# from the code and paste it into the corresponding textbox in your drupal setup. or
  3. Uncheck the “Legacy Google Analytics” checkbox since the legacy code is no longer updated.
  4. Select the roles that you would like to track. (I usually just check all of them) Note: This is different from prior versions. You must explicitly set what roles you want tracked. Note: Your roles may, and most likely will look different than this screenshot.
  5. If you wish to use User Segmentation, make sure you have the Profile Module enabled (it’s from core Drupal so there’s nothing additional to download) and select the fields you would like reported to Google Analytics. Remember, the more fields you add in the profile settings the more options you’ll have in this select list.
  6. If you want to track file types, add in the file extensions (without the dot) separated by pipes “|”.
  7. Click on Save configuration and everything should be setup!

To verify that the module is working:

  1. Go to any page that isn’t in the administration section since the Google Analytics module does not track /admin or it’s children.
  2. View the source
  3. Scroll to the bottom
  4. Look for some Javascript code that contains your UA id. If it’s there, than it was successful.

A note for themers, make sure your theme prints the $closure variable right before the </body> tag or else your Google Analytics code will never be output (it will also mess up some other modules).