![](/img/trans.png)
[英]How creating a report with dimensionFilter and matchType in PHP ? (GA4)
[英]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
Metric.name is required and must not be the empty string
這是我的代碼
$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);
請將“Google_Service_AnalyticsReporting_Metric”替換為“Google_Service_AnalyticsData_Metric”。 替換該變量后,應該存在 setName 方法。
如果要檢索 GA4 媒體資源的指標數據,則需要使用 AnalyticsData API。 如果要檢索 Universal Analytics 視圖的指標數據,可以使用 AnalyticsReporting API。 每個 API 都有單獨的 PHP 類。
在此代碼段中,兩個 API 的代碼都存在。 這兩個獨立 API 的類不能互換使用。
在 AnalyticsData API 中,指標 class 有一個名稱字段: https://developers.google.com/analytics/devguides/reporting/Metricvdata/v
這是 AnalyticsReporting API: https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php的參考。 所有對象都以“Google_Service_AnalyticsReporting_”開頭。
此外,“城市”是一個維度,而不是一個指標。 在 GA4 中,維度和指標名稱不以“ga:”為前綴; 維度名稱只是“城市”而不是“ga:city”。 對於 AnalyticsData API,這些是 API 中可用的維度和指標: https://developers.google.com/analytics/devguides/reporting//
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.