使用Google指标和维度中列出的指标时出错

时间:2016-01-08 06:16:53

标签: api google-analytics metrics dimensions

我正在使用此代码查询api

Cordova library for "android" already exists. No need to download. Continuing.
Checking if platform "android" passes minimum requirements...
Checking Android requirements...
Running "android list target" (output to follow)
Available Android targets:
----------

id: 1 or "android-19"
     Name: Android 4.4
     Type: Platform
     API level: 19
     Revision: 1
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
     ABIs : armeabi-v7a

Error: Please install Android target 17 (the Android 4.2 SDK). Make sure you have the latest Android tools installed as well. Run `android` from your command-line to install/update any missing SDKs or tools.
    at C:\Program Files (x86)\Zend\Zend Studio 11.0.2\plugins\com.zend.php.ccm.core.win32_11.0.2.v20140926-0202\resources\nodejs\node_modules\cordova\src\platform.js:268:42
    at C:\Program Files (x86)\Zend\Zend Studio 11.0.2\plugins\com.zend.php.ccm.core.win32_11.0.2.v20140926-0202\resources\nodejs\node_modules\cordova\src\metadata\android_parser.js:54:17
    at C:\Program Files (x86)\Zend\Zend Studio 11.0.2\plugins\com.zend.php.ccm.core.win32_11.0.2.v20140926-0202\resources\nodejs\node_modules\cordova\node_modules\shelljs\shell.js:1707:7
    at ChildProcess.exithandler (child_process.js:645:7)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:753:16)
    at Socket.<anonymous> (child_process.js:966:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.close (net.js:465:12)

执行代码时出现此错误

  

致命错误:未捕获的异常'Google_Service_Exception'   消息'调用GET时出错   https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A114460017&start-date=30daysAgo&end-date=today&metrics=ga%3AsessionCount%2Cga%3AsessionDurationBucket%2Cga%3Ausers%2Cga%3ApercentNewSessions%2Cga%3AbounceRate%2Cga%3Apageviews:   (400)未知指标:ga:sessionCount,ga:sessionDurationBucket

有谁经历过?我不明白为什么它列出时不能识别这些指标

https://developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&group=user&jump=ga_sessioncount

1 个答案:

答案 0 :(得分:1)

如果您仔细查看该文档,您会发现会话计数不是指标,而是一个维度。原因是您希望能够按会话计数对指标进行细分(例如,“为具有3个会话的用户显示平均会话持续时间”),并且您需要分类数据。

即使你忽略了目录中的(不是特别有区别的)列标题(ga:sessionCount在“维度”列中),数据类型是字符串这一事实也是一个不错的赠品。指标始终是数字。尺寸总是字符串,即使它们有时看起来像数字。

同样适用于ga:sessionDurationBucket。

请查看此example from the documentation,了解如何通过包含可选参数的数组将维度传递到查询中:

private function queryCoreReportingApi() {
  $optParams = array(
      'dimensions' => 'ga:source,ga:keyword',
      'sort' => '-ga:sessions,ga:source',
      'filters' => 'ga:medium==organic',
      'max-results' => '25');

  return $service->data_ga->get(
      TABLE_ID,
      '2010-01-01',
      '2010-01-15',
      'ga:sessions',
      $optParams);
}

您需要构建一个类似的$ optParams数组:

$optParams = array(
          'dimensions' => 'ga:sessionCount,ga:sessionDurationBucket'
          '); 

并将其传递给您的查询:

return $analytics->data_ga->get(
       'ga:' . $profileId,
       '30daysAgo',
       'today',
        $optParams,  
       'ga:users,ga:percentNewSessions,ga:bounceRate,ga:pageviews');
}

并从指标列表中删除维度。

顺便说一下。 Google对维度和指标之间的差异及其在报告中的使用方式有wonderful documentation page