【问题标题】:Get google analytics real time data using php使用 php 获取谷歌分析实时数据
【发布时间】:2015-11-09 14:08:22
【问题描述】:

我想获取活跃用户的谷歌分析实时数据。我使用了来自的 google api client php https://code.google.com/p/google-api-php-client/source/browse/trunk/src/?r=474#

For screenviews after setting metrics and dimensions

$metrics    =   'ga:screenviews';
$optParams  =   array('dimensions' => 'ga:screenName');

$service = new Google_AnalyticsService($client);
try {
    $result = $service->data_ga->get(
        $GA_VIEW_ID,
        $start_date,
        $end_date,
        $metrics,
        $optParams
    );
} catch(Exception $e) {
    var_dump($e);
}

我得到了正确的结果。 我想获取实时数据,但无法获取。我已经尝试如下。

$metrics = 'rt:medium'; $optParams = array('dimensions' => 'rt:activeUsers');

try {
  $results = $service->data_realtime->get(
      $GA_VIEW_ID,
      'rt:activeUsers',
      $optParams);
} catch (apiServiceException $e) {
  // Handle API service exceptions.
  $error = $e->getMessage();
}

// Error  : Undefined property: Google_AnalyticsService::$data_realtime

请给我解决方案以获取实时数据。

【问题讨论】:

  • 你有实时 API 的测试访问权限吗?

标签: php google-api google-analytics-api google-api-php-client


【解决方案1】:

问题是您签出了一个非常旧版本的客户端库。继续检查来自 github 的 v1-master 分支:

git clone -b v1-master https://github.com/google/google-api-php-client.git

我还建议您按照Hello Analytics API php 中的说明进行操作,以帮助您入门。

【讨论】:

    猜你喜欢
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    相关资源
    最近更新 更多