Merge pull request #1682 from mailpoet/woo-stats
Report more WooCommerce stats [MAILPOET-1646]
This commit is contained in:
@@ -4,6 +4,7 @@ namespace MailPoet\Analytics;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@@ -11,6 +12,7 @@ class Analytics {
|
||||
|
||||
const SETTINGS_LAST_SENT_KEY = 'analytics_last_sent';
|
||||
const SEND_AFTER_DAYS = 7;
|
||||
const ANALYTICS_FILTER = 'mailpoet_analytics';
|
||||
|
||||
/** @var Reporter */
|
||||
private $reporter;
|
||||
@@ -22,7 +24,7 @@ class Analytics {
|
||||
/** @return array */
|
||||
function generateAnalytics() {
|
||||
if($this->shouldSend()) {
|
||||
$data = $this->reporter->getData();
|
||||
$data = WPHooks::applyFilters(self::ANALYTICS_FILTER, $this->reporter->getData());
|
||||
$this->recordDataSent();
|
||||
return $data;
|
||||
}
|
||||
|
@@ -21,6 +21,16 @@ class Reporter {
|
||||
$checker = new ServicesChecker();
|
||||
$bounceAddress = Setting::getValue('bounce.address');
|
||||
$segments = Segment::getAnalytics();
|
||||
$has_wc = class_exists('WooCommerce');
|
||||
$wc_customers_count = 0;
|
||||
if($has_wc) {
|
||||
$wc_customers_count = (int)Newsletter::rawQuery(
|
||||
"SELECT COUNT(DISTINCT m.meta_value) as count FROM ".$wpdb->prefix."posts p ".
|
||||
"JOIN ".$wpdb->prefix."postmeta m ON m.post_id = p.id ".
|
||||
"WHERE p.post_type = 'shop_order' ".
|
||||
"AND m.meta_key = '_customer_user' AND m.meta_value <> 0"
|
||||
)->findOne()->count;
|
||||
}
|
||||
|
||||
return array(
|
||||
'PHP version' => PHP_VERSION,
|
||||
@@ -49,7 +59,8 @@ class Reporter {
|
||||
'Open and click tracking' => (boolean)Setting::getValue('tracking.enabled', false),
|
||||
'Premium key valid' => $checker->isPremiumKeyValid(),
|
||||
'New subscriber notifications' => NewSubscriberNotificationMailer::isDisabled(Setting::getValue(NewSubscriberNotificationMailer::SETTINGS_KEY)),
|
||||
'Number of standard newsletters sent in last 3 months' => $newsletters['sent_newsletters'],
|
||||
'Number of standard newsletters sent in last 3 months' => $newsletters['sent_newsletters_3_months'],
|
||||
'Number of standard newsletters sent in last 30 days' => $newsletters['sent_newsletters_30_days'],
|
||||
'Number of active post notifications' => $newsletters['notifications_count'],
|
||||
'Number of active welcome emails' => $newsletters['welcome_newsletters_count'],
|
||||
'Number of segments' => isset($segments['dynamic']) ? (int)$segments['dynamic'] : 0,
|
||||
@@ -59,7 +70,7 @@ class Reporter {
|
||||
'Plugin > Bloom' => is_plugin_active('bloom-for-publishers/bloom.php'),
|
||||
'Plugin > WP Holler' => is_plugin_active('holler-box/holler-box.php'),
|
||||
'Plugin > WP-SMTP' => is_plugin_active('wp-mail-smtp/wp_mail_smtp.php'),
|
||||
'Plugin > WooCommerce' => is_plugin_active('woocommerce/woocommerce.php'),
|
||||
'Plugin > WooCommerce' => $has_wc,
|
||||
'Plugin > WooCommerce Subscription' => is_plugin_active('woocommerce-subscriptions/woocommerce-subscriptions.php'),
|
||||
'Plugin > WooCommerce Follow Up Emails' => is_plugin_active('woocommerce-follow-up-emails/woocommerce-follow-up-emails.php'),
|
||||
'Plugin > WooCommerce Email Customizer' => is_plugin_active('woocommerce-email-customizer/woocommerce-email-customizer.php'),
|
||||
@@ -73,6 +84,8 @@ class Reporter {
|
||||
'Plugin > Formidable Forms' => is_plugin_active('formidable/formidable.php'),
|
||||
'Plugin > Contact Form 7' => is_plugin_active('contact-form-7/wp-contact-form-7.php'),
|
||||
'Plugin > Easy Digital Downloads' => is_plugin_active('easy-digital-downloads/easy-digital-downloads.php'),
|
||||
'Web host' => Setting::getValue('mta_group') == 'website' ? Setting::getValue('web_host') : null,
|
||||
'Number of WooCommerce subscribers' => $wc_customers_count,
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -577,6 +577,7 @@ class Newsletter extends Model {
|
||||
return $count > 0;
|
||||
}
|
||||
|
||||
|
||||
static function getAnalytics() {
|
||||
$welcome_newsletters_count = Newsletter::getPublished()
|
||||
->filter('filterType', self::TYPE_WELCOME)
|
||||
@@ -588,7 +589,19 @@ class Newsletter extends Model {
|
||||
->filter('filterStatus', self::STATUS_ACTIVE)
|
||||
->count();
|
||||
|
||||
$sent_newsletters = static::table_alias('newsletters')
|
||||
$sent_newsletters_3_months = self::sentAfter(Carbon::now()->subMonths(3));
|
||||
$sent_newsletters_30_days = self::sentAfter(Carbon::now()->subDays(30));
|
||||
|
||||
return array(
|
||||
'welcome_newsletters_count' => $welcome_newsletters_count,
|
||||
'notifications_count' => $notifications_count,
|
||||
'sent_newsletters_3_months' => $sent_newsletters_3_months,
|
||||
'sent_newsletters_30_days' => $sent_newsletters_30_days,
|
||||
);
|
||||
}
|
||||
|
||||
static function sentAfter($date) {
|
||||
return static::table_alias('newsletters')
|
||||
->where('newsletters.type', self::TYPE_STANDARD)
|
||||
->where('newsletters.status', self::STATUS_SENT)
|
||||
->join(
|
||||
@@ -602,14 +615,8 @@ class Newsletter extends Model {
|
||||
'tasks'
|
||||
)
|
||||
->where('tasks.status', SendingQueue::STATUS_COMPLETED)
|
||||
->whereGte('tasks.processed_at', Carbon::now()->subMonths(3))
|
||||
->whereGte('tasks.processed_at', $date)
|
||||
->count();
|
||||
|
||||
return array(
|
||||
'welcome_newsletters_count' => $welcome_newsletters_count,
|
||||
'notifications_count' => $notifications_count,
|
||||
'sent_newsletters' => $sent_newsletters,
|
||||
);
|
||||
}
|
||||
|
||||
static function search($orm, $search = '') {
|
||||
|
Reference in New Issue
Block a user