Skip to content

Rails 3 helpers to manage google analytics tracking. Mostly intended for small to medium websites.

Notifications You must be signed in to change notification settings

kelvin22/google-analytics-rails

 
 

Repository files navigation

Fast Google Analytics setup for Rails 3. This gem is mostly intended for small to medium websites with a simple analytics strategy.

Installation

Add the following to your Gemfile:

gem 'google-analytics-rails'

Then run:

bundle install

Documentation

http://rubydoc.info/github/bgarret/google-analytics-rails

Example configurations

Production only

config/environments/production.rb:

# replace this with your tracker code
GA.tracker = "UA-xxxxxx-x"

app/views/layout/application.html.erb, in the <head> tag :

	<%= analytics_init if Rails.env.production? %>

With DoubleClick instead of vanilla Google Analytics script

config/environments/production.rb:

# replace this with your tracker code
GA.tracker = "UA-xxxxxx-x"
GA.source_script = "('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'"

app/views/layout/application.html.erb, in the <head> tag :

	<%= analytics_init if Rails.env.production? %>

Different accounts for development and production

config/environments/production.rb:

# replace this with your production tracker code
GA.tracker = "UA-xxxxxx-x"

config/environments/development.rb:

# replace this with your development tracker code
GA.tracker = "UA-xxxxxx-x"

app/views/layout/application.html.erb, in the <head> tag :

	<%= analytics_init :local => Rails.env.development? %>

License

google-analytics-rails is released under the MIT license:

Thanks

Many thanks to the people that took time to submit patches.

About

Rails 3 helpers to manage google analytics tracking. Mostly intended for small to medium websites.

Resources

Stars

Watchers

Forks

Packages

No packages published