创建使用GAPI浏览量和独立用户访问报告 [英] Create report with pageviews and unique visitors using GAPI

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

问题描述

我使用GAPI尝试创建我们的谷歌Analytics(分析)数据的简单报告。
我的内部客户希望看到一个总览,每页2场:浏览量和访问者。
我有浏览量部分工作,但我无法得到独立访问者的部分​​工作。
这是我目前的code。该过滤器将是他们可以改变一个参数,但很难codeD现在:

 要求'gapi.class.php';$ GA =新GAPI(ga_email,ga_password);$过滤器='PAGEPATH =〜^ / $家';
$ GA-> requestReportData(ga_profile_id,
                        阵列('PAGEPATH'),
                        阵列(浏览量),
                       浏览量,
                       $过滤器,
                       '2010-10-01',
                       '2010-10-31');

,然后一些code到显示结果在这里是不是真的有关。
至于说,该作品,但如果我加上'游客'的指标是这样的:

  $ GA-> requestReportData(ga_profile_id,
                       阵列('PAGEPATH'),
                       阵列(浏览量,访问者),
                       -pageviews',
                       $过滤器,
                      '2010-10-01',
                      '2010-10-31');

然后,我得到这个错误:

  PHP致命错误:未捕获的异常'异常'有消息'GAPI:无法申请报告的数据。错误:gapi.class.php'的维度和指标组合非法:218堆栈跟踪:
#0example.filter.php(24):gapi-> requestReportData('30296235',阵列,阵列,'-pageviews','PAGEPATH =〜^ /小时......','2010-10-01',' 2010-10-31)
#1主{}
抛出gapi.class.php线218


解决方案

在谷歌Analytics(分析)API限制什么组合它可以告诉你。具体来说,游客被严格限制,以什么度量它可以与使用(不要与访问次数混淆)。 游客小时是两个最严格限制的指标和维度你可以在谷歌Analytics(分析)查询。所以,你尝试过上面的组合是无效的,而谷歌拒绝计算它。只要将它切换到访问次数,它会工作。

注意在此有效组合页面,几乎所有的指标限制游客

这样做的原因可能是游客是更昂贵的计算,偶尔也无法计算,而且,说实话,不是特别有用。 游客访问次数的集合,但是受限于特定的Cookie设置,而一去就是一个特定的会话了游客。它也用处不大,因为游客不映射1:1的人。例如,我访问从Safari浏览器,Chrome浏览器和Firefox计算器在我的家庭和工作的电脑,以及从我的iPhone。 SO看见我的7游客!这不是追踪用户的有效途径。参观,由是在它所提供更多的限制,提供了更好的视野。

此外,由于是一个游客跨越多个会话,你不能完全拥有 PAGEPATH 他们。

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');

Then I get this error:

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

解决方案

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.

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.

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

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

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