Add woocommerce properties to mixpanel reporter

[MAILPOET-1821]
This commit is contained in:
Pavel Dohnal
2019-03-19 15:45:24 +01:00
committed by M. Shull
parent 8b4bf19bdd
commit e660541b5b
2 changed files with 45 additions and 20 deletions

View File

@@ -26,7 +26,7 @@ class Reporter {
} }
function getData() { function getData() {
global $wpdb, $wp_version; global $wpdb, $wp_version, $woocommerce;
$mta = $this->settings->get('mta', []); $mta = $this->settings->get('mta', []);
$newsletters = Newsletter::getAnalytics(); $newsletters = Newsletter::getAnalytics();
$isCronTriggerMethodWP = $this->settings->get('cron_trigger.method') === CronTrigger::$available_methods['wordpress']; $isCronTriggerMethodWP = $this->settings->get('cron_trigger.method') === CronTrigger::$available_methods['wordpress'];
@@ -34,19 +34,8 @@ class Reporter {
$bounceAddress = $this->settings->get('bounce.address'); $bounceAddress = $this->settings->get('bounce.address');
$segments = Segment::getAnalytics(); $segments = Segment::getAnalytics();
$has_wc = $this->woocommerce_helper->isWooCommerceActive(); $has_wc = $this->woocommerce_helper->isWooCommerceActive();
$wc_customers_count = 0;
if ($has_wc) {
/** @var \stdClass */
$wc_customers = 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();
$wc_customers_count = (int)$wc_customers->count;
}
return array( $result = [
'PHP version' => PHP_VERSION, 'PHP version' => PHP_VERSION,
'MySQL version' => $wpdb->db_version(), 'MySQL version' => $wpdb->db_version(),
'WordPress version' => $wp_version, 'WordPress version' => $wp_version,
@@ -77,6 +66,7 @@ class Reporter {
'Number of standard newsletters sent in last 30 days' => $newsletters['sent_newsletters_30_days'], '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 post notifications' => $newsletters['notifications_count'],
'Number of active welcome emails' => $newsletters['welcome_newsletters_count'], 'Number of active welcome emails' => $newsletters['welcome_newsletters_count'],
'Total number of standard newsletters sent' => $newsletters['sent_newsletters_count'],
'Number of segments' => isset($segments['dynamic']) ? (int)$segments['dynamic'] : 0, 'Number of segments' => isset($segments['dynamic']) ? (int)$segments['dynamic'] : 0,
'Number of lists' => isset($segments['default']) ? (int)$segments['default'] : 0, 'Number of lists' => isset($segments['default']) ? (int)$segments['default'] : 0,
'Plugin > MailPoet Premium' => WPFunctions::get()->isPluginActive('mailpoet-premium/mailpoet-premium.php'), 'Plugin > MailPoet Premium' => WPFunctions::get()->isPluginActive('mailpoet-premium/mailpoet-premium.php'),
@@ -98,22 +88,32 @@ class Reporter {
'Plugin > Formidable Forms' => WPFunctions::get()->isPluginActive('formidable/formidable.php'), 'Plugin > Formidable Forms' => WPFunctions::get()->isPluginActive('formidable/formidable.php'),
'Plugin > Contact Form 7' => WPFunctions::get()->isPluginActive('contact-form-7/wp-contact-form-7.php'), 'Plugin > Contact Form 7' => WPFunctions::get()->isPluginActive('contact-form-7/wp-contact-form-7.php'),
'Plugin > Easy Digital Downloads' => WPFunctions::get()->isPluginActive('easy-digital-downloads/easy-digital-downloads.php'), 'Plugin > Easy Digital Downloads' => WPFunctions::get()->isPluginActive('easy-digital-downloads/easy-digital-downloads.php'),
'Plugin > WooCommerce Multi-Currency' => WPFunctions::get()->isPluginActive('woocommerce-multi-currency/woocommerce-multi-currency.php'),
'Plugin > Multi Currency for WooCommerce' => WPFunctions::get()->isPluginActive('woo-multi-currency/woo-multi-currency.php'),
'Web host' => $this->settings->get('mta_group') == 'website' ? $this->settings->get('web_host') : null, 'Web host' => $this->settings->get('mta_group') == 'website' ? $this->settings->get('web_host') : null,
'Number of WooCommerce subscribers' => $wc_customers_count, ];
); if ($has_wc) {
$result['WooCommerce version'] = $woocommerce->version;
$result['Number of WooCommerce subscribers'] = isset($segments['woocommerce_users']) ? (int)$segments['woocommerce_users'] : 0;
$result['WooCommerce: opt-in on checkout is active'] = $this->settings->get('woocommerce.optin_on_checkout.enabled') ?: false;
$result['WooCommerce: set old customers as subscribed'] = $this->settings->get('mailpoet_subscribe_old_woocommerce_customers.enabled') ?: false;
$result['Number of active WooCommerce first purchase emails'] = $newsletters['first_purchase_emails_count'];
$result['Number of active WooCommerce purchased this product emails'] = $newsletters['product_purchased_emails_count'];
}
return $result;
} }
function getTrackingData() { function getTrackingData() {
$newletters = Newsletter::getAnalytics(); $newsletters = Newsletter::getAnalytics();
$segments = Segment::getAnalytics(); $segments = Segment::getAnalytics();
$mta = $this->settings->get('mta', []); $mta = $this->settings->get('mta', []);
$installed_at = new Carbon($this->settings->get('installed_at')); $installed_at = new Carbon($this->settings->get('installed_at'));
return [ return [
'installedAtIso' => $installed_at->format(Carbon::ISO8601), 'installedAtIso' => $installed_at->format(Carbon::ISO8601),
'newslettersSent' => $newletters['sent_newsletters_count'], 'newslettersSent' => $newsletters['sent_newsletters_count'],
'welcomeEmails' => $newletters['welcome_newsletters_count'], 'welcomeEmails' => $newsletters['welcome_newsletters_count'],
'postnotificationEmails' => $newletters['notifications_count'], 'postnotificationEmails' => $newsletters['notifications_count'],
'woocommerceEmails' => $newletters['automatic_emails_count'], 'woocommerceEmails' => $newsletters['automatic_emails_count'],
'subscribers' => Subscriber::getTotalSubscribers(), 'subscribers' => Subscriber::getTotalSubscribers(),
'lists' => isset($segments['default']) ? (int)$segments['default'] : 0, 'lists' => isset($segments['default']) ? (int)$segments['default'] : 0,
'sendingMethod' => isset($mta['method']) ? $mta['method'] : null, 'sendingMethod' => isset($mta['method']) ? $mta['method'] : null,

View File

@@ -626,6 +626,9 @@ class Newsletter extends Model {
->filter('filterStatus', self::STATUS_SENT) ->filter('filterStatus', self::STATUS_SENT)
->count(); ->count();
$first_purchase_emails_count = self::getActiveAutomaticNewslettersCount('woocommerce_first_purchase');
$product_purchased_emails_count = self::getActiveAutomaticNewslettersCount('woocommerce_product_purchased');
$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));
@@ -636,9 +639,31 @@ class Newsletter extends Model {
'sent_newsletters_count' => $newsletters_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,
'first_purchase_emails_count' => $first_purchase_emails_count,
'product_purchased_emails_count' => $product_purchased_emails_count,
); );
} }
private static function getActiveAutomaticNewslettersCount($event_name) {
return NewsletterOption::tableAlias('options')
->join(
self::$_table,
'newsletters.id = options.newsletter_id',
'newsletters'
)
->join(
MP_NEWSLETTER_OPTION_FIELDS_TABLE,
'option_fields.id = options.option_field_id',
'option_fields'
)
->whereNull('newsletters.deleted_at')
->where('newsletters.type', self::TYPE_AUTOMATIC)
->where('newsletters.status', self::STATUS_ACTIVE)
->where('option_fields.name', 'event')
->where('options.value', $event_name)
->count();
}
static function sentAfter($date) { static function sentAfter($date) {
return static::tableAlias('newsletters') return static::tableAlias('newsletters')
->where('newsletters.type', self::TYPE_STANDARD) ->where('newsletters.type', self::TYPE_STANDARD)