google-analytics - 使用 Google Analytics Reporting API v4 构 build 备类别图表

标签 google-analytics google-api google-reporting-api

我正在尝试使用 Google Analytics Reporting API v4 构建多折线图。

一张图表,其中我按每天的 session 计数为每个设备(台式机/平板电脑/移动设备)设置了一条线。

但现在我能得到的是:

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>

最佳答案

基于这个问题的答案 - 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

关于google-analytics - 使用 Google Analytics Reporting API v4 构 build 备类别图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41984919/

相关文章:

java - 谷歌分析报告 API v4 : get Sessions and Revenue data

javascript - 在 Google API 请求中使用 "filters"参数总是导致错误?

google-analytics - 是否有任何针对 VB6 的桌面应用程序使用跟踪系统?

google-api - 使用 StudentWorkFolder 创建类(class)工作

php - 通过 Google Analytics API 获取 AdSense 数据

javascript - 我可以将gapi.hangout.onair 命名空间用于常规的非直播/非播出的Google Hangouts 应用程序吗?

android - 无法从公共(public)谷歌日历 api v3 获取事件

angular - 如何更改默认的 `Page View` 名称

firebase - Firebase 分析如何工作?我应该引用什么文档?