Home  >  Q&A  >  body text

How to use multiple filters with the Google Analytics Data API (GA4) using PHP

So this is my first question, I will try my best to follow the community rules. I'm trying to use multiple filters in Google Analytics Data API (GA4) using PHP. I've successfully been able to use a filter and display it in a custom dashboard.

The following is the code to get the url data starting with the value: /133. The question is, how to make a filter to get multiple urls. That is, I want the page's data to start with the values ​​"/133", "/88", "/678" and "/67"?

$response = $client->runReport([
    'property' => 'properties/' . $property_id,
    'dateRanges' => [
        new DateRange([
            'start_date' => '2022-01-01',
            'end_date' => 'today',
        ]),
    ],
    'dimensions' => [
        new Dimension(['name' => 'pageTitle',]),
        new Dimension(['name' => 'fullPageUrl',]),
    ],
    'metrics' => [
        new Metric(['name' => 'screenPageViews',]),
        new Metric(['name' => 'activeUsers',]),
        new Metric(['name' => 'newUsers',]),
        new Metric(['name' => 'userEngagementDuration',]),
    ],
    'dimensionFilter' => new FilterExpression([
        'filter' => new Filter([
            'field_name' => 'pagePath',
            'string_filter' => new FilterStringFilter([
                'match_type' => FilterStringFilterMatchType::BEGINS_WITH,
                'value' => '/133',
            ])
        ]),
    ]),
]);


P粉704196697P粉704196697324 days ago639

reply all(1)I'll reply

  • P粉011360903
  • Cancelreply