我正在尝试使用 Google Analytics Reporting API v4 构建多折线图。
一张图表,其中我按每天的 session 计数为每个设备(台式机/平板电脑/移动设备)设置了一条线。
但现在我能得到的是:
我的代码是:
<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>
最佳答案
基于这个问题的答案 - 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>
就是这样:
关于google-analytics - 使用 Google Analytics Reporting API v4 构 build 备类别图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41984919/