2017-02-01 82 views
2

我正在嘗試使用Google Analytics Reporting API v4構建多行圖表。使用Google Analytics Reporting API v4構建設備類別圖表

一個圖表,其中每個設備(桌面/平板電腦/手機)的會話計數按天排列。

但是現在我能得到的是這樣的:

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

您可能想檢查使用V4的示例,如[遷移指南](https://developers.google.com/analytics/devguides/reporting/core/v4/migration)中所示,以表達更復雜的段定義使用包含的'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

相關問題