diff --git a/lib/Cron/Workers/StatsNotifications/Worker.php b/lib/Cron/Workers/StatsNotifications/Worker.php
index a779721a42..aab0c65534 100644
--- a/lib/Cron/Workers/StatsNotifications/Worker.php
+++ b/lib/Cron/Workers/StatsNotifications/Worker.php
@@ -42,9 +42,9 @@ class Worker {
try {
$this->mailer->send($this->constructNewsletter($task), $settings['address']);
} catch(\Exception $e) {
- //if(WP_DEBUG) {
+ if(WP_DEBUG) {
throw $e;
- //}
+ }
} finally {
$this->markTaskAsFinished($task);
}
@@ -99,19 +99,24 @@ class Worker {
}
private function prepareContext(Newsletter $newsletter, NewsletterLink $link) {
+ $clicked = ($newsletter->statistics['clicked'] * 100) / $newsletter->total_sent;
+ $opened = ($newsletter->statistics['opened'] * 100) / $newsletter->total_sent;
+ $unsubscribed = ($newsletter->statistics['unsubscribed'] * 100) / $newsletter->total_sent;
return [
'subject' => $newsletter->subject,
'preheader' => sprintf(_x(
'%1$s%% opens, %2$s%% clicks, %3$s%% unsubscribes in a nutshell.', 'newsletter open rate, click rate and unsubscribe rate', 'mailpoet'),
- number_format(($newsletter->statistics['clicked'] * 100) / $newsletter->total_sent, 2),
- number_format(($newsletter->statistics['opened'] * 100) / $newsletter->total_sent,2),
- number_format(($newsletter->statistics['unsubscribed'] * 100) / $newsletter->total_sent,2)
+ number_format($clicked, 2),
+ number_format($opened, 2),
+ number_format($unsubscribed, 2)
),
- 'topLinkClicks' => $link->clicksCount,
+ 'topLinkClicks' => (int)$link->clicksCount,
'topLink' => $link->url,
'linkSettings' => get_site_url(null, '/wp-admin/admin.php?page=mailpoet-settings#basics'),
'linkStats' => get_site_url(null, '/wp-admin/admin.php?page=mailpoet-newsletters#/stats/' . $newsletter->id()),
'premiumPluginActive' => is_plugin_active('mailpoet-premium/mailpoet-premium.php'),
+ 'clicked' => $clicked,
+ 'opened' => $opened,
];
}
diff --git a/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php b/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php
index 0121ac0b20..ff92b07467 100644
--- a/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php
+++ b/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php
@@ -170,7 +170,7 @@ class WorkerTest extends \MailPoetTest {
$this->stringContains('statsNotification.html'),
$this->callback(function($context){
return ($context['topLink'] === 'Link url2')
- && ($context['topLinkClicks'] === '2');
+ && ($context['topLinkClicks'] === 2);
}));
$this->stats_notifications->process();
diff --git a/views/emails/statsNotification.html b/views/emails/statsNotification.html
index a0f47b4f18..df361b6848 100644
--- a/views/emails/statsNotification.html
+++ b/views/emails/statsNotification.html
@@ -24,6 +24,20 @@
+<% if opened > 30 %>
+ <% set openedColor = '2993ab' %>
+<% elseif opened > 10 %>
+ <% set openedColor = 'f0b849' %>
+<% else %>
+ <% set openedColor = 'd54e21' %>
+<% endif %>
+<% if clicked > 3 %>
+ <% set clickedColor = '2993ab' %>
+<% elseif clicked > 1 %>
+ <% set clickedColor = 'f0b849' %>
+<% else %>
+ <% set clickedColor = 'd54e21' %>
+<% endif %>
@@ -106,8 +120,14 @@
@@ -117,8 +137,8 @@
-
- 29.8%
+
+ <%= number_format_i18n(opened) %>%
|
@@ -128,7 +148,7 @@
-
+
<%= __('open rate') %>
|
@@ -151,8 +171,14 @@
@@ -162,8 +188,8 @@
-
- 3.1%
+
+ <%= number_format_i18n(clicked) %>%
|
@@ -173,7 +199,7 @@
-
+
<%= __('click rate') %>
|
@@ -193,75 +219,77 @@
-
-
-
- |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <%= __('%s unique clicks')|replace({'%s': topLinkClicks}) %>
-
- |
-
- |
-
-
-
- |
-
-
-
- |
-
+ <% if topLinkClicks > 0 %>
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <%= __('%s unique clicks')|replace({'%s': topLinkClicks}) %>
+
+ |
+
+ |
+
+
+
+ |
+
+
+
+ |
+
+ <% endif %>
@@ -283,44 +311,47 @@
|
-
-
-
-
+ <% if premiumPluginActive %>
+
+
+
+ |
+
+ <% else %>
+
+
+
-
- |
-
-
-
-
-
-
- <%= __('See more stats in the Premium version, like all the links that were clicked or which subscribers opened your emails. You can also create segments of subscribers by clicks and opens.') %>
- |
-
- |
-
-
-
-
- |
-
+
+ <%= __('See more stats in the Premium version, like all the links that were clicked or which subscribers opened your emails. You can also create segments of subscribers by clicks and opens.') %>
+ |
+
+ |
+
+
+
+
+ |
+
+ <% endif %>
|
|