LoginSignup
97
81

More than 5 years have passed since last update.

RailsアプリへのGoogleAnalyticsの導入手順

Last updated at Posted at 2015-07-01

導入自体はかなり簡単だったのでさっくりまとめ

手順

トラッキングID発行

  • http://www.google.com/intl/ja_jp/analytics/ にアクセス
  • Googleアカウントでログイン
  • 申し込みフォームがあるので申し込み
    • WebアプリのURLや名前を埋めて申し込む。
    • 既にサイトを作ってデプロイしておく必要がある。
  • トラッキングIDが発行される。これをWebアプリに埋め込むことでGoogle Analyticsが動作する。

タグ埋め込み

gem 'google-analytics-rails'
  • トラッキングIDを設定値に記載する。
config/environments/production.rb
# トラッキングIDを記載
GA.tracker = "UA-xxxxxx-x"
  • application.html.hamlのhead内にタグ挿入処理を記載する。
app/views/layout/application.html.haml
    = analytics_init if Rails.env.production?
  • (※erb利用の場合はこちら↓)
app/views/layout/application.html.erb
    <%= analytics_init if Rails.env.production? %>
  • デプロイしてできあがり!

動作確認

  • トラッキング組み込み確認
    • Google Analyticsの「アナリティクス設定」の「トラッキング情報」にステータスが表示されるが、そこがステータス: トラッキングがインストールされていますになっていれば設置完了。
  • レポート確認
    • GoogleAnalyticsの「レポート」から状況が確認できる。「リアルタイム」のレポートはアクセス内容がほぼ即時反映されるので、サイトにアクセス後このレポートにアクセス結果が反映されればOK。
97
81
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
97
81