Google AnalyticsAPI设备类别 [英] Google Analytics API deviceCategory
问题描述
我正尝试在 Google Analytics API (v3) href =https://developers.google.com/apps-script/ =nofollow> Google脚本将 Google设备类别信息。
在 Audience - >移动 - >概述
有一个设备类别
部分列表'平板电脑','移动'和'桌面'
。我希望将这些数字放到我的脚本所附带的Google表格中。
我相信我应该使用的代码是:
ga:deviceCategory == mobile(用于提取移动流量)
和 ga:deviceCategory == tablet
以吸引平板电脑流量。
但是,我收到错误:
$ b
无效的维度或指标:ga:deviceCategory ==桌面
我对此有些困惑,因为Google自己的文档显示deviceCategory是有效的维度
如果我从结尾删除设备类型('ga:deviceCategory'),则会出现错误:
$ b
未知指标:ga:deviceCategory(第43行,文件代码)
这导致我相信我需要预先包含指标(我相信它是'浏览量')。如果是这种情况,有人能告诉我我是如何拉动手机/平板电脑流量的数据的吗?
我没有其他问题拉动我的数据的其他方面。例如:
var impressions = Analytics.Data.Ga.get(tableId,startDate,endDate,'ga:visits') .rows.toString();
可以正常工作。
这是我用于设备类别的完整代码:
//获取移动访问次数,这是来自移动设备的访问次数设备
var mvisits = Analytics.Data.Ga.get(tableId,startDate,endDate,'ga:deviceCategory == mobile')。rows.toString();
mvisits = mvisits;
我将不胜感激任何帮助,请让我知道如果您需要更多代码。
预先感谢。
我的应用程序脚本是有点生疏,但你的问题是你的 ==
维度字段只是你想选择的一列。
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);
您需要做的是添加一些过滤器
代替。如果你认为这像一个关系数据库,这就像是说:
select deviceCategory,访问tableId $ b中的
$ b其中devicecategory == mobile
请记住,您需要添加一个指标。
示例:无耻地从分析服务页面。
I am trying to use the Google Analytics API (v3) in Google Scripts to pull Device Category information from Google Analytics.
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.
The code I believe I should be using is:
ga:deviceCategory==mobile (to pull mobile traffic)
and ga:deviceCategory==tablet
to pull tablet traffic.
However, I receive the error:
Invalid dimension or metric: ga:deviceCategory==desktop
I'm somewhat confused by this as Google's own documentation says that deviceCategory is a valid dimension
If I remove the device type from the end ('ga:deviceCategory') I get the error:
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();
works fine.
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.
Thanks in advance.
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.
Example: shamelessly ripped from Analytics service page.
这篇关于Google AnalyticsAPI设备类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!