很抱歉,这个话题复活了,但是我也有同样的疑问。
我使用的是gapi,目前“ 2013年10月23日”,谷歌更改了如何获取数据。我无法获得全部访问。
我只需要访问我的网站的总次数,仅此而已。
这是我正在使用的代码:
<?php
define('ga_email','[email protected]');
define('ga_password','password');
define('ga_profile_id','999999');
require 'gapi.class.php';
$ga = new gapi(ga_email,ga_password);
$ga->requestReportData(ga_profile_id,
array('browser','browserVersion'),
array('pageviews','visitors')
);
?>
<table>
<tr>
<th>Browser & Browser Version</th>
<th>Pageviews</th>
</tr>
<?php
foreach($ga->getResults() as $result):
?>
<tr>
<td><?php echo $result ?></td>
<td><?php echo $result->getPageviews() ?></td>
<td><?php echo "Visitors: ".$result->getVisitors() ?></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->getVisitors() ?></td>
</tr>
<tr>
<th>Results Updated</th>
<td><?php echo $ga->getUpdated() ?></td>
</tr>
</table>}
有人可以帮我举个例子吗?
谢谢
参考方案
你的foreach错了
<?php
....
foreach($ga->getResults() as $result):
?>
必须是这样的:
<?php
....
foreach($ga->getResults() as $result) {
?>
<tr>
<td><?php echo $result ?></td>
<td><?php echo $result->getPageviews() ?></td>
<td><?php echo "Visitors: ".$result->getVisitors() ?></td>
</tr>
<?php
}
?>
你会得到什么:
<?php
....
$ga->requestReportData(
ga_profile_id,
array('browser'),
array('pageviews','visits'),
array('-visits'),
null,
'2013-05-01',
null,
1,
30
);
?>
<table>
<tr>
<th>Total Pageviews</th>
<td><?php echo $ga->getPageviews() ?>
</tr>
<tr>
<th>Total Visits</th>
<td><?php echo $ga->getVisits() ?></td>
</tr>
</table>
php Singleton类实例将在多个会话中保留吗? - php举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…
PHP PDO组按列名称查询结果 - php以下PDO查询返回以下结果:$db = new PDO('....'); $sth = $db->prepare('SELECT ...'); 结果如下: name curso ABC stack CDE stack FGH stack IJK stack LMN overflow OPQ overflow RS…
验证IBAN PHP - php在设计新平台时,我们尝试集成IBAN编号。我们必须确保IBAN已经过验证,并且存储在数据库中的IBAN始终正确。那么验证数字的正确方法是什么? 参考方案 正如我在其他问题中解释的逻辑一样,我尝试自己创建一个函数。根据Wikipedia文章中解释的逻辑,在下面找到合适的功能。国家特定验证。它适合吗http://en.wikipedia.org/wiki/Int…
通过>和<运算符比较日期 - php在我的所有php代码中,我都在UTC中存储日期和时间,但是我也在使用mysql存储日期时间(也在utc中)。大于和小于运算符会导致日期比较失败吗? $curdate=date('Y-m-d H:i:s'); if($start_datetime>$curdate) 参考方案 不。他们没有办法失败。为此,特意制作了MySQL日期格式。…
我如何在Safari浏览器中支持<video>? - php我想在野生动物园浏览器中显示视频,当我刷新浏览器时,什么也没有发生,该怎么办?这是我的代码:<!doctype html> <html> <head> <title>Simple Movie Player</title> </head> <body> <video sr…