如何在php分析报告中使用自定义维度

如何在php分析报告中使用自定义维度,php,google-analytics-api,Php,Google Analytics Api,我正在建立一个从google analytics获取数据的报告脚本。我正在添加三个维度来获取数据,但其中一个维度是名为test_dimension的自定义维度。当我设置这个维度时,我得到了这个错误 未知维度:测试维度 我尝试了开发人员API,但没有得到预期的结果 我希望输出具有应用的维度。如果我删除了自定义维度,代码将起作用。您需要使用自定义维度的索引(例如ga:dimension03)而不是其名称。该索引在“自定义定义”下的属性管理设置中可见 $custom = new Google_Ser

我正在建立一个从google analytics获取数据的报告脚本。我正在添加三个维度来获取数据,但其中一个维度是名为test_dimension的自定义维度。当我设置这个维度时,我得到了这个错误

未知维度:测试维度

我尝试了开发人员API,但没有得到预期的结果


我希望输出具有应用的维度。如果我删除了自定义维度,代码将起作用。

您需要使用自定义维度的索引(例如
ga:dimension03
)而不是其名称。该索引在“自定义定义”下的属性管理设置中可见

$custom = new Google_Service_AnalyticsReporting_Dimension();
$custom->setName("test_dimension");

$campaign = new Google_Service_AnalyticsReporting_Dimension();
$campaign->setName("ga:campaign");

$sourceMedium = new Google_Service_AnalyticsReporting_Dimension();
$sourceMedium->setName("ga:sourceMedium");

$request->setDimensions(array($custom,$campaign,$sourceMedium));

$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );