LoginSignup
8
8

More than 5 years have passed since last update.

Ruby on rails にGoogle Analyticsを入れる

Last updated at Posted at 2014-05-19

簡単にrailsにGoogleAnalyticsを入れられます。

1. Gemfileに'google-analytics-rails'を追加する

gem 'google-analytics-rails'

2. トラッキングIDを設定する

config/initializers/google_analytics.rbを作成して、
以下のようにGoogleAnalyticsのトラッキングIDを設定する。

# config/initializers/google_analytics.rb
GA.tracker = "UA-xxxxxxxx-x"

3. 解析用のコードを埋める

以下で、本番環境向けにのみ解析コードを埋める事が出来ます。

# app/views/layouts/application.html.erb
# headタグの中
<%= analytics_init if Rails.env.production? %>
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8