Skip to content

Commit

Permalink
feat: add new param 'metricFilter' in signature method 'get'
Browse files Browse the repository at this point in the history
  • Loading branch information
laudefe committed Jun 20, 2024
1 parent 36ffe36 commit 3ab5c4f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ The function returns a `Collection` in which each item is an array that holds ke
For all other queries you can use the `get` function.

```php
public function get(Period $period, array $metrics, array $dimensions = [], int $limit = 10, array $orderBy = [], FilterExpression $dimensionFilter = null): Collection
public function get(Period $period, array $metrics, array $dimensions = [], int $limit = 10, array $orderBy = [], FilterExpression $dimensionFilter = null, FilterExpression $metricFilter = null): Collection
```

Here's some extra info on the arguments you can pass:
Expand Down Expand Up @@ -284,6 +284,28 @@ $dimensionFilter = new FilterExpression([
]);
```

`FilterExpression $metricFilter`: filter applied after aggregating the report's rows, similar to SQL having-clause. Dimensions cannot be used in this filter. You can find more details [here](https://cloud.google.com/php/docs/reference/analytics-data/latest/V1beta.RunReportRequest).

For example:
```php
use Google\Analytics\Data\V1beta\Filter;
use Google\Analytics\Data\V1beta\FilterExpression;
use Google\Analytics\Data\V1beta\Filter\NumericFilter;
use Google\Analytics\Data\V1beta\NumericValue;
use Google\Analytics\Data\V1beta\Filter\NumericFilter\Operation;

$metricFilter = new FilterExpression([
'filter' => new Filter([
'field_name' => 'eventCount',
'numeric_filter' => new NumericFilter([
'operation' => Operation::GREATER_THAN,
'value' => new NumericValue([
'int64_value' => 3,
]),
]),
]),
]);

## Testing

Run the tests with:
Expand Down
2 changes: 2 additions & 0 deletions src/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public function get(
array $orderBy = [],
int $offset = 0,
?FilterExpression $dimensionFilter = null,
?FilterExpression $metricFilter = null,
bool $keepEmptyRows = false,
): Collection {
return $this->client->get(
Expand All @@ -224,6 +225,7 @@ public function get(
$orderBy,
$offset,
$dimensionFilter,
$metricFilter,
$keepEmptyRows
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/AnalyticsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function get(
array $orderBy = [],
int $offset = 0,
?FilterExpression $dimensionFilter = null,
?FilterExpression $metricFilter = null,
bool $keepEmptyRows = false,
): Collection {
$typeCaster = resolve(TypeCaster::class);
Expand All @@ -51,6 +52,7 @@ public function get(
'offset' => $offset,
'orderBys' => $orderBy,
'dimensionFilter' => $dimensionFilter,
'metricFilter' => $metricFilter,
'keepEmptyRows' => $keepEmptyRows,
]);

Expand Down

0 comments on commit 3ab5c4f

Please sign in to comment.