【问题标题】:How to set dates in GAPI Google Analytics class?如何在 GAPI Google Analytics 类中设置日期?
【发布时间】: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 &amp; 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


    【解决方案1】:

    好的,这成功了

     $start_date = ("2017-11-01");
     $end_date = ("today");
    
      $ga->requestReportData(ga_profile_id, array('browser', 'browserVersion'), array('pageviews', 'visits'), '-visits', $filter,$start_date,$end_date);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-13
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      • 2016-11-07
      • 1970-01-01
      相关资源
      最近更新 更多