Run report setting and metrics in GA4

  • Welcome to Babiato Forum! All Resources are 100% clean and Safe to Use

xandercage43

New member
Jan 12, 2021
1
0
1
India
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 the script without adding name I am getting an error.

Code:
Metric.name is required and must not be the empty string

here is my code


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);

_________________________
Pursuing Data Analytics training.
 

About us

  • Babiato Forum - The webmaster community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day, updating Daily resource to make sure our community is one of the best.

Quick Navigation

User Menu