加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

使用php获取谷歌分析实时数据

发布时间:2020-12-13 22:24:33 所属栏目:PHP教程 来源:网络整理
导读:我想为活跃用户获取谷歌分析实时数据.我用过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
我想为活跃用户获取谷歌分析实时数据.我用过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

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

解决方法

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

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

我还建议按照Hello Analytics API php中的说明来帮助您入门.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读