所以这是我的第一个问题,我会尽力遵守社区规则。 我正在尝试使用 PHP 在 Google Analytics Data API (GA4) 中使用多个过滤器。我已经成功地能够使用一个过滤器并将其显示在自定义仪表板中。
下面是获取以值开头的 url 数据的代码:/133。 问题是,如何制作一个过滤器来获取多个网址。也就是说,我希望页面的数据以值“/133”、“/88”、“/678”和“/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', ]) ]), ]), ]);
有关如何构建 FitlerExpression 的文档链接可以找到 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([ 'or_group' => new FilterExpressionList([ 'expressions' => [ new FilterExpression([ 'filter' => new Filter([ 'field_name' => 'pagePath', 'string_filter' => new Filter\StringFilter([ 'match_type' => Filter\StringFilter\MatchType::BEGINS_WITH, 'value' => '/133', ]) ]), ]), new FilterExpression([ 'filter' => new Filter([ 'field_name' => 'pagePath', 'string_filter' => new Filter\StringFilter([ 'match_type' => Filter\StringFilter\MatchType::BEGINS_WITH, 'value' => '/88', ]) ]), ]), ] ]), ]), ]);