Last updated 15 May 2015. Created on 15 November 2005.
Edited by pietpomp, courtneyjordan, hass, LinL. Log in to edit this page.

Google Analytics is Google's free statistics package, originally based off the Urchin Software.

For webmasters to make use of Google Analytics you would normally need to insert some Javascript containing the unique Google Analytics account number (in the format UA-XXXXXX-X) in to the header or footer of every page.

This could be achieved by editing the Drupal template page.tpl.php. However, this would then mean you cannot run multiple sites from the same base theme template.

This module allows you to enter your Google Analytics account number into the modules settings page. It will then automatically add the required Javascript to every page generated by Drupal.

The Drupal Google Analytics module is currently available from the module downloads.

Drush install fails with drush en google_analytics -y.

To install with Drush use:

drush dl google_analytics and then

drush en googleanalytics.
Note the underscore in the namespace.

Additional Features

The Drupal module also offers a bit more than basic tracking.

Page tracking

Allows you to provide a list of pages to track, or a list of pages not to track.

Role Tracking

Usually Google Analytics will track all users on a site, but you can also omit groups of users by Drupal role. Simply un-tick the role name on the settings page.

Link tracking

The module provides functionality to track downloads of files, mailto and outgoing links on your site. Select the relevant options on the main Google Analytics settings page. A textfield is also provided where you can specify a list of file extensions that should be tracked. Separate each file extension with a '|' character pdf|zip|doc or better leave the defaults.

To see the link tracking reports, go into your Google Analytics dashboard and click on the main Content menu item on the left. That should reveal the Event Tracking option.

Search and Adsense

Allows you to track internal search and track AdSense ads.

Custom variables

Allows you to send custom variables along with the Google Analytics tracking request. You can use node tokens to populate the value on pages that provide the node object.

Advanced Settings

Advanced settings for Google Analytics are hidden away in the collapsed fieldset. Expand it and you'll find the following additional features.

Cache tracking code

If you find your site pages load slow due to a delay in fetching the urchin.js/ga.js file from Google's servers - there's the option to cache the urchin.js/ga.js file locally on your server for 1 day. In order to use this feature your site must be configured to serve public files.

Custom code snippets

If you wish to inject additional custom Google Analytics JavaScript code snippets, two textareas is provided to add in code snippets. Just remember to remove the <script> ... </script> tags from the start and end of your snippet! The "before" textarea sets variables prior to the actual trackPageview, then the "after" handles variables, and additional actions (like tracking in multiple accounts).

Looking for support? Visit the forums, or join #drupal-support in IRC.