使用 GAPI 创建包含综合浏览量和唯一身份访问者的报告 [英] Create report with pageviews and unique visitors using GAPI

查看:46
本文介绍了使用 GAPI 创建包含综合浏览量和唯一身份访问者的报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GAPI 尝试根据我们的 Google Analytics(分析)数据创建简单的报告.我的内部客户希望查看每页包含 2 个字段的概览:综合浏览量和唯一身份访问者.我有网页浏览部分工作,但我无法让唯一身份访问者部分工作.这是我目前的代码.过滤器将是他们可以更改的参数,但目前是硬编码的:

I'm using GAPI to try and create simple reports from our Google Analytics data. My internal customer would like to see an overview with 2 fields per page: pageviews and unique visitors. I have the pageviews part working, but I cannot get the unique visitors part to work. This is my current code. The filter would be a parameter they can change, but is hardcoded for now:

require 'gapi.class.php';

$ga = new gapi(ga_email,ga_password);

$filter = 'pagepath =~ ^/home$';
$ga->requestReportData(ga_profile_id,
                        array('pagepath'),
                        array('pageviews'),
                       'pageviews',
                       $filter,
                       '2010-10-01',
                       '2010-10-31');

然后是一些代码来显示这里并不真正相关的结果.如上所述,这是可行的,但如果我像这样将访客"添加到指标中:

and then some code to show the results which is not really relevant here. As said, that works, but if I add 'visitors' to the metric like this:

$ga->requestReportData(ga_profile_id,
                       array('pagepath'),
                       array('pageviews','visitors'),
                       '-pageviews',
                       $filter,
                      '2010-10-01',
                      '2010-10-31');

然后我得到这个错误:

PHP Fatal error:  Uncaught exception 'Exception' with message 'GAPI: Failed to request report data. Error: "Illegal combination of dimensions and metrics"' in gapi.class.php:218

Stack trace:
#0example.filter.php(24): gapi->requestReportData('30296235', Array, Array, '-pageviews', 'pagepath =~ ^/h...', '2010-10-01', '2010-10-31')
#1 {main}
thrown in gapi.class.php on line 218

推荐答案

Google Analytics API 限制了它可以向您显示的组合.具体来说,visitors(不要与 visits 混淆)在它可以使用的指标方面受到严格限制.visitorshour 是您可以在 Google Analytics 中查询的两个最严格的指标和维度.因此,您尝试的上述组合无效,Google 拒绝对其进行计算.只需将其切换到 visits,它就会起作用.

The Google Analytics API restricts what combinations it can show you. Specifically, visitors (not to be confused with visits) is heavily restricted as to what metrics it can be used with. visitors and hour are the two most heavily restricted metrics and dimensions you can query in Google Analytics. So, the above combination you tried is invalid, and Google refuses to compute it. Just switch it to visits, and it'll work.

有效组合页面上的通知,几乎所有指标限制访问者.

Notice on this valid combinations page, almost all of the metrics restrict visitors.

这样做的原因可能是 visitors 的计算成本要高得多,有时无法计算,而且说实话,并不是特别有用.visitorvisits 的集合,但受限于特定的 cookie 集,而访问只是访问者的一个特定会话.它也不太有用,因为 visitors 不会将 1:1 映射到人.例如,我从家庭和工作计算机上的 Safari、Chrome 和 Firefox 以及 iPhone 访问 StackOverflow.所以将我视为 7 个访客!这不是跟踪用户的有用方法.访问通过限制提供的内容提供更好的视图.

The reason for this is likely that visitors is much more computationally expensive, occasionally impossible to compute, and, to be honest, not particularly useful. visitor is aggregate of visits, but constrained to a particular cookie set, whereas a visit is just one particular session for a visitor. It's also less useful, since visitors does not map 1:1 to people. For example, I access StackOverflow from Safari, Chrome, and Firefox on my home and work computers, as well as from my iPhone. SO sees me as 7 visitors! It's not a useful way of tracking users. Visit, by being more limited in what it offers, provides a better view.

此外,由于访问者跨越多个会话,因此您不能完全为他们设置 pagePath.

Also, since being a visitor spans multiple sessions, you can't quite have a pagePath for them.

这篇关于使用 GAPI 创建包含综合浏览量和唯一身份访问者的报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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