Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/ConvertKit_API_Traits.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
41 changes: 41 additions & 0 deletions tests/ConvertKitAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down