LoginSignup
17
18

More than 5 years have passed since last update.

railsでGoogle Analyticsを使う方法

Last updated at Posted at 2013-11-13

Gemfileに'google-analytics-rails'を追加

gem 'google-analytics-rails'

GA.trackerを初期化

google analyticsに登録して"UA-xxxxxx-x"みたいなのが見れたら、以下のように初期化する。

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

headでanalytics_init

%head
  = analytics_init if GA.tracker != GoogleAnalytics::PLACEHOLDER_TRACKER

初期化されてる場合だけ有効にできる。

なんとこれだけで使えるようになる。

17
18
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
17
18