获取Google Analytics(个人资料)视图的目标列表

时间:2016-03-16 16:49:28

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

使用Google Analytics核心报告API查询目标转换数据,如果我使用以下参数查询API,我可以获得总目标转换次数:

 $metrics    = 'ga:goal1Completions,ga:goal2Completions,ga:goal3Completions',
   [
        'dimensions'    => 'ga:date',
        'output'        => 'dataTable'
    ]

enter image description here

问题是我不知道为每个View(Profile)注册了多少个目标,在这个例子中,目标3不存在。

如何列出特定视图(个人资料)的可用目标?

1 个答案:

答案 0 :(得分:2)

您可以通过Google Analytics Management API调用goals.list method

/**
 * Example #1:
 * Requests goals for a single view (profile).
 */
try {
  $goals = $analytics->management_goals->listManagementGoals($ACCOUNT_ID,
      $PROPERTY_ID,
      $VIEW_ID);

} catch (apiServiceException $e) {
  print 'There was an Analytics API service error '
      . $e->getCode() . ':' . $e->getMessage();

} catch (apiException $e) {
  print 'There was a general API error '
      . $e->getCode() . ':' . $e->getMessage();
}

目标也是templatized deimension/metric,如果您要查询Google Analytics Metadata API,它应至少让您知道最小值和最大值。