leehambley/rack-google-analytics — pull request #9 by smontgomerie (2012-07-10 21:01:40+00:00)
Title: Updated gem to include Custom Tracking Variables and Events

These commits add fully unit-tested code for adding custom variables and events to google analytics in async mode. Usage is described in the README.

Essentially it allows users to specify custom variables and events in their application controllers. It accomplishes this by adding instance methods to the ActionController::Base class. These methods store data in the environment to pass to rack, and write the variables when rendering the GA javascript tags.

The documentation for Google Analytics tracking requirements is detailed here:
https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables
https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

Open to discussion on code style. Particularly, I'm not sure I like this syntax:
```ruby
set_ga_custom_var(1, "LoggedIn", value, GoogleAnalytics::CustomVar::SESSION_LEVEL)
```
I might prefer to modify the method to take a hash:

```ruby
set_ga_custom_var( :slot => 1, :name => "LoggedIn", :value => value, :scope => GoogleAnalytics::CustomVar::SESSION_LEVEL)
```