From 796b43485a246c735d330d0f4eb212644c46f771 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 8 Apr 2018 08:22:52 +1000 Subject: [PATCH] dev/Core#53 Add in stats to AB tests and add in clickthrough and opened % stats to mailing reports Update Test following changes in stats function Fixes following on from review Further divide by zero fixes --- CRM/Mailing/BAO/Mailing.php | 8 ++++++++ ang/crmMailingAB/EditCtrl/report.html | 2 +- ang/crmMailingAB/ReportCtrl.js | 6 +++++- api/v3/Mailing.php | 8 ++++++++ templates/CRM/Mailing/Page/Report.tpl | 4 ++-- tests/phpunit/api/v3/MailingTest.php | 3 +++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 3a0f08048c..8862cb7bdb 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -1997,12 +1997,16 @@ ORDER BY civicrm_email.is_bulkmail DESC $row['bounce_rate'] = (100.0 * $mailing->bounce) / $mailing->queue; $row['unsubscribe_rate'] = (100.0 * $row['unsubscribe']) / $mailing->queue; $row['optout_rate'] = (100.0 * $row['optout']) / $mailing->queue; + $row['opened_rate'] = $mailing->delivered ? (($row['opened'] / $mailing->delivered) * 100.0) : 0; + $row['clickthrough_rate'] = $mailing->delivered ? (($mailing->url / $mailing->delivered) * 100.0) : 0; } else { $row['delivered_rate'] = 0; $row['bounce_rate'] = 0; $row['unsubscribe_rate'] = 0; $row['optout_rate'] = 0; + $row['opened_rate'] = 0; + $row['clickthrough_rate'] = 0; } $row['links'] = array( @@ -2066,12 +2070,16 @@ ORDER BY civicrm_email.is_bulkmail DESC $report['event_totals']['bounce_rate'] = (100.0 * $report['event_totals']['bounce']) / $report['event_totals']['queue']; $report['event_totals']['unsubscribe_rate'] = (100.0 * $report['event_totals']['unsubscribe']) / $report['event_totals']['queue']; $report['event_totals']['optout_rate'] = (100.0 * $report['event_totals']['optout']) / $report['event_totals']['queue']; + $report['event_totals']['opened_rate'] = !empty($report['event_totals']['delivered']) ? (($report['event_totals']['opened'] / $report['event_totals']['delivered']) * 100.0) : 0; + $report['event_totals']['clickthrough_rate'] = !empty($report['event_totals']['delivered']) ? (($report['event_totals']['url'] / $report['event_totals']['delivered']) * 100.0) : 0; } else { $report['event_totals']['delivered_rate'] = 0; $report['event_totals']['bounce_rate'] = 0; $report['event_totals']['unsubscribe_rate'] = 0; $report['event_totals']['optout_rate'] = 0; + $report['event_totals']['opened_rate'] = 0; + $report['event_totals']['clickthrough_rate'] = 0; } /* Get the click-through totals, grouped by URL */ diff --git a/ang/crmMailingAB/EditCtrl/report.html b/ang/crmMailingAB/EditCtrl/report.html index d75d0ed23d..68b79245a3 100644 --- a/ang/crmMailingAB/EditCtrl/report.html +++ b/ang/crmMailingAB/EditCtrl/report.html @@ -78,7 +78,7 @@ class="crm-hover-button action-item" ng-href="{{statUrl(am.mailing, statType, 'events')}}" title="{{ts('Browse events of type \'%1\'', {1: statType.title})}}" - >{{stats[am.name][statType.name] || ts('n/a')}} + >{{stats[am.name][statType.name] || ts('n/a')}} {{stats[am.name][rateStats[statType.name]] || ' '}} {$report.event_totals.actionlinks.delivered} {if $report.mailing.open_tracking} {ts}Unique Opens{/ts} - {$report.event_totals.opened} + {$report.event_totals.opened} ({$report.event_totals.opened_rate|string_format:"%0.2f"}%) {$report.event_totals.actionlinks.opened} {ts}Total Opens{/ts} {$report.event_totals.total_opened} @@ -44,7 +44,7 @@ {/if} {if $report.mailing.url_tracking} {ts}Click-throughs{/ts} - {$report.event_totals.url} + {$report.event_totals.url} ({$report.event_totals.clickthrough_rate|string_format:"%0.2f"}%) {$report.event_totals.actionlinks.clicks} {/if} {ts}Forwards{/ts} diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php index 51d0b1fa43..1e506e601d 100644 --- a/tests/phpunit/api/v3/MailingTest.php +++ b/tests/phpunit/api/v3/MailingTest.php @@ -685,6 +685,9 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; 'Opened' => 20, 'Unique Clicks' => 0, 'Unsubscribers' => 20, + 'delivered_rate' => '80%', + 'opened_rate' => '25%', + 'clickthrough_rate' => '0%', ); $this->checkArrayEquals($expectedResult, $result['values'][$mail['id']]); } -- 2.25.1