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