Google Analytics API 设备类别 [英] Google Analytics API deviceCategory

查看:29
本文介绍了Google Analytics API 设备类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Google Analytics API (v3) 在 Google Scripts 以拉取 设备类别来自 Google Analytics 的信息.

I am trying to use the Google Analytics API (v3) in Google Scripts to pull Device Category information from Google Analytics.

Audience 下的 Analytics 内 ->移动 ->概述 有一个 Device Category 部分列出了 'tablet'、'mobile' 和 'desktop'.我希望将这些数字提取到我的脚本所附的 Google 表格中.

Within Analytics under Audience -> Mobile -> Overview there is a Device Category section listing 'tablet', 'mobile' and 'desktop'. I wish to pull these numbers into a Google Sheet that my script is attached to.

我认为我应该使用的代码是:ga:deviceCategory==mobile(拉动移动流量)ga:deviceCategory==tablet 拉动平板电脑流量.

The code I believe I should be using is: ga:deviceCategory==mobile (to pull mobile traffic) and ga:deviceCategory==tablet to pull tablet traffic.

但是,我收到错误:

维度或指标无效:ga:deviceCategory==desktop

Invalid dimension or metric: ga:deviceCategory==desktop

我对此有些困惑,因为 Google 自己的文档说 deviceCategory 是一个有效的维度

I'm somewhat confused by this as Google's own documentation says that deviceCategory is a valid dimension

(https:///developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&group=platform_or_device&jump=ga_devicecategory)

如果我从末尾删除设备类型 ('ga:deviceCategory'),我会收到错误:

If I remove the device type from the end ('ga:deviceCategory') I get the error:

未知指标:ga:deviceCategory(第 43 行,文件代码")

Unknown metric(s): ga:deviceCategory (line 43, file "Code")

这让我相信我需要事先包含指标(我认为是浏览量").如果是这种情况,有人可以告诉我我是如何提取移动/平板电脑流量数据的吗?

This leads me to believe that I need to include the metric (which I believe is 'pageviews') beforehand. If this is the case, can someone show me how I pull in the figures for mobile/tablet traffic?

我在提取数据的其他方面没有其他问题.例如:

I am having no other issues pulling other aspects of my data. For example:

var impressions = Analytics.Data.Ga.get(tableId, startDate, endDate, 'ga:visits').rows.toString(); 

工作正常.

作为参考,这是我用于设备类别的完整代码:

For reference, this is the full code I am using for device Category:

  // Get Mobile Visits, this is the number of visits from mobile devices
  var mvisits = Analytics.Data.Ga.get(tableId, startDate, endDate, 'ga:deviceCategory==mobile').rows.toString();
      mvisits = mvisits;

我将不胜感激,如果您需要我的脚本中的更多代码,请告诉我.

I would be grateful for any assistance and please let me know if you require any more code from my script.

提前致谢.

推荐答案

我的应用程序脚本有点生疏,但您的问题是您的 == 维度字段只是您要选择的列.

My app script is a bit rusty but your problem is your == the dimension field is just a column you want to select.

var tableId  = 'ga:' + profileId;
var metric = 'ga:visits';
var options = {
    'dimensions': 'ga:deviceCategory',
    'filters': 'ga:deviceCategory==mobile'
    };
var report = Analytics.Data.Ga.get(tableId, startDate, endDate, metric,
  options);

您需要做的是添加一些过滤器.如果你把它想象成一个关系数据库,这就像是在说

What you need to do is add some filters instead. If you think of this like a relational database this would be like saying

select deviceCategory, visits
from tableId  
where devicecategory == mobile

请记住,您需要添加一个指标.

Remember you need to add a metric.

示例:无耻地从 分析服务页.

这篇关于Google Analytics API 设备类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆