kangguru/rack-google-analytics — pull request #36 by mbarnett (2013-12-12 17:46:59+00:00)
Title: Lambda-based tracking code support

We had a set of scenarios in which we wanted an application to be able dynamically specify the tracking code based on whatever business logic needed to govern it. This PR adds support for optionally passing a lambda that provides the tracking code at runtime based on the Rack environment.

With this change a site can define a tracker like

```ruby
config.middleware.use Rack::GoogleAnalytics, :tracker => lambda { |env|
return env[:site_ga].tracker if env[:site_ga]
}
```

and then vary the tracking code dynamically based on whatever logic it wants, a contrived example being:

```ruby
class WelcomeController < ApplicationController
def index
env[:site_ga] = OpenStruct.new(:tracker => "abc123")
end
end
```