Skip to content

Commit

Permalink
fix division by zero error
Browse files Browse the repository at this point in the history
  • Loading branch information
199ocero committed Jun 2, 2024
1 parent c8a17d8 commit 061a207
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions app/Filament/Admin/Widgets/CampaignPerformanceMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,23 @@ protected function getData(): array
->where('complained_at', '!=', null)
->count();

$bounceRate = round(($emailsBounced / $emailsDelivered) * 100, 2);
$openRate = round(($emailsOpened / ($emailsDelivered - $emailsBounced)) * 100, 2);
$clickedThroughRate = round(($emailsClicked / ($emailsDelivered - $emailsBounced)) * 100, 2);
$unsubscribeRate = round(($unsubscribe / $emailsDelivered) * 100, 2);
$spamRate = round(($emailsComplaint / $emailsDelivered) * 100, 2);
if ($emailsDelivered != 0) {
$bounceRate = round(($emailsBounced / $emailsDelivered) * 100, 2);
$unsubscribeRate = round(($unsubscribe / $emailsDelivered) * 100, 2);
$spamRate = round(($emailsComplaint / $emailsDelivered) * 100, 2);
} else {
$bounceRate = 0;
$unsubscribeRate = 0;
$spamRate = 0;
}

if ($emailsDelivered - $emailsBounced != 0) {
$openRate = round(($emailsOpened / ($emailsDelivered - $emailsBounced)) * 100, 2);
$clickedThroughRate = round(($emailsClicked / ($emailsDelivered - $emailsBounced)) * 100, 2);
} else {
$openRate = 0;
$clickedThroughRate = 0;
}

return [
'datasets' => [
Expand Down

0 comments on commit 061a207

Please sign in to comment.