2017-02-01 16 views
2

GoogleアナリティクスレポートAPI v4で複数の折れ線グラフを作成しようとしています。GoogleアナリティクスレポートAPI v4でデバイスカテゴリチャートを作成

各デバイス(デスクトップ/タブレット/モバイル)の行が1日ごとにセッションごとに表示されているグラフ。

しかし、今のところ、私は得ることができるすべてはこれです:

enter image description here

そして、私のコードは次のとおりです。この質問の回答に基づいて

<div id="chart-1-container"></div> 

<script> 
gapi.analytics.ready(function() { 
    var dataChart1 = new gapi.analytics.googleCharts.DataChart({ 
     query: { 
      'ids': 'ga:XX', // <-- Replace with the ids value for your view. 
      'start-date': '7daysAgo', 
      'end-date': 'yesterday', 
      'metrics': 'ga:sessions', 
      'dimensions': 'ga:deviceCategory' 
     }, 
     chart: { 
      'container': 'chart-1-container', 
      'type': 'LINE', 
      'options': { 
       'width': '100%' 
      } 
     } 
    }); 
    dataChart1.execute(); 
}); 
</script> 
+0

[移行ガイド](https://developers.google.com/analytics/devguides/reporting/core/v4/migration)に示されているように、V4を使用して例を確認して、より複雑なセグメント定義を以下を含む 'segments'フィールドを使用します。 [動的セグメント](https://developers.google.com/analytics/devguides/reporting/core/v4/migration#segments)オブジェクト。この例に示すように、セグメント内の条件とシーケンスを組み合わせることができます。希望が助けてくれる! – Teyam

+0

こんにちは、ありがとう。私はそれをチェックしたが、質問を解決する方法を見つけられなかった:( – Patrick

答えて

1

からGoogle Analytics API deviceCategory - 私は最終的に問題を発見。

モバイルなどのカテゴリに基づいて特定のチャートを取得するには、データがビルド私が達成しようとしていたような寸法上のフィルタではなくに基づいている:

<div id="chart-1-container"></div> 

<script> 
    gapi.analytics.ready(function() { 
     var dataChart1 = new gapi.analytics.googleCharts.DataChart({ 
      query: { 
       'ids': 'ga:XX', // <-- Replace with the ids value for your view. 
       'start-date': '7daysAgo', 
       'end-date': 'yesterday', 
       'metrics': 'ga:sessions', 
       'dimensions': 'ga:date', 
       'filters': 'ga:deviceCategory==mobile' // <-- Filter the category here 
      }, 
      chart: { 
       'container': 'chart-1-container', 
       'type': 'LINE', 
       'options': { 
        'width': '100%' 
       } 
      } 
     }); 

     dataChart1.execute(); 

    }); 
</script> 

そして、それはそれだ:

enter image description here

関連する問題