[英]Build a device category chart with Google Analytics Reporting API v4
I am trying to build a multiple line chart with Google Analytics Reporting API v4.我正在尝试使用 Google Analytics Reporting API v4 构建多折线图。
A chart where I have a line for each device (Desktop/Tablet/Mobile) by session count by day.一个图表,其中我按每天的会话计数为每个设备(台式机/平板电脑/移动设备)设置了一条线。
But for now all I can get is this:但现在我能得到的就是:
And my code is:我的代码是:
<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>
Based on the answer of this question - Google Analytics API deviceCategory - I finally found the problem.基于这个问题的答案 - Google Analytics API deviceCategory - 我终于找到了问题所在。
To get a specific chart based on a category like mobile, the data is build based on filters and not on dimensions like I was trying to achieve:要根据移动设备等类别获取特定图表,数据是基于过滤器而不是我试图实现的维度构建的:
<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>
And that's it:就是这样:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.