diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index 71f2175..381746f 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -1196,6 +1196,37 @@ public function get_broadcast_stats(int $id) return $this->get(sprintf('broadcasts/%s/stats', $id)); } + /** + * List link clicks for a specific broadcast. + * + * @param integer $id Broadcast ID. + * @param string $after_cursor Return results after the given pagination cursor. + * @param string $before_cursor Return results before the given pagination cursor. + * @param integer $per_page Number of results to return. + * + * @since 2.2.1 + * + * @see https://developers.kit.com/api-reference/broadcasts/get-link-clicks-for-a-broadcast + * + * @return false|mixed + */ + public function get_broadcast_link_clicks( + int $id, + string $after_cursor = '', + string $before_cursor = '', + int $per_page = 100 + ) { + // Send request. + return $this->get( + sprintf('broadcasts/%s/clicks', $id), + $this->build_total_count_and_pagination_params( + after_cursor: $after_cursor, + before_cursor: $before_cursor, + per_page: $per_page + ) + ); + } + /** * Updates a broadcast. * diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index e05a025..cb83d34 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -4190,6 +4190,47 @@ public function testGetBroadcastStatsWithInvalidBroadcastID() $this->api->get_broadcast_stats(12345); } + /** + * Test that get_broadcast_link_clicks() returns the expected data. + * + * @since 2.2.1 + * + * @return void + */ + public function testGetBroadcastLinkClicks() + { + // Get broadcast link clicks. + $result = $this->api->get_broadcast_link_clicks( + $_ENV['CONVERTKIT_API_BROADCAST_ID'], + per_page: 1 + ); + + // Assert clicks and pagination exist. + $this->assertDataExists($result->broadcast, 'clicks'); + $this->assertPaginationExists($result); + + // Assert a single click was returned. + $this->assertCount(1, $result->broadcast->clicks); + + // Assert has_previous_page and has_next_page are correct. + $this->assertFalse($result->pagination->has_previous_page); + $this->assertFalse($result->pagination->has_next_page); + } + + /** + * Test that get_broadcast_link_clicks() throws a ClientException when an invalid + * broadcast ID is specified. + * + * @since 2.2.1 + * + * @return void + */ + public function testGetBroadcastLinkClicksWithInvalidBroadcastID() + { + $this->expectException(ClientException::class); + $this->api->get_broadcast_link_clicks(12345); + } + /** * Test that update_broadcast() throws a ClientException when an invalid * broadcast ID is specified.