diff --git a/assets/js/src/subscribers/listings_engagement_score.tsx b/assets/js/src/subscribers/listings_engagement_score.tsx index 8b9b9b4888..38b81ed4e1 100644 --- a/assets/js/src/subscribers/listings_engagement_score.tsx +++ b/assets/js/src/subscribers/listings_engagement_score.tsx @@ -7,12 +7,24 @@ interface Props { } export const ListingsEngagementScore: React.FunctionComponent = ({ subscriber }) => ( -
- {subscriber.engagement_score != null && ( -
- {subscriber.engagement_score} - % -
- )} +
+
+ {subscriber.engagement_score != null && ( +
+ { + subscriber + .engagement_score + .toLocaleString( + undefined, + { + minimumFractionDigits: 1, + maximumFractionDigits: 1, + } + ) + } + % +
+ )} +
); diff --git a/lib/Config/Migrator.php b/lib/Config/Migrator.php index 92878618d3..ae5a13a395 100644 --- a/lib/Config/Migrator.php +++ b/lib/Config/Migrator.php @@ -216,7 +216,7 @@ class Migrator { 'count_confirmations int(11) unsigned NOT NULL DEFAULT 0,', 'unsubscribe_token char(15) NULL,', 'link_token char(32) NULL,', - 'engagement_score tinyint unsigned NULL,', + 'engagement_score FLOAT unsigned NULL,', 'engagement_score_updated_at timestamp NULL,', 'PRIMARY KEY (id),', 'UNIQUE KEY email (email),', diff --git a/lib/Cron/Workers/SubscribersEngagementScore.php b/lib/Cron/Workers/SubscribersEngagementScore.php index ef7fc688de..4ba59ff6f4 100644 --- a/lib/Cron/Workers/SubscribersEngagementScore.php +++ b/lib/Cron/Workers/SubscribersEngagementScore.php @@ -39,6 +39,7 @@ class SubscribersEngagementScore extends SimpleWorker { if ($subscribers) { $this->schedule(); } + return true; } public function getNextRunDate() { diff --git a/lib/Entities/SubscriberEntity.php b/lib/Entities/SubscriberEntity.php index c37b851db5..f228e29fa3 100644 --- a/lib/Entities/SubscriberEntity.php +++ b/lib/Entities/SubscriberEntity.php @@ -126,8 +126,8 @@ class SubscriberEntity { private $linkToken; /** - * @ORM\Column(type="integer") - * @var int|null + * @ORM\Column(type="float", nullable=true) + * @var float|null */ private $engagementScore; @@ -410,16 +410,16 @@ class SubscriberEntity { } /** - * @return int|null + * @return float|null */ - public function getEngagementScore(): ?int { + public function getEngagementScore(): ?float { return $this->engagementScore; } /** - * @param int|null $engagementScore + * @param float|null $engagementScore */ - public function setEngagementScore(?int $engagementScore): void { + public function setEngagementScore(?float $engagementScore): void { $this->engagementScore = $engagementScore; } diff --git a/lib/Statistics/StatisticsOpensRepository.php b/lib/Statistics/StatisticsOpensRepository.php index 580b32c50a..b6c7c6eee9 100644 --- a/lib/Statistics/StatisticsOpensRepository.php +++ b/lib/Statistics/StatisticsOpensRepository.php @@ -9,7 +9,7 @@ use MailPoet\Entities\SubscriberEntity; use MailPoet\Tasks\Sending; /** - * @extends Repository + * @extends Repository */ class StatisticsOpensRepository extends Repository { protected function getEntityClassName(): string { @@ -43,7 +43,7 @@ class StatisticsOpensRepository extends Repository { ->setParameter('subscriberId', $subscriber) ->getQuery() ->getSingleScalarResult(); - $score = (int)round(($opens / $newslettersSentCount) * 100); + $score = ($opens / $newslettersSentCount) * 100; $subscriber->setEngagementScore($score); $this->entityManager->flush(); } diff --git a/lib/Statistics/Track/Clicks.php b/lib/Statistics/Track/Clicks.php index d5aa99ad31..a1180f0b52 100644 --- a/lib/Statistics/Track/Clicks.php +++ b/lib/Statistics/Track/Clicks.php @@ -33,16 +33,21 @@ class Clicks { /** @var LinkShortcodeCategory */ private $linkShortcodeCategory; + /** @var Opens */ + private $opens; + public function __construct( SettingsController $settingsController, Cookies $cookies, Shortcodes $shortcodes, + Opens $opens, LinkShortcodeCategory $linkShortcodeCategory ) { $this->settingsController = $settingsController; $this->cookies = $cookies; $this->shortcodes = $shortcodes; $this->linkShortcodeCategory = $linkShortcodeCategory; + $this->opens = $opens; } /** @@ -73,8 +78,7 @@ class Clicks { $this->sendRevenueCookie($statisticsClicks); $this->sendAbandonedCartCookie($subscriber); // track open event - $openEvent = new Opens(); - $openEvent->track($data, $displayImage = false); + $this->opens->track($data, $displayImage = false); } $url = $this->processUrl($link->getUrl(), $newsletter, $subscriber, $queue, $wpUserPreview); $this->redirectToUrl($url); diff --git a/tests/integration/Statistics/StatisticsOpensRepositoryTest.php b/tests/integration/Statistics/StatisticsOpensRepositoryTest.php index 0157cc96ee..6043209eef 100644 --- a/tests/integration/Statistics/StatisticsOpensRepositoryTest.php +++ b/tests/integration/Statistics/StatisticsOpensRepositoryTest.php @@ -12,7 +12,7 @@ use MailPoet\Subscribers\SubscribersRepository; use MailPoet\Tasks\Sending; use MailPoetVendor\Carbon\CarbonImmutable; -class StatisticsFormsRepositoryTest extends \MailPoetTest { +class StatisticsOpensRepositoryTest extends \MailPoetTest { /** @var StatisticsOpensRepository */ private $repository;