Home > Projects > Google Analytics Plugin
This is a wee plugin for Ruby on Rails which will trivially allow you to integrate with Google Analytics. It simply adds the appropriate snippet into every one of your application's pages so that Google can track and analyse your web site's usage.
To install the Google Analytics plugin, add my plugin repository to your rails plugin sources:
script/plugin source http://svn.rubaidh.com/plugins/trunk
and to install the Google Analytics plugin:
script/plugin install google_analytics
To configure it, add the following to config/environment.rb:
Rubaidh::GoogleAnalytics.tracker_id = 'UA-12345-67'
Rubaidh::GoogleAnalytics.domain_name = 'example.com'
Rubaidh::GoogleAnalytics.environments = ['production']
where the tracker_id is what _uacct gets set to in the chunk of javascript that Google gives you to insert. domain_name is pushed into the _udn attribute in the Javascript -- you can leave it out if you don't need it set. The environment defaults just to production so you can also leave that out if you're happy that the Analytics code should only be inserted in a production environment. That's it! All configured! Your tracking information will be inserted into every page. If you don't want it in particular controller, you can do the usual to skip after_filters:
skip_after_filter :add_google_analytics_code
Simple, eh? The plugin will also automagically use the SSL version of the Analytics URL if you are serving an SSL page to avoid browsers warning users about a mixture of secure and insecure content.
If you have any feedback, comments or patches, please feel free to mail mathie@rubaidh.com. Enjoy!