简体   繁体   English

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 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.

相关问题 如何在 PHP 中使用 dimensionFilter 和 matchType 创建报告? (GA4) - How creating a report with dimensionFilter and matchType in PHP ? (GA4) 在 GA4 Api 的维度过滤器中期望 integer - Expect integer in dimensionFilter of GA4 Api 通过 Measurement Protocol 向 GA4 媒体资源发送网页浏览事件 - send a pageview event via Measurement Protocol to a GA4 property 如何将访问令牌与 Google Admin API 一起用于 GA4 属性? - How to use access tokens with Google Admin API for GA4 properties? 如何在 PHP GA4 中为多个过滤器应用不同的和/或组? - How to apply different and/or groups for multiple filters in PHP GA4? 如何获取 Google Analytics(分析)GA4 帐户的所有属性 - How to get all properties for Google Analytics GA4 accounts PHP Google Analytics 数据 API V1 (Beta) (GA4) 通过服务账户授权 - PHP Google Analytics Data API V1 (Beta) (GA4) Authorization via Service Account 如何在使用 PHP 的 Google Analytics Data API (GA4) 中使用多个过滤器 - How to use multiple filters with Google Analytics Data API (GA4) using PHP 通过 oauth2(同意屏幕)从 Google Analytics Data API (Ga4) 中提取数据 - Extract data from Google Analytics Data API (Ga4) via oauth2 (consent screen) 来自服务器端的 GA4 自定义事件,有人可以告诉我如何在 php 中执行以下代码吗? - GA4 custom event from server side, can someone tell me how i can do the following code in php?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM