Sim*_*ard 4 php google-analytics google-analytics-api
我只是想通过销售的商品数量和总收入来获得产品销售.我正在使用适用于PHP的Google API客户端库:https://github.com/google/google-api-php-client.git
我能够为每个产品获得一个指标,例如,我可以列出上周购买的所有产品.或者我可以获得上周每个产品的总销售收入.我想要做的是同时获得两者.
所以我尝试的是......
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:itemQuantity,ga:itemRevenue");
Run Code Online (Sandbox Code Playgroud)
仅供参考,其余代码与https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php#3_setup_the_sample示例完全相同,我显然已添加到我的代码中细节,如果我只做ga:itemQuantity或ga:itemRevenue,一切正常.
我准备的任何文档都说逗号分隔指标,但它只是死了,整个页面甚至没有加载所以我没有得到任何错误等.
我想做什么?如果是这样我该如何去做呢?
小智 14
我没有尝试使用逗号分隔值,但你可以做的是创建多个指标,如下所示:
$metric1 = new Google_Service_AnalyticsReporting_Metric();
$metric1->setExpression("ga:itemQuantity");
$metric2 = new Google_Service_AnalyticsReporting_Metric();
$metric2->setExpression("ga:itemRevenue");
Run Code Online (Sandbox Code Playgroud)
然后,当您创建请求时,您可以"附加"这两个指标:
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
...
$request->setMetrics(array($metric1, $metric2));
....
// Follow the samples that you mentioned for the rest
Run Code Online (Sandbox Code Playgroud)
这应该有效,并且在响应指标数据中,您现在应该拥有一个包含两个指标值的数组.
祝好运!