Community Documentation

Google Analytics: free advanced website statistics

Last updated January 21, 2013. Created by hass on November 15, 2005.
Edited by LinL, mradcliffe, c31ck, EvanDonovan. Log in to edit this page.

Google Analytics is Google's free statistics package, originally based on the Urchin system.

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 located at ?q=admin/settings/googleanalytics. It will then automatically add the required Javascript to the footer of every page generated by Drupal.

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

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.

Profile / User segmentation

Google Analytics provides a rough mechanism called "segmentation" to track your users based on data about their them.

For every page hit that is logged by Google, you can also attach the user roles to it. This can provide a good overview of what type of users visit what pages on your site.

If you've got the Core profile.module activated you'll find a list of all the profile fields which can be added to the tracking. This would allow you to track things like the gender of your users, the age group or their location!

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

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).

Original development of this module sponsored by Ixis IT.

About this page

Drupal version
Drupal 5.x, Drupal 6.x, Drupal 7.x
Audience
Site administrators

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here