获取gapi Object的内容

时间:2014-07-09 17:31:23

标签: php

我想通过GAPI提取一些Google Analytics数据。但是,我在array中的Object中获得了array。我不知道如何从中获取数据。

这是回复:

gapiReportEntry Object ( [metrics:gapiReportEntry:private] => Array ( [pageviews] => 102 [visits] => 79 [avgTimeOnSite] => 30.569620253165 [percentNewVisits] => 98.73417721519 [visitBounceRate] => 77.215189873418 [UniquePageviews] => 92 ) [dimensions:gapiReportEntry:private] => Array ( [browser] => Safari (in-app) ) ) 

这是我运行的代码:

define('ga_email','my_email');
define('ga_password','my_password');
define('ga_profile_id',$analyticsid);

require('Including/php/gapi-1.3/gapi.class.php');

$number = 0;

while($number < 3) {
    $date = date("Y-m-d",strtotime("-".$number." days"));

    $ga = new gapi(ga_email,ga_password);
    //$dimensions, $metrics, $sort_metric=null, $filter=null, $start_date=null, $end_date=null, $start_index=1, $max_results=30)
    $request = $ga->requestReportData(
        ga_profile_id,
        array('browser'),
        array('pageviews','visits','avgTimeOnSite','percentNewVisits','visitBounceRate','UniquePageviews',),
        array('-visits'), 
        null, 
        $date,
        $date,
        1,
        30
    );

    ${'data'.$number} = $request;

    $number++;

}

然后print_r($data0[0]);给了我这个结果。

1 个答案:

答案 0 :(得分:0)

使用Gapi.class.php,您应该使用$request->getVisits();获取访问权限,以及您将使用的网页浏览$request->getPageviews();等。