任何人都知道如何使用GAPI从我的Google分析帐户中返回以下信息?
答案 0 :(得分:3)
您需要使用pagePath
维度和pageviews
指标。尝试以下内容:
<?php
require 'gapi.class.php';
$gaEmail = 'youremail@email.com';
$gaPassword = 'your password';
$profileId = 'your profile id';
$dimensions = array('pagePath');
$metrics = array('pageviews');
$sortMetric=null;
$filter=null;
$startDate='2011-02-01';
$endDate='2011-02-28';
$startIndex=1;
$maxResults=10000;
$ga = new gapi($gaEmail, $gaPassword);
$ga->requestReportData($profileId, $dimensions, $metrics, $sortMetric, $filter, $startDate, $endDate, $startIndex, $maxResults);
$totalPageviews = $ga->getPageviews();
foreach ($ga->getResults() as $result) {
$pageviews = $result->getPageviews();
$percentPageviews = round(($result->getPageviews()/$totalPageviews)*100,2);
print "$result:$pageviews:$percentPageviews\n";
}
?>