WoopraAnalytics

This module will easily enable Woopra Analytics support for your application. By default it’ll output the analytics code for every single page automatically, if it’s configured correctly.

If you want to disable the code insertion for particular pages, add the following to controllers that don’t want it:

skip_after_filter :add_woopra_analytics_code

If you are running rails 2.1 or above add install this by adding:

config.gem 'jonathannelson-woopra_analytics', :lib => 'jonathannelsoon/woopra_analytics', :source => 'http://gems.github.com'

and run:

rake gems:install

That’s it!

USING LOCAL COPIES OF THE WOOPRA ANALYTICS JAVASCRIPT FILES

Under certain circumstances you might find it valuable to serve a copy of the Analytics JavaScript directly from your server to your visitors, and not directly from Woopra. If your visitors are geographically very far from Woopra, or if they have low quality international bandwidth, the loading time for the Analytics JS might kill the user experience and force you to remove the valuable tracking code from your site.

This plugin now supports local copies Woopra JavaScript files, updated via a rake task and served courtesy of the Rails AssetTagHelper methods. So even if you use asset hosts, the JS will be served from the correct source and under the correct protocol (HTTP/HTTPS).

To enable cached copies and the following to your initialization code:

JonathanNelson::WoopraAnalytics.local_javascript = true

Use the following rake task to update the local copy of the JavaScript file:

rake woopra_analytics:updates

To keep the file updated you can add the following to your Capistrano configuration:

after "deploy:symlink", "deploy:woopra_analytics"

namespace :deploy do
  desc "Update local Woopra Analytics files"
  task :woopra_analytics, :role => :web do
    run "cd #{current_path} && rake woopra_analytics:update RAILS_ENV=#{ENV['RAILS_ENV']}"
  end
end

The above Capistrano recipe will almost certainly need some adjustments based on how you run your deployments, but you should get the idea.

OVERRIDE APPLICATION-WIDE VALUES

If you’re using one Rails application to serve pages across multiple domains, you may wish to override the domain and tracker ID values on a controller-by-controller or view-by-view basis. You can do this by setting the override_domain_name properties. These properties are automatically reset after each use, so the values you set for domain_name (usually in an initializer) will apply to all other requests.

before_filter :local_analytics

def local_analytics

JonathanNelson::WoopraAnalytics.override_domain_name  = 'foo.com'

end