playgroundで自由にgoogle analytics APIをとってきてみる


利用方法

記録方法

  • アプリだと、screenごとに記録すると、Exit, Avg. Time on Screen, Screen Views, Unique Screen Viewsの4つが記録される。
  • なので、基本はスクリーン単位で保存するのがよい
  • 分析しやすいように、custom dimentionとmetrixを多用するのはいい。絞り込んだりグルーピングしたいときは、dimentionに。ただ値を使いたいときはmetrixを使う。なにも考えないならdimention。

解析例

ある期間のあるsession数を知りたい

https://www.googleapis.com/analytics/v3/data/ga?ids=ga:****&metrics=ga:sessions&start-date=2014-09-01&end-date=2014-09-20
"rows": [
  [
    "1929"
  ]
]

日付ごとのsession数を知りたい

  • dimensionsという項目にga:dateを追加する
https://www.googleapis.com/analytics/v3/data/ga?ids=ga:****&metrics=ga:sessions&start-date=2014-09-11&end-date=2014-09-16&dimensions=ga:date
"rows": [
    [
      "20140911", 
      "2"
    ], 
    [
      "20140912", 
      "2"
    ], 
    [
      "20140913", 
      "2"
    ], 
    [
      "20140914", 
      "2"
    ], 
    [
      "20140915", 
      "1"
    ], 
    [
      "20140916", 
      "9"
    ], 
  ], 

イベントの取得の方法

  • ga:totalEvents, ga:uniqueEventsを取得する
https://www.googleapis.com/analytics/v3/data/ga?ids=ga:90975587&metrics=ga:totalEvents,ga:uniqueEvents&start-date=2014-09-11&end-date=2014-09-16&dimensions=ga:date
"rows": [
    [
      "20140911", 
      "38", 
      "3"
    ], 
    [
      "20140912", 
      "21", 
      "1"
    ], 
    [
      "20140913", 
      "37", 
      "3"
    ], 
    [
      "20140914", 
      "0", 
      "0"
    ], 
    [
      "20140915", 
      "8", 
      "1"
    ], 
    [
      "20140916", 
      "1072", 
      "11"
    ]
  ], 

イベントカテゴリで絞り込んで、eventActionごとに表示する

  • filterの説明はこちら https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters
  • filtersにeventCategoryを追加し、dimensionにga:eventActionを追加する
  • 例えば、Show Articleというカテゴリ名だったらeventCategory%3D%3DShow+Articleなる。eventCategory%3D%3DShow Articleのままでもいいかも。
  • 結果は、dimentionsの次にmetricsという流れで返ってくる
https://www.googleapis.com/analytics/v3/data/ga?ids=ga:90975587&metrics=ga:totalEvents,ga:uniqueEvents&start-date=2014-09-11&end-date=2014-09-16&dimensions=ga:date,ga:eventAction&filters=ga:eventCategory%3D%3DShow Article
[
      "20140911", 
      "16", 
      "1", 
      "1"
    ], 
    [
      "20140911", 
      "17", 
      "4", 
      "1"
    ], 
    [
      "20140912", 
      "100", 
      "1", 
      "1"
    ], 
    [
      "20140912", 
      "101", 
      "1", 
      "1"
    ], 
    [
      "20140912", 
      "102", 
      "1", 
      "1"
    ], 
]

使うメトリックスとディメンションの整理

  • 詳細はここ https://developers.google.com/analytics/devguides/reporting/core/dimsmets
  • dimentionはmetricsにも指定できる。
  • セッション。ga:sessions, ga:sessionDuration, ga:bounces, ga:bounceRate
  • トラフィックソース。ga:referralPath, ga:kayword
  • App Tracking。ga:screenviews, ga:timeOnScreen, ga:screenName, ga:screenDepth, ga:landingScreenName, ga:exitScreenName
  • Custom Variable。ga:dimmensionXX, ga:metrixXX
  • 日付。ga:date
  • イベント。ga:eventCategory, ga:eventAction, ga:eventLabel, ga:totalEvent, ga:uniqEvent

railsでgoogle analyticsのAPIを叩くには

その他の項目

  • max-resultsはデフォルトで1000。maxでは10000まで指定可能。