• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Run report setting and metrics in GA4

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

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock