From 7bdd4ca4ae33eebddac2d3ad9cd96eadae784038 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 16 Jun 2026 20:06:21 +0800 Subject: [PATCH 1/3] Add `counting_mode` to `filter_subscribers` method --- src/ConvertKit_API_Traits.php | 6 +++++- tests/ConvertKitAPITest.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index 93f1c2e..e0bae89 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -1516,6 +1516,9 @@ public function create_subscribers(array $subscribers, string $callback_url = '' * - 'before' (\DateTime|null). * - 'states' (array). * - 'any' (array|null). + * @param string $counting_mode Controls how engagement-filter count thresholds are tallied. + * - 'raw' (default) counts every event — five opens of the same email = five. + * - 'unique_email' counts distinct emails on which the action occurred. * @param boolean $include_total_count To include the total count of records in the response, use true. * @param string $after_cursor Return results after the given pagination cursor. * @param string $before_cursor Return results before the given pagination cursor. @@ -1529,12 +1532,13 @@ public function create_subscribers(array $subscribers, string $callback_url = '' */ public function filter_subscribers( array $all = [], + string $counting_mode = 'raw', bool $include_total_count = false, string $after_cursor = '', string $before_cursor = '', int $per_page = 100 ) { - $options = []; + $options = ['counting_mode' => $counting_mode]; foreach ($all as $condition) { $option = []; diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index 33bb640..bfc9b20 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -4487,6 +4487,37 @@ public function testFilterSubscribersWithMultipleConditions() $this->assertPaginationExists($result); } + /** + * Test that filter_subscribers() returns the expected data + * when a counting mode is specified. + * + * @since 2.4.0 + * + * @return void + */ + public function testFilterSubscribersWithCountingMode() + { + $result = $this->api->filter_subscribers( + all: [ + [ + 'type' => 'opens', + 'count_greater_than' => 10, + 'count_less_than' => 100, + 'after' => new \DateTime('2024-01-01'), + 'before' => new \DateTime('2027-01-01'), + 'states' => [ + 'active', + ], + ] + ], + counting_mode: 'unique_email' + ); + + // Assert subscribers and pagination exist. + $this->assertDataExists($result, 'subscribers'); + $this->assertPaginationExists($result); + } + /** * Test that filter_subscribers() returns the expected data * when no parameters are specified. From fc57c55ec7b281f41d0809c3352e960dfc7c5815 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 16 Jun 2026 20:08:14 +0800 Subject: [PATCH 2/3] Tests: Fix version number --- tests/ConvertKitAPITest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index bfc9b20..bb69f2a 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -4491,7 +4491,7 @@ public function testFilterSubscribersWithMultipleConditions() * Test that filter_subscribers() returns the expected data * when a counting mode is specified. * - * @since 2.4.0 + * @since 2.5.0 * * @return void */ From 9f0360d93c652fa327e7810ffbf28a0ef873d110 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 17 Jun 2026 15:36:29 +0800 Subject: [PATCH 3/3] PHPStan compat. --- src/ConvertKit_API_Traits.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index e0bae89..5901454 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -1538,7 +1538,7 @@ public function filter_subscribers( string $before_cursor = '', int $per_page = 100 ) { - $options = ['counting_mode' => $counting_mode]; + $options = []; foreach ($all as $condition) { $option = []; @@ -1577,7 +1577,10 @@ public function filter_subscribers( return $this->post( 'subscribers/filter', $this->build_total_count_and_pagination_params( - ['all' => $options], + [ + 'all' => $options, + 'counting_mode' => $counting_mode, + ], $include_total_count, $after_cursor, $before_cursor,