gem install eyestreet-analytics_goo
Newer usage pattern
Initially I made an adapter pattern thinking that we would support multiple analytics packages. So far I only need Google Analytics:
tracker = AnalyticsGoo::GoogleAnalyticsAdapter.new(:analytics_id => "MO-11685745-5", :domain => "shor.tswit.ch", :remote_address => "184.108.40.206", :user_agent => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6", :http_accept_language => "en-us,en;q=0.5") tracker.track_page_view("/testFoo/myPage.html")
The simple usage is the following:
tracker = AnalyticsGoo.config(:google_analytics, :analytics_id => "MO-11685745-5", :domain => "demo.eyestreet.com") tracker.track_page_view("/foo")
The first parameter passed to the config initializes the desired analytics adapter. Currently we only support Google Analytics. The subsequent hash provide a name for the account, the analytics id, and a domain.
In your environment.rb add the following:
config.gem "analytics_goo", :lib => "analytics_goo"
You can call things in the same way as above, or you can mix in some additional rails specific functionality that is shown below. In an intializer like config/initializers/analytics_goo.rb or in your appropriate environment.rb file
AnalyticsGoo.config(:google_analytics, :analytics_id => "MO-11685745-3", :domain => "demo.eyestreet.com", :rails_core_mixins => true, :environment => "production")
- analytics type - Currently we only support :google_analytics
The analytics option hash takes the following:
- :rails_core_mixins - Defaults to false. If set to true then you get an accessor method on rails core classes for analytics_goo
- :environment - The RAILS_ENV environment that the analytics code should be called in. In all other environments it is a noop.
Then in your models, controllers, and mailers you can do the following:
user = User.find(:first) user.analytics_goo.track_page_view("/found_my_first_user")
Check test/test_helper.rb to make sure you have the required gems installed.
rake test or autotest
Copyright (c) 2009 rwc9u, Eyestreet Software released under the MIT license