I try to add regex filters to this request but I didn't find documentation with samples using filter : Filter\StringFilter\MatchType::FULL_REGEXP.
I don't have errors but i also doesn't have result. Where i do wrong ?
Here my code in error :
$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 Filter\StringFilter([
'match_type' => Filter\StringFilter\MatchType::FULL_REGEXP,
'value' => 'hostName==www.site.com',
])
]),
]),
new FilterExpression([
'filter' => new Filter([
'field_name' => 'pageReferrer',
'string_filter' => new Filter\StringFilter([
'match_type' => Filter\StringFilter\MatchType::FULL_REGEXP,
'value' => 'pageReferrer!~^https:\/\/*',
])
]),
]),
]
]),
]),
]);
Still i link doc and samples i found about this API :
General PHP examples about filters and request from github.
Other basic examples of how to create request with filters but in raw HTTP or python only (no mention of PHP).
The filter doc give some details about filters, but no idea how to translate it into PHP code.
Looking directly at the comments in the API code can also be useful.
The only example PHP found in the google doc.
This is my first post, so please forgive formatting mistakes.
I concur with the other poster's comment "There's obviously lack of examples in the GA4 documentation." The GA4 Data API v1 is laughably unready for commercial use, utterly at odds with Google's promise to sunset Universal Analytics on July 1. The lack of examples in their docs is maybe the most egregious gap.
Soapbox put away.... When you specify FULL_REGEXP, then the 'value' key is intended to hold a regular expression, not a regex evaluation. So, your filter definition would be:
new FilterExpression([
'filter' => new Filter([
'field_name' => 'hostName',
'string_filter' => new Filter\StringFilter([
'match_type' => Filter\StringFilter\MatchType::FULL_REGEXP,
'value' => 'www\.site\.com',
])
]),
]),