使用 Google Analytics Reporting API v4 构建设备类别图表
Build a device category chart with Google Analytics Reporting API v4
我正在尝试使用 Google Analytics Reporting API v4.
构建多折线图
一张图表,其中我为每个设备 (Desktop/Tablet/Mobile) 按每天的会话数划分了一条线。
但是现在我能得到的只有这个:
我的代码是:
<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>
根据这个问题的回答--我终于找到问题了
要获得基于类别(如移动设备)的特定图表,数据是基于过滤器而不是像我试图实现的维度那样构建的:
<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 Reporting API v4.
构建多折线图一张图表,其中我为每个设备 (Desktop/Tablet/Mobile) 按每天的会话数划分了一条线。
但是现在我能得到的只有这个:
我的代码是:
<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>
根据这个问题的回答-
要获得基于类别(如移动设备)的特定图表,数据是基于过滤器而不是像我试图实现的维度那样构建的:
<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>
就是这样: