[英]GA4 run report setting metrics & dimenssion
Using php laravel i am implementing GA4 data analytics api to get metrics data of my GA4 client website but i am unable to find method setName in Google_Service_AnalyticsReporting_Metric class when running script with out adding name i am getting error Using php laravel i am implementing GA4 data analytics api to get metrics data of my GA4 client website but i am unable to find method setName in Google_Service_AnalyticsReporting_Metric class when running script with out adding name i am getting error
Metric.name is required and must not be the empty string
here is my code这是我的代码
$analytics=new Google_Service_AnalyticsData($client);
// Create the ReportRequest object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("7daysAgo");
$dateRange->setEndDate("today");
// Create the Metrics object.
$metric = new Google_Service_AnalyticsReporting_Metric();
$metric->setExpression("ga:city");
// Create the Entity object.
$entity=new Google_Service_AnalyticsData_Entity();
$entity->setPropertyId("11111111");
// Create the Request object.
$request = new Google_Service_AnalyticsData_RunReportRequest();
$request->setEntity($entity);
$request->setDateRanges($dateRange);
$request->setMetrics($metric);
$data=$analytics->v1alpha->runReport($request);
Please replace "Google_Service_AnalyticsReporting_Metric" with "Google_Service_AnalyticsData_Metric".请将“Google_Service_AnalyticsReporting_Metric”替换为“Google_Service_AnalyticsData_Metric”。 After replacing that variable, the setName method should be present.
替换该变量后,应该存在 setName 方法。
If you want to retrieve metric data for GA4 property, you need to use the AnalyticsData API.如果要检索 GA4 媒体资源的指标数据,则需要使用 AnalyticsData API。 If you want to retrieve metric data for Universal Analytics view, you can use the AnalyticsReporting API.
如果要检索 Universal Analytics 视图的指标数据,可以使用 AnalyticsReporting API。 There are separate PHP classes for each API.
每个 API 都有单独的 PHP 类。
In this code snippet, code for both APIs are present.在此代码段中,两个 API 的代码都存在。 Classes for these two separate APIs cannot be used interchangeably.
这两个独立 API 的类不能互换使用。
In the AnalyticsData API, the metric class has a name field: https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1alpha/Metric在 AnalyticsData API 中,指标 class 有一个名称字段: https://developers.google.com/analytics/devguides/reporting/Metricvdata/v
This is a reference for the AnalyticsReporting API: https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php .这是 AnalyticsReporting API: https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php的参考。 All objects begin with "Google_Service_AnalyticsReporting_".
所有对象都以“Google_Service_AnalyticsReporting_”开头。
Also, "city" is a dimension and not a metric.此外,“城市”是一个维度,而不是一个指标。 In GA4, dimension and metric names are not prefixed by "ga:";
在 GA4 中,维度和指标名称不以“ga:”为前缀; the dimension name is just "city" and not "ga:city".
维度名称只是“城市”而不是“ga:city”。 For the AnalyticsData API, these are the dimensions and metrics available in the API: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema
对于 AnalyticsData API,这些是 API 中可用的维度和指标: https://developers.google.com/analytics/devguides/reporting//
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.