Google AnalyticsAPI仅返回10行

时间:2016-08-06 10:19:07

标签: php google-analytics

我正在使用此课程从Google Analytics中提取数据:

https://github.com/erebusnz/gapi-google-analytics-php-interface

我只能显示10行,但我的分析数据中有10行以上。

我还设置了max_results=50。它仍只显示10行。

以下是显示超过10行的屏幕截图:

enter image description here

$start_date='2016-08-06';
$end_date='2016-09-05';
try {
      $ga->requestReportData(xxxxxxxx,
      array('browser'),
      array('pageviews'),
      $sort_metric=null, $filter=null,
      $start_date,$end_date,
      $start_index=1, $max_results=50);
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
    ?>
    <table width='60%'>
    <tr style="background-color:#00ff00;">
      <th>Browser</th>
      <th>Page Views</th>
    </tr>
    <?php
    foreach($ga->getResults() as $result):
    ?>
    <tr style="background-color:<?php echo $color ?>">
      <td><?php echo $result ?></td>
      <td><?php echo $result->getPageviews() ?></td>
    </tr>
    <?php
    endforeach
    ?>
    </table>

1 个答案:

答案 0 :(得分:0)

我同意你的看法,你的代码看起来是正确的,但是我想知道你附加的截图是否代表了与代码相同的日期范围。如果您提供屏幕截图的Google Analytics视图覆盖的时间比代码检索的时间长,那么考虑到第11项到第16项的会话数量相对较少而您没有检索到该数据,因为它不在您要求提供数据的日期范围。如果您将该日期范围打开,例如一年,会发生什么?

$start_date='2015-08-06';
$end_date='2016-09-05';
try {
      $ga->requestReportData(xxxxxxxx,
      array('browser'),
      array('pageviews'),
      $sort_metric=null, $filter=null,
      $start_date,$end_date,
      $start_index=1, $max_results=50);
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
    ?>
    <table width='60%'>
    <tr style="background-color:#00ff00;">
      <th>Browser</th>
      <th>Page Views</th>
    </tr>
    <?php
    foreach($ga->getResults() as $result):
    ?>
    <tr style="background-color:<?php echo $color ?>">
      <td><?php echo $result ?></td>
      <td><?php echo $result->getPageviews() ?></td>
    </tr>
    <?php
    endforeach
    ?>
    </table>

在原始代码中,您要求从今天开始并延续到今年9月5日的数据,这意味着您检索的唯一值将与今天发生的会话相关。今天没有人使用YE,SeaMonkey,Maxthon,亚马逊Silk,Opera Mini或UC浏览器访问您的网站的可能性很高。超过这六个的所有内容都代表了今天可能访问过的更常见的使用模式。