LoginSignup
5
7

More than 5 years have passed since last update.

google-analytics-rails を使ってカスタムディメンション値などを送る方法

Posted at

railsgoogle-analytics-rails を使うと綺麗に GoogleAnalytics を導入できて便利。
ただ、カスタムディメンション値を渡したりする方法が若干わかりにくかったのでメモ。

カスタムディメンション値を設定する

カスタムディメンション を設定するためには二つ手順がある。

GoogleAnalyticsで設定

Rails側での設定

analytics_init を通して設定値を渡す。
例えば有料・無料みたいなユーザー属性を渡したいとしたら、以下のような感じで設定できる。

// GA::Events::SetCustomDimension.new(カスタムディメンションのインデックス値, 渡したい値)
= analytics_init(custom_vars: GA::Events::SetCustomDimension.new(1, current_user.type))

User ID値を設定する

複数の端末をまたいでセッションのグループを計測したい場合は
User ID - ウェブ トラッキング
 などの値を設定する必要があるのでこれの設定方法。

= analytics_init( setup: { userId: current_user.id } )

こんな感じでできる。

5
7
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
5
7