Calculate difference to previously sent emails
This commit is contained in:
@@ -56,7 +56,10 @@ export function transformEmailsToRows(emails: EmailStats[]) {
|
||||
|
||||
return emails.map((email) => {
|
||||
// Shows the percentage of clicked emails compared to the number of sent emails
|
||||
const clickedPercentage = calculatePercentage(email.clicked, email.sent);
|
||||
const clickedPercentage = calculatePercentage(
|
||||
email.clicked,
|
||||
email.sent.current,
|
||||
);
|
||||
const clickedBadge = percentageBadgeCalculation(clickedPercentage);
|
||||
|
||||
return [
|
||||
@@ -79,19 +82,23 @@ export function transformEmailsToRows(emails: EmailStats[]) {
|
||||
<a
|
||||
href={`?page=mailpoet-newsletters#/sending-status/${email.id}`}
|
||||
>
|
||||
{`${email.sent}`}
|
||||
{`${email.sent.current}`}
|
||||
</a>
|
||||
</Tooltip>
|
||||
}
|
||||
subValue={
|
||||
// Shows the percentage of sent emails compared to the previous email
|
||||
percentageFormatter.format(
|
||||
calculatePercentage(email.sent, email.sent, true) / 100,
|
||||
calculatePercentage(
|
||||
email.sent.current,
|
||||
email.sent.previous,
|
||||
true,
|
||||
) / 100,
|
||||
)
|
||||
}
|
||||
/>
|
||||
),
|
||||
value: email.sent,
|
||||
value: email.sent.current,
|
||||
},
|
||||
{
|
||||
display: (
|
||||
@@ -100,7 +107,7 @@ export function transformEmailsToRows(emails: EmailStats[]) {
|
||||
subValue={
|
||||
// Shows the percentage of opened emails compared to the number of sent emails
|
||||
percentageFormatter.format(
|
||||
calculatePercentage(email.opened, email.sent) / 100,
|
||||
calculatePercentage(email.opened, email.sent.current) / 100,
|
||||
)
|
||||
}
|
||||
/>
|
||||
@@ -112,13 +119,15 @@ export function transformEmailsToRows(emails: EmailStats[]) {
|
||||
<Cell
|
||||
value={email.clicked}
|
||||
className={
|
||||
email.sent > 0
|
||||
email.sent.current > 0
|
||||
? 'mailpoet-automation-analytics-email-clicked'
|
||||
: ''
|
||||
}
|
||||
subValue={percentageFormatter.format(clickedPercentage / 100)}
|
||||
badge={email.sent > 0 ? clickedBadge.badge : undefined}
|
||||
badgeType={email.sent > 0 ? clickedBadge.badgeType : undefined}
|
||||
badge={email.sent.current > 0 ? clickedBadge.badge : undefined}
|
||||
badgeType={
|
||||
email.sent.current > 0 ? clickedBadge.badgeType : undefined
|
||||
}
|
||||
/>
|
||||
),
|
||||
value: email.clicked,
|
||||
|
@@ -9,7 +9,7 @@ export function calculateSummary(rows: EmailStats[]) {
|
||||
}
|
||||
const data = rows.reduce(
|
||||
(acc, row) => {
|
||||
acc.sent += row.sent;
|
||||
acc.sent += row.sent.current;
|
||||
acc.opened += row.opened;
|
||||
acc.clicked += row.clicked;
|
||||
acc.orders += row.orders;
|
||||
|
@@ -18,7 +18,7 @@ export type EmailStats = {
|
||||
order: number;
|
||||
name: string;
|
||||
previewUrl: string;
|
||||
sent: number;
|
||||
sent: CurrentAndPrevious;
|
||||
opened: number;
|
||||
clicked: number;
|
||||
orders: number;
|
||||
|
@@ -75,7 +75,8 @@ class OverviewStatisticsController {
|
||||
$newsletter = $this->newslettersRepository->findOneById($newsletterId);
|
||||
$data['emails'][$newsletterId]['id'] = $newsletterId;
|
||||
$data['emails'][$newsletterId]['name'] = $newsletter ? $newsletter->getSubject() : '';
|
||||
$data['emails'][$newsletterId]['sent'] = $statistic->getTotalSentCount();
|
||||
$data['emails'][$newsletterId]['sent']['current'] = $statistic->getTotalSentCount();
|
||||
$data['emails'][$newsletterId]['sent']['previous'] = 0;
|
||||
$data['emails'][$newsletterId]['opened'] = $statistic->getOpenCount();
|
||||
$data['emails'][$newsletterId]['clicked'] = $statistic->getClickCount();
|
||||
$data['emails'][$newsletterId]['unsubscribed'] = $statistic->getUnsubscribeCount();
|
||||
@@ -92,13 +93,16 @@ class OverviewStatisticsController {
|
||||
$requiredData
|
||||
);
|
||||
|
||||
foreach ($previousStatistics as $statistic) {
|
||||
foreach ($previousStatistics as $newsletterId => $statistic) {
|
||||
$data['sent']['previous'] += $statistic->getTotalSentCount();
|
||||
$data['opened']['previous'] += $statistic->getOpenCount();
|
||||
$data['clicked']['previous'] += $statistic->getClickCount();
|
||||
$data['unsubscribed']['previous'] += $statistic->getUnsubscribeCount();
|
||||
$data['orders']['previous'] += $statistic->getWooCommerceRevenue() ? $statistic->getWooCommerceRevenue()->getOrdersCount() : 0;
|
||||
$data['revenue']['previous'] += $statistic->getWooCommerceRevenue() ? $statistic->getWooCommerceRevenue()->getValue() : 0;
|
||||
if (isset($data['emails'][$newsletterId])) {
|
||||
$data['emails'][$newsletterId]['sent']['previous'] = $statistic->getTotalSentCount();
|
||||
}
|
||||
}
|
||||
|
||||
usort($data['emails'], function ($a, $b) {
|
||||
|
Reference in New Issue
Block a user