-
Implementing Advanced Dimension Filters in Google Analytics Data API (GA4) with PHP Client Library
Hey, I’m working on adding regex filters to a request. I’m trying to use the filter FilterStringFilterMatchType::FULL_REGEXP, but I can’t seem to find any examples or helpful documentation on this. I’ve run my code, and even though there aren’t any errors, I’m not getting any results either.
Right now, I’m trying to retrieve results where the hostname is a site and the pageReferrer starts with https://. Below is the piece of code I’m working with:
$request = $client->runReport([
'property' => 'properties/' . $property_id,
'dateRanges' => [
new DateRange([
'start_date' => "$dateStart",
'end_date' => "$dateEnd",
]),
],
'dimensions' => [
new Dimension(['name' => 'hostName']),
new Dimension(['name' => 'pageReferrer']),
],'metrics' => [
new Metric(['name' => 'sessions']),
],'dimensionFilter' => new FilterExpression([
'and_group' => new FilterExpressionList([
'expressions' => [
new FilterExpression([
'filter' => new Filter([
'field_name' => 'hostName',
'string_filter' => new FilterStringFilter([
'match_type' => FilterStringFilterMatchType::FULL_REGEXP,
'value' => 'hostName==www.site.com',
])
]),
]),
new FilterExpression([
'filter' => new Filter([
'field_name' => 'pageReferrer',
'string_filter' => new FilterStringFilter([
'match_type' => FilterStringFilterMatchType::FULL_REGEXP,
'value' => 'pageReferrer!~^https://*',
])
]),
]),
]
]),
]),
]);
Any ideas where I’m going wrong here?
Log in to reply.