- Displays statistics in newsletter listing

This commit is contained in:
Vlad
2016-04-26 11:50:40 -04:00
committed by Tautvidas Sipavičius
parent 67ca305b7f
commit 18f35b5e91
4 changed files with 53 additions and 11 deletions

View File

@ -16,7 +16,7 @@ define(
MailPoet
) {
var Link = Router.Link;
console.log(MailPoet)
var columns = [
{
name: 'subject',
@ -31,6 +31,10 @@ define(
name: 'segments',
label: MailPoet.I18n.t('lists')
},
{
name: 'statistics',
label: MailPoet.I18n.t('statistics')
},
{
name: 'created_at',
label: MailPoet.I18n.t('createdOn'),
@ -205,6 +209,31 @@ define(
);
}
},
renderStatistics: function(item) {
if(!item.statistics || !item.queue) {
return (
<span>
{MailPoet.I18n.t('notSentYet')}
</span>
);
}
var percentage_clicked = Math.round(
(item.statistics.clicked * 100) / (item.queue.count_processed)
);
var percentage_opened = Math.round(
(item.statistics.opened * 100) / (item.queue.count_processed)
);
var percentage_unsubscribed = Math.round(
(item.statistics.unsubscribed * 100) / (item.queue.count_processed)
);
return (
<span>
{ percentage_opened }%, { percentage_clicked }%, { percentage_unsubscribed }%
</span>
);
},
renderItem: function(newsletter, actions) {
var rowClasses = classNames(
'manage-column',
@ -216,6 +245,13 @@ define(
return segment.name
}).join(', ');
var statistics_column =
(!mailpoet_settings.tracking || !mailpoet_settings.tracking.enabled) ?
false :
<td className="column {statistics_class}" data-colname="Statistics">
{ this.renderStatistics(newsletter) }
</td>;
return (
<div>
<td className={ rowClasses }>
@ -224,12 +260,13 @@ define(
</strong>
{ actions }
</td>
<td className="column" data-colname="Lists">
<td className="column" data-colname="Status">
{ this.renderStatus(newsletter) }
</td>
<td className="column" data-colname="Lists">
{ segments }
</td>
{ statistics_column }
<td className="column-date" data-colname="Subscribed on">
<abbr>{ MailPoet.Date.full(newsletter.created_at) }</abbr>
</td>
@ -240,6 +277,9 @@ define(
);
},
render: function() {
if (!mailpoet_settings.tracking || !mailpoet_settings.tracking.enabled) {
columns = _.without(columns, _.findWhere(columns, {name: 'statistics'}));
}
return (
<div>
<h2 className="title">

View File

@ -94,15 +94,14 @@ class Newsletter extends Model {
}
function getStatistics() {
if (!property_exists($this, 'queue') || $this->queue === false) {
if ($this->queue === false) {
return false;
}
return SendingQueue::tableAlias('queues')
->selectExpr(
'count(DISTINCT(clicks.id)) as clicks, ' .
'count(DISTINCT(opens.id)) as opens, ' .
'count(DISTINCT(unsubscribes.id)) as unsubscribes',
'queues.count_processed as total_sent'
'count(DISTINCT(clicks.id)) as clicked, ' .
'count(DISTINCT(opens.id)) as opened, ' .
'count(DISTINCT(unsubscribes.id)) as unsubscribed '
)
->join(
MP_STATISTICS_CLICKS_TABLE,

View File

@ -203,11 +203,13 @@ class Newsletters {
$listing_data = $listing->get();
foreach($listing_data['items'] as $key => $newsletter) {
$listing_data['items'][$key] = $newsletter
$newsletter = $newsletter
->withSegments()
->withSendingQueue()
->withStatistics()
->asArray();
->withSendingQueue();
if((boolean) Setting::getValue('tracking.enabled')) {
$newsletter = $newsletter->withStatistics();
}
$listing_data['items'][$key] = $newsletter->asArray();
}
return $listing_data;

View File

@ -46,6 +46,7 @@
'subject': __('Subject'),
'status': __('Status'),
'statistics': __('Opened, Clicked, Unsubscribed'),
'lists': __('Lists'),
'createdOn': __('Created on'),
'lastModifiedOn': __('Last modified on'),