【发布时间】:2017-11-20 04:08:24
【问题描述】:
我正在为 Google Analytics API 使用 GAPI 类 (gapi.class.php)。
这是代码:
<?php
require 'gapi.class.php';
define('ga_profile_id', 'your profile id');
$ga = new gapi("XXXXXXXX@developer.gserviceaccount.com", "key.p12");
$filter = 'country == United States && browser == Firefox || browser == Chrome';
$ga->requestReportData(ga_profile_id, array('browser', 'browserVersion'), array('pageviews', 'visits'), '-visits', $filter);
?>
<table>
<tr>
<th>Browser & Browser Version</th>
<th>Pageviews</th>
<th>Visits</th>
</tr>
<?php
foreach($ga->getResults() as $result):
?>
<tr>
<td><?php echo $result ?></td>
<td><?php echo $result->getPageviews() ?></td>
<td><?php echo $result->getVisits() ?></td>
</tr>
<?php
endforeach
?>
</table>
<table>
<tr>
<th>Total Results</th>
<td><?php echo $ga->getTotalResults() ?></td>
</tr>
<tr>
<th>Total Pageviews</th>
<td><?php echo $ga->getPageviews() ?>
</tr>
<tr>
<th>Total Visits</th>
<td><?php echo $ga->getVisits() ?></td>
</tr>
<tr>
<th>Result Date Range</th>
<td><?php echo $ga->getStartDate() ?> to <?php echo $ga->getEndDate() ?></td>
</tr>
</table>
但我找不到如何更改日期范围。
默认情况下,它显示的是从 2014 年到今天的状态——我认为这是分析帐户的生命周期。
有一个类似的question,但它适用于旧版本,现在无法使用。
谢谢。
【问题讨论】:
标签: php google-analytics google-analytics-api