Enhance Analytics\Reporter to fetch tracking data
[MAILPOET-1815]
This commit is contained in:
committed by
M. Shull
parent
f91b89bba5
commit
efc5aa5900
@@ -19,9 +19,9 @@ class Reporter {
|
|||||||
/** @var WooCommerceHelper */
|
/** @var WooCommerceHelper */
|
||||||
private $woocommerce_helper;
|
private $woocommerce_helper;
|
||||||
|
|
||||||
public function __construct(SettingsController $settings) {
|
public function __construct(SettingsController $settings, WooCommerceHelper $woocommerce_helper) {
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->woocommerce_helper = new WooCommerceHelper;
|
$this->woocommerce_helper = $woocommerce_helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getData() {
|
function getData() {
|
||||||
@@ -102,4 +102,19 @@ class Reporter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTrackingData() {
|
||||||
|
$newletters = Newsletter::getAnalytics();
|
||||||
|
$segments = Segment::getAnalytics();
|
||||||
|
$mta = $this->settings->get('mta', []);
|
||||||
|
return [
|
||||||
|
'newslettersSent' => $newletters['sent_newsletters_count'],
|
||||||
|
'welcomeEmails' => $newletters['welcome_newsletters_count'],
|
||||||
|
'postnotificationEmails' => $newletters['notifications_count'],
|
||||||
|
'woocommerceEmails' => $newletters['automatic_emails_count'],
|
||||||
|
'subscribers' => Subscriber::getTotalSubscribers(),
|
||||||
|
'lists' => isset($segments['default']) ? (int)$segments['default'] : 0,
|
||||||
|
'sendingMethod' => isset($mta['method']) ? $mta['method'] : null,
|
||||||
|
'woocommerceIsInstalled' => $this->woocommerce_helper->isWooCommerceActive(),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,8 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
ContainerWrapper::class,
|
ContainerWrapper::class,
|
||||||
'getInstance'
|
'getInstance'
|
||||||
]);
|
]);
|
||||||
|
// Analytics
|
||||||
|
$container->autowire(\MailPoet\Analytics\Reporter::class)->setPublic(true);
|
||||||
// API
|
// API
|
||||||
$container->autowire(\MailPoet\API\JSON\API::class)
|
$container->autowire(\MailPoet\API\JSON\API::class)
|
||||||
->addArgument(new Reference(ContainerWrapper::class))
|
->addArgument(new Reference(ContainerWrapper::class))
|
||||||
|
@@ -614,12 +614,24 @@ class Newsletter extends Model {
|
|||||||
->filter('filterStatus', self::STATUS_ACTIVE)
|
->filter('filterStatus', self::STATUS_ACTIVE)
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
|
$automatic_count = Newsletter::getPublished()
|
||||||
|
->filter('filterType', self::TYPE_AUTOMATIC)
|
||||||
|
->filter('filterStatus', self::STATUS_ACTIVE)
|
||||||
|
->count();
|
||||||
|
|
||||||
|
$newsletters_count = Newsletter::getPublished()
|
||||||
|
->filter('filterType', self::TYPE_STANDARD)
|
||||||
|
->filter('filterStatus', self::STATUS_SENT)
|
||||||
|
->count();
|
||||||
|
|
||||||
$sent_newsletters_3_months = self::sentAfter(Carbon::now()->subMonths(3));
|
$sent_newsletters_3_months = self::sentAfter(Carbon::now()->subMonths(3));
|
||||||
$sent_newsletters_30_days = self::sentAfter(Carbon::now()->subDays(30));
|
$sent_newsletters_30_days = self::sentAfter(Carbon::now()->subDays(30));
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'welcome_newsletters_count' => $welcome_newsletters_count,
|
'welcome_newsletters_count' => $welcome_newsletters_count,
|
||||||
'notifications_count' => $notifications_count,
|
'notifications_count' => $notifications_count,
|
||||||
|
'automatic_emails_count' => $automatic_count,
|
||||||
|
'sent_newsletters_count' => $newsletters_count,
|
||||||
'sent_newsletters_3_months' => $sent_newsletters_3_months,
|
'sent_newsletters_3_months' => $sent_newsletters_3_months,
|
||||||
'sent_newsletters_30_days' => $sent_newsletters_30_days,
|
'sent_newsletters_30_days' => $sent_newsletters_30_days,
|
||||||
);
|
);
|
||||||
|
@@ -5,13 +5,14 @@ namespace MailPoet\Twig;
|
|||||||
use MailPoet\Analytics\Reporter;
|
use MailPoet\Analytics\Reporter;
|
||||||
use MailPoet\Analytics\Analytics as AnalyticsGenerator;
|
use MailPoet\Analytics\Analytics as AnalyticsGenerator;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
|
use MailPoet\WooCommerce\Helper;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Analytics extends \Twig_Extension {
|
class Analytics extends \Twig_Extension {
|
||||||
public function getFunctions() {
|
public function getFunctions() {
|
||||||
$settings = new SettingsController();
|
$settings = new SettingsController();
|
||||||
$analytics = new AnalyticsGenerator(new Reporter($settings), $settings);
|
$analytics = new AnalyticsGenerator(new Reporter($settings, new Helper), $settings);
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction(
|
new \Twig_SimpleFunction(
|
||||||
'get_analytics_data',
|
'get_analytics_data',
|
||||||
|
@@ -6,6 +6,7 @@ use Carbon\Carbon;
|
|||||||
use Codeception\Stub;
|
use Codeception\Stub;
|
||||||
use Codeception\Stub\Expected;
|
use Codeception\Stub\Expected;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
|
use MailPoet\WooCommerce\Helper as WooCommerceHelper;
|
||||||
|
|
||||||
class AnalyticsTest extends \MailPoetTest {
|
class AnalyticsTest extends \MailPoetTest {
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ class AnalyticsTest extends \MailPoetTest {
|
|||||||
function _before() {
|
function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
$this->settings = new SettingsController();
|
$this->settings = new SettingsController();
|
||||||
$this->analytics = new Analytics(new Reporter($this->settings), $this->settings);
|
$this->analytics = new Analytics(new Reporter($this->settings, new WooCommerceHelper), $this->settings);
|
||||||
// Remove premium plugin hooks so that tests pass also with premium active
|
// Remove premium plugin hooks so that tests pass also with premium active
|
||||||
remove_all_filters(Analytics::ANALYTICS_FILTER);
|
remove_all_filters(Analytics::ANALYTICS_FILTER);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user