Repository is archived
No commit activity in last 3 years
No release in over 3 years
Google Analytics for Ruby on Rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 5.0
 Project Readme

Google Analytics for Ruby on Rails

This gem helps with Google Analytics tracking. It supports Turbolinks 5.

Installation

Add this line to your application's Gemfile:

gem 'google_analytics_rails'

And then execute:

$ bundle

Add the following to your application.js file:

//= require google_analytics

Set GOOGLE_ANALYTICS_ID evironment variable.
You can add dotenv-rails gem to set it using .env file. The file should look like this:

GOOGLE_ANALYTICS_ID=UA-123456-1

If you don't want to use environment variable you can create initializer config/initializers/google_analytics_rails.rb containing:

GoogleAnalyticsRails.google_analytics_id = "YOUR GOOGLE ANALYTICS ID"

After that add this line to <head> in your layouts:

<%= google_analytics_meta_tag %>

Make sure you add it before stylesheet_link_tag and javascript_include_tag.
It will contain the meta tag with the ID you've set so it can be used from google_analytics.coffee file.

Contributing

If you find any bug or have an idea for improvement please create new PR or issue.

License

google_analytics_rails gem is available as open source under the terms of the MIT License.

Acknowledgments

Thanks to @reed for tutorials:
http://reed.github.io/turbolinks-compatibility/google_analytics.html
http://reed.github.io/turbolinks-compatibility/google_universal_analytics.html