John Davidson

php - Google Analytics 4 Data API can't get values of multiple metrics query

0 comments
Message:


I trying to get values of totalUsers, activeUsers, newUsers


My runReport code:


$response = $client->runReport([
'property' => "properties/$site->google_property_id",
'dateRanges' => [
new DateRange([
'start_date' => '30daysAgo',
'end_date' => 'today',
]),
],
'dimensions' => [new Dimension(['name' => 'date',])],
'metrics' => [
new Metric(['name' => 'totalUsers']),
new Metric(['name' => 'activeUsers']),
new Metric(['name' => 'newUsers']),

],
'orderBys' => [
new OrderBy([
'dimension' => new OrderBy\DimensionOrderBy([
'dimension_name' => 'date', // your dimension here
]),
'desc' => true,
]),
],
]);
$params['analytics'] = $response->getRows();

Problem: i can't get values of with $row->getMetricValues() and $row->getMetricValues()[1] but not working


@foreach ($analytics as $row)
@foreach ($row->getMetricValues() as $dimensionValue)
'{{$dimensionValue->getValue()}}',
@endforeach
@endforeach


My Answer:
be used to access and retrieve data from Google Analytics 4 properties. This API allows developers to programmatically access metrics, dimensions, and other data from their Google Analytics 4 accounts. This can be useful for creating custom reports, integrating Google Analytics data with other systems, and automating data retrieval tasks. The API uses RESTful endpoints and requires authentication using OAuth 2.0. Developers can use client libraries in various programming languages, such as PHP, to interact with the Google Analytics 4 Data API.

Rate this post

5 of 5 based on 9607 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us