Google Analytics PHP API(GAPI) - 获取页面浏览次数 [英] Google Analytics PHP API (GAPI) - Getting number of page views

查看:187
本文介绍了Google Analytics PHP API(GAPI) - 获取页面浏览次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在为此工作两天,似乎无处可寻。



我使用GAPI Google分析PHP类。这是我现在使用的当前代码:

  $ ga-> requestReportData([UID],array('天),数组(访问),数组(日)); 

我想要做的是从过去7天中获取综合浏览量的数量。因此,输出将如下所示:

 <?php foreach($ ga-> getResults()as $ result){ ?> 
日期:<?php echo $ result; ?>
页面浏览量:<?php echo $ result-> getPageviews(); ?>
<?php}?>

我是Google analytics API的新手,所以不确定从哪里开始。感谢您的帮助!

解决方案

这应该对您有所帮助

 <?php 
require'gapi.class.php';

$ gaEmail ='youremail@email.com';
$ gaPassword ='您的密码';
$ profileId ='您的个人资料ID';

$ dimensions = array('pagePath','country','region','city');
$ metrics = array('visits');
$ sortMetric = null;
$ filter = null;
$ startDate ='2011-02-01';
$ endDate ='2011-02-28';
$ startIndex = 1;
$ maxResults = 10000;

$ ga = new gapi($ gaEmail,$ gaPassword);
$ b $ ga-> requestReportData($ profileId,$ dimensions,$ metrics,$ sortMetric,$ filter,$ startDate,$ endDate,$ startIndex,$ maxResults);

$ totalPageviews = $ ga-> getPageviews();
$ b foreach($ ga-> getResults()as $ result){
$ visits = $ result-> getVists();
print $ visits;
}

?>

请记住关闭Google帐户的两步验证功能。如果您不这样做,即使您的帐户信息有效,它也会向您发出错误的请求错误。


been working on this for two days now and seem to be getting nowhere.

I am using the GAPI Google analytics PHP class. This is the current code I have the now:

$ga->requestReportData("[UID]",array('day'),array('visits'), array("day"));

What I want to do is get the number of "pageviews" from the "past 7 days". So output would be something like:

<?php foreach($ga->getResults() as $result) { ?>
    Date: <?php echo $result; ?>
    Page Views: <?php echo $result->getPageviews(); ?>
<?php } ?>

I am new to Google analytics API so not sure where to start. Thanks for any help!

解决方案

This should help you

   <?php
  require 'gapi.class.php';

 $gaEmail = 'youremail@email.com';
 $gaPassword = 'your password';
 $profileId = 'your profile id';

 $dimensions = array('pagePath','country', 'region', 'city'); 
 $metrics = array('visits');
 $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) {
    $visits = $result->getVists();
    print $visits; 
  }

 ?>

Keep in mind to turn off your 2-step verification for the google account. If you don't , it will throw you a bad request error despite the validity of your account info.

这篇关于Google Analytics PHP API(GAPI) - 获取页面浏览次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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