xandercage43
New member
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.
here is my code
_________________________
Pursuing Data Analytics training.
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.