From 3ab5c4f43cce26c39c8bc273bc1026c1efe1581d Mon Sep 17 00:00:00 2001 From: laudefe Date: Thu, 20 Jun 2024 11:15:21 -0300 Subject: [PATCH 1/4] feat: add new param 'metricFilter' in signature method 'get' --- README.md | 24 +++++++++++++++++++++++- src/Analytics.php | 2 ++ src/AnalyticsClient.php | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4527635..f5e861b 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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: diff --git a/src/Analytics.php b/src/Analytics.php index 4e286f8..5b8d448 100644 --- a/src/Analytics.php +++ b/src/Analytics.php @@ -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( @@ -224,6 +225,7 @@ public function get( $orderBy, $offset, $dimensionFilter, + $metricFilter, $keepEmptyRows ); } diff --git a/src/AnalyticsClient.php b/src/AnalyticsClient.php index d4f5ab5..51829a8 100644 --- a/src/AnalyticsClient.php +++ b/src/AnalyticsClient.php @@ -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); @@ -51,6 +52,7 @@ public function get( 'offset' => $offset, 'orderBys' => $orderBy, 'dimensionFilter' => $dimensionFilter, + 'metricFilter' => $metricFilter, 'keepEmptyRows' => $keepEmptyRows, ]); From 661a367a32bc198c1dea7bd33695d3e011ad284e Mon Sep 17 00:00:00 2001 From: laudefe Date: Thu, 20 Jun 2024 11:55:10 -0300 Subject: [PATCH 2/4] fix: add new param to AnalyticsTest --- tests/AnalyticsTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/AnalyticsTest.php b/tests/AnalyticsTest.php index 984d0ea..4bc4c9c 100644 --- a/tests/AnalyticsTest.php +++ b/tests/AnalyticsTest.php @@ -33,6 +33,7 @@ [], 0, null, + null, false, ]; @@ -73,6 +74,7 @@ ], 0, null, + null, false, ]; @@ -115,6 +117,7 @@ ], 0, null, + null, false, ]; @@ -158,6 +161,7 @@ ], 0, null, + null, false, ]; @@ -202,6 +206,7 @@ ], 0, null, + null, false, ]; @@ -242,6 +247,7 @@ ], 0, null, + null, false, ]; @@ -293,6 +299,7 @@ ], 0, null, + null, false, ]; @@ -344,6 +351,7 @@ ], 0, null, + null, false, ]; From 15a7da571a7c8af67dfa77c442e5182eb873e63d Mon Sep 17 00:00:00 2001 From: laudefe Date: Tue, 16 Jul 2024 10:29:11 -0300 Subject: [PATCH 3/4] fix: move new param to the last position --- src/Analytics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analytics.php b/src/Analytics.php index 5b8d448..ee3bca2 100644 --- a/src/Analytics.php +++ b/src/Analytics.php @@ -213,8 +213,8 @@ public function get( array $orderBy = [], int $offset = 0, ?FilterExpression $dimensionFilter = null, - ?FilterExpression $metricFilter = null, bool $keepEmptyRows = false, + ?FilterExpression $metricFilter = null, ): Collection { return $this->client->get( $this->propertyId, From df6db707cdc2c03b2b465c9c243b011b698b6bc6 Mon Sep 17 00:00:00 2001 From: laudefe Date: Fri, 19 Jul 2024 11:59:05 -0300 Subject: [PATCH 4/4] fix: move new param to the last position in analyticsClient --- src/Analytics.php | 4 ++-- src/AnalyticsClient.php | 4 ++-- tests/AnalyticsTest.php | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Analytics.php b/src/Analytics.php index ee3bca2..293dfc6 100644 --- a/src/Analytics.php +++ b/src/Analytics.php @@ -225,8 +225,8 @@ public function get( $orderBy, $offset, $dimensionFilter, - $metricFilter, - $keepEmptyRows + $keepEmptyRows, + $metricFilter ); } } diff --git a/src/AnalyticsClient.php b/src/AnalyticsClient.php index 51829a8..a8994d9 100644 --- a/src/AnalyticsClient.php +++ b/src/AnalyticsClient.php @@ -36,8 +36,8 @@ public function get( array $orderBy = [], int $offset = 0, ?FilterExpression $dimensionFilter = null, - ?FilterExpression $metricFilter = null, bool $keepEmptyRows = false, + ?FilterExpression $metricFilter = null, ): Collection { $typeCaster = resolve(TypeCaster::class); @@ -52,8 +52,8 @@ public function get( 'offset' => $offset, 'orderBys' => $orderBy, 'dimensionFilter' => $dimensionFilter, - 'metricFilter' => $metricFilter, 'keepEmptyRows' => $keepEmptyRows, + 'metricFilter' => $metricFilter ]); $result = collect(); diff --git a/tests/AnalyticsTest.php b/tests/AnalyticsTest.php index 4bc4c9c..784aa92 100644 --- a/tests/AnalyticsTest.php +++ b/tests/AnalyticsTest.php @@ -33,8 +33,8 @@ [], 0, null, - null, false, + null, ]; $this @@ -74,8 +74,8 @@ ], 0, null, - null, false, + null, ]; $this @@ -117,8 +117,8 @@ ], 0, null, - null, false, + null, ]; $this @@ -161,8 +161,8 @@ ], 0, null, - null, false, + null, ]; $this @@ -206,8 +206,8 @@ ], 0, null, - null, false, + null, ]; $this @@ -247,8 +247,8 @@ ], 0, null, - null, false, + null, ]; $this @@ -299,8 +299,8 @@ ], 0, null, - null, false, + null, ]; $this @@ -351,8 +351,8 @@ ], 0, null, - null, false, + null, ]; $this