Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Google Analytics for Rails

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 config
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 garails.gemspec

Google Analytics for Rails

Complete package to use google analytics in your rails application. It supports recording to google analytics:

  • for normal web browsers (javascript)

  • for mobile handsets (gif)

  • programmatically (events)


Add to your Gemfile:

gem 'garails'

and run 'bundle install'.

Then create a config/initializers/garails.rb with the following content:

Garails.ga_account = 'UA-12345678-9'
# Garails.ga_cookie_domain = ''
# Garails.ga_hostname = ''


for normal web browsers

Add to your layout (usually app/views/layouts/application.html.erb) in the head section:

    <title>My App</title>
    <%= google_analytics_tracking_javascript %>

for mobile handsets (non-Javascript)

In your layout for mobile handsets without Javascript support, add at the very bottom of the body the following:

<%= utm_tag %>


In your view or controller you can record events by using:

ga_event(category, action, label, value)

See for details. label and value are optional.

Something went wrong with that request. Please try again.