This is a companion piece to the Google Analytics module.

Google Analytics is a free service that tracks users, demographic, and statistical data. On a typical site it is easy to set up --especially in Drupal using the Google Analytics module. Under a typical set-up Google Analytics tracks a user as he/she navigates from page to page within a site. This is fine for a typical site where every action on a site requires a new page view. What if, however, the site owner wanted to track how a user is using the ajax form built into views or some other custom ajax event. Google Analytics has a control for this called Event Tracking.

Event Tracking is a way to track user interaction with out registering a page view. Using Google Maps as an example site, event tracking would allow the user to track Zoom, Drag, and View Change events without contaminating the page view statistic.

This module allows an interface for Google Analytics event tracking capabilities. It provides a hook for other modules or "glue code" and also has some handy drush commands.

I will be refering to the example module that is included with Google Analytics Event Tracking.

Steps to Making Google Analytics Event Tracking To Work

First, write a module that implements hook_google_analytics_et_api() -- this can most easily be done by copying (and renaming) the example module that is included with Google Analytics Event Tracking.
Second, edit the array that is returned by the example's hook_google_analytics_et_api() implementation.

23   $selectors = array(
  24     array(
  25       'event' => 'mousedown',
  26       'selector' => '#main-menu li a',
  27       'category' => 'main navigation',
  28       'action' => 'click',
  29       'label' => '!text',
  30       'value' => 0,
  31       'noninteraction' => TRUE,
  32     ),

You will notice that the hook returns a multi-dimensional array (an array of arrays). Each of the arrays has the same structure:
  • event
  • selector
  • category
  • action
  • label
  • value
  • noninteration

This should be somewhat self-explanatory, however I will go through them now.

event
The jQuery event that triggers the event.
selector
A CSS Selector that the event is bound to.
action
This is more for internal book keeping. An arbitrary string that will help organize the events in Google Analytics.
label
This is more for internal book keeping. An arbitrary string that will help organize the events in Google Analytics.
value
Helps determine what the worth of an event is; for internal use (usually zero). An arbitrary integer that will help organize the events in Google Analytics.
noninteraction
Should this event be counted towards the sites overall bounce rate.

There are several tokens that can be used as a string replacement with category, action, and label.

!text
This is what would be returned from the jQuery .text() method.
!href
The value of the href attribute (handy with anchor tags).
!currentPage
The URL of the current page (this is taken with the code window.location.href

There is one more bit that is handy when configuring the module.
Passing !test will send an alert to the page when the event is triggered and not send the event to Google Analytics.

Notes

Remember to flush Drupals cache every time a change is made to the implementation.

Drupal 6 Version

The Drupal 6 version was created by a patch and will only be receiving security releases (or submitted patches)

Project Information

Downloads