-
Implementing Metric Filtering in GA4 API with PHP Library
Hey folks, I’m messing around with the GA4 api php library and trying to learn how to filter dimensions. But I’m stuck as it’s currently in beta and the php examples I need are nowhere to be found.
Right now when I run my code, I get “Expect GoogleAnalyticsDataV1betaNumericValue.” popping up.
If anyone can point me in the right direction, that’d be amazing.
$response = $client->runReport([ 'property' => 'properties/' . $property_id, 'dateRanges' => [ new DateRange([ 'start_date' => 'yesterday', 'end_date' => 'yesterday', ]), ], 'dimensions' => [ new Dimension([ 'name' => 'eventName', ]), ], 'metrics' => [ new Metric([ 'name' => 'eventCount', ]) ], 'metricFilter' => new FilterExpression([ 'filter' => new Filter([ 'field_name' => 'eventCount', 'numeric_filter' => new FilterNumericFilter([ 'operation' => FilterNumericFilterOperation::GREATER_THAN, 'value' => '10000', ]) ]), ]), ]);
Oh, and here’s the JSON version of the request from the api explorer, in case it helps:
{ "dimensions": [ { "name": "eventName" } ], "metrics": [ { "name": "eventCount" } ], "dateRanges": [ { "startDate": "yesterday", "endDate": "yesterday" } ], "metricFilter": { "filter": { "fieldName": "eventCount", "numericFilter": { "operation": "GREATER_THAN", "value": { "int64Value": "10000" } } } } }
Log in to reply.