Analytics.php
2 years ago
Reporter.php
1 year ago
ReporterCampaignData.php
2 years ago
UnsubscribeReporter.php
3 years ago
index.php
3 years ago
Reporter.php
442 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Analytics; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Automation\Engine\Data\Automation; |
| 9 | use MailPoet\Automation\Engine\Data\Step; |
| 10 | use MailPoet\Automation\Engine\Storage\AutomationStorage; |
| 11 | use MailPoet\Config\ServicesChecker; |
| 12 | use MailPoet\Cron\CronTrigger; |
| 13 | use MailPoet\Entities\DynamicSegmentFilterData; |
| 14 | use MailPoet\Listing\ListingDefinition; |
| 15 | use MailPoet\Newsletter\NewslettersRepository; |
| 16 | use MailPoet\Segments\DynamicSegments\DynamicSegmentFilterRepository; |
| 17 | use MailPoet\Segments\DynamicSegments\Filters\AutomationsEvents; |
| 18 | use MailPoet\Segments\DynamicSegments\Filters\EmailAction; |
| 19 | use MailPoet\Segments\DynamicSegments\Filters\EmailActionClickAny; |
| 20 | use MailPoet\Segments\DynamicSegments\Filters\EmailOpensAbsoluteCountAction; |
| 21 | use MailPoet\Segments\DynamicSegments\Filters\EmailsReceived; |
| 22 | use MailPoet\Segments\DynamicSegments\Filters\MailPoetCustomFields; |
| 23 | use MailPoet\Segments\DynamicSegments\Filters\NumberOfClicks; |
| 24 | use MailPoet\Segments\DynamicSegments\Filters\SubscriberDateField; |
| 25 | use MailPoet\Segments\DynamicSegments\Filters\SubscriberScore; |
| 26 | use MailPoet\Segments\DynamicSegments\Filters\SubscriberSegment; |
| 27 | use MailPoet\Segments\DynamicSegments\Filters\SubscriberSubscribedViaForm; |
| 28 | use MailPoet\Segments\DynamicSegments\Filters\SubscriberTag; |
| 29 | use MailPoet\Segments\DynamicSegments\Filters\SubscriberTextField; |
| 30 | use MailPoet\Segments\DynamicSegments\Filters\UserRole; |
| 31 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceAverageSpent; |
| 32 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceCategory; |
| 33 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceCountry; |
| 34 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceCustomerTextField; |
| 35 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceFirstOrder; |
| 36 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceMembership; |
| 37 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceNumberOfOrders; |
| 38 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceNumberOfReviews; |
| 39 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceProduct; |
| 40 | use MailPoet\Segments\DynamicSegments\Filters\WooCommercePurchaseDate; |
| 41 | use MailPoet\Segments\DynamicSegments\Filters\WooCommercePurchasedWithAttribute; |
| 42 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceSingleOrderValue; |
| 43 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceSubscription; |
| 44 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceTag; |
| 45 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceTotalSpent; |
| 46 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceUsedCouponCode; |
| 47 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceUsedPaymentMethod; |
| 48 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceUsedShippingMethod; |
| 49 | use MailPoet\Segments\SegmentsRepository; |
| 50 | use MailPoet\Services\AuthorizedEmailsController; |
| 51 | use MailPoet\Settings\Pages; |
| 52 | use MailPoet\Settings\SettingsController; |
| 53 | use MailPoet\Settings\TrackingConfig; |
| 54 | use MailPoet\Subscribers\ConfirmationEmailCustomizer; |
| 55 | use MailPoet\Subscribers\NewSubscriberNotificationMailer; |
| 56 | use MailPoet\Subscribers\SubscriberListingRepository; |
| 57 | use MailPoet\Subscription\Captcha\CaptchaConstants; |
| 58 | use MailPoet\Tags\TagRepository; |
| 59 | use MailPoet\Util\License\Features\Subscribers as SubscribersFeature; |
| 60 | use MailPoet\WooCommerce\Helper as WooCommerceHelper; |
| 61 | use MailPoet\WooCommerce\Subscription; |
| 62 | use MailPoet\WP\Functions as WPFunctions; |
| 63 | use MailPoet\WPCOM\DotcomHelperFunctions; |
| 64 | use MailPoetVendor\Carbon\Carbon; |
| 65 | |
| 66 | class Reporter { |
| 67 | /** @var NewslettersRepository */ |
| 68 | private $newslettersRepository; |
| 69 | |
| 70 | /** @var SegmentsRepository */ |
| 71 | private $segmentsRepository; |
| 72 | |
| 73 | /** @var DynamicSegmentFilterRepository */ |
| 74 | private $dynamicSegmentFilterRepository; |
| 75 | |
| 76 | /** @var TagRepository */ |
| 77 | private $tagRepository; |
| 78 | |
| 79 | /** @var ServicesChecker */ |
| 80 | private $servicesChecker; |
| 81 | |
| 82 | /** @var SettingsController */ |
| 83 | private $settings; |
| 84 | |
| 85 | /** @var WooCommerceHelper */ |
| 86 | private $woocommerceHelper; |
| 87 | |
| 88 | /** @var WPFunctions */ |
| 89 | private $wp; |
| 90 | |
| 91 | /** @var SubscribersFeature */ |
| 92 | private $subscribersFeature; |
| 93 | |
| 94 | /** @var TrackingConfig */ |
| 95 | private $trackingConfig; |
| 96 | |
| 97 | /** @var SubscriberListingRepository */ |
| 98 | private $subscriberListingRepository; |
| 99 | |
| 100 | /** @var AutomationStorage */ |
| 101 | private $automationStorage; |
| 102 | |
| 103 | /*** @var UnsubscribeReporter */ |
| 104 | private $unsubscribeReporter; |
| 105 | |
| 106 | /*** @var DotcomHelperFunctions */ |
| 107 | private $dotcomHelperFunctions; |
| 108 | |
| 109 | /*** @var ReporterCampaignData */ |
| 110 | private $reporterCampaignData; |
| 111 | |
| 112 | public function __construct( |
| 113 | NewslettersRepository $newslettersRepository, |
| 114 | SegmentsRepository $segmentsRepository, |
| 115 | DynamicSegmentFilterRepository $dynamicSegmentFilterRepository, |
| 116 | TagRepository $tagRepository, |
| 117 | ServicesChecker $servicesChecker, |
| 118 | SettingsController $settings, |
| 119 | WooCommerceHelper $woocommerceHelper, |
| 120 | WPFunctions $wp, |
| 121 | SubscribersFeature $subscribersFeature, |
| 122 | TrackingConfig $trackingConfig, |
| 123 | SubscriberListingRepository $subscriberListingRepository, |
| 124 | AutomationStorage $automationStorage, |
| 125 | UnsubscribeReporter $unsubscribeReporter, |
| 126 | DotcomHelperFunctions $dotcomHelperFunctions, |
| 127 | ReporterCampaignData $reporterCampaignData |
| 128 | ) { |
| 129 | $this->newslettersRepository = $newslettersRepository; |
| 130 | $this->segmentsRepository = $segmentsRepository; |
| 131 | $this->dynamicSegmentFilterRepository = $dynamicSegmentFilterRepository; |
| 132 | $this->tagRepository = $tagRepository; |
| 133 | $this->servicesChecker = $servicesChecker; |
| 134 | $this->settings = $settings; |
| 135 | $this->woocommerceHelper = $woocommerceHelper; |
| 136 | $this->wp = $wp; |
| 137 | $this->subscribersFeature = $subscribersFeature; |
| 138 | $this->trackingConfig = $trackingConfig; |
| 139 | $this->subscriberListingRepository = $subscriberListingRepository; |
| 140 | $this->automationStorage = $automationStorage; |
| 141 | $this->unsubscribeReporter = $unsubscribeReporter; |
| 142 | $this->dotcomHelperFunctions = $dotcomHelperFunctions; |
| 143 | $this->reporterCampaignData = $reporterCampaignData; |
| 144 | } |
| 145 | |
| 146 | public function getData() { |
| 147 | global $wpdb, $wp_version, $woocommerce; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 148 | $mta = $this->settings->get('mta', []); |
| 149 | $newsletters = $this->newslettersRepository->getAnalytics(); |
| 150 | $isCronTriggerMethodWP = $this->settings->get('cron_trigger.method') === CronTrigger::METHOD_WORDPRESS; |
| 151 | $bounceAddress = $this->settings->get('bounce.address'); |
| 152 | $segments = $this->segmentsRepository->getCountsPerType(); |
| 153 | $hasWc = $this->woocommerceHelper->isWooCommerceActive(); |
| 154 | $inactiveSubscribersMonths = (int)round((int)$this->settings->get('deactivate_subscriber_after_inactive_days') / 30); |
| 155 | $inactiveSubscribersStatus = $inactiveSubscribersMonths === 0 ? 'never' : "$inactiveSubscribersMonths months"; |
| 156 | |
| 157 | $result = [ |
| 158 | 'PHP version' => PHP_VERSION, |
| 159 | 'MySQL version' => $wpdb->db_version(), |
| 160 | 'WordPress version' => $wp_version, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 161 | 'Multisite environment' => $this->wp->isMultisite() ? 'yes' : 'no', |
| 162 | 'RTL' => $this->wp->isRtl() ? 'yes' : 'no', |
| 163 | 'WP_MEMORY_LIMIT' => WP_MEMORY_LIMIT, |
| 164 | 'WP_MAX_MEMORY_LIMIT' => WP_MAX_MEMORY_LIMIT, |
| 165 | 'PHP memory_limit' => ini_get('memory_limit'), |
| 166 | 'PHP max_execution_time' => ini_get('max_execution_time'), |
| 167 | 'users_can_register' => $this->wp->getOption('users_can_register') ? 'yes' : 'no', |
| 168 | 'MailPoet Free version' => MAILPOET_VERSION, |
| 169 | 'MailPoet Premium version' => (defined('MAILPOET_PREMIUM_VERSION')) ? MAILPOET_PREMIUM_VERSION : 'N/A', |
| 170 | 'Total number of subscribers' => $this->subscribersFeature->getSubscribersCount(), |
| 171 | 'Sending Method' => isset($mta['method']) ? $mta['method'] : null, |
| 172 | "Send all site's emails with" => $this->settings->get('send_transactional_emails') ? 'current sending method' : 'default WordPress sending method', |
| 173 | 'Date of plugin installation' => $this->settings->get('installed_at'), |
| 174 | 'Subscribe in comments' => (boolean)$this->settings->get('subscribe.on_comment.enabled', false), |
| 175 | 'Subscribe in registration form' => (boolean)$this->settings->get('subscribe.on_register.enabled', false), |
| 176 | 'Manage Subscription page > MailPoet page' => (boolean)Pages::isMailpoetPage(intval($this->settings->get('subscription.pages.manage'))), |
| 177 | 'Unsubscribe page > MailPoet page' => (boolean)Pages::isMailpoetPage(intval($this->settings->get('subscription.pages.unsubscribe'))), |
| 178 | 'Sign-up confirmation' => (boolean)$this->settings->get('signup_confirmation.enabled', false), |
| 179 | 'Sign-up confirmation: Confirmation page > MailPoet page' => (boolean)Pages::isMailpoetPage(intval($this->settings->get('subscription.pages.confirmation'))), |
| 180 | 'Bounce email address' => !empty($bounceAddress), |
| 181 | 'Newsletter task scheduler (cron)' => $isCronTriggerMethodWP ? 'visitors' : 'script', |
| 182 | 'Open and click tracking' => $this->trackingConfig->isEmailTrackingEnabled(), |
| 183 | 'Tracking level' => $this->settings->get('tracking.level', TrackingConfig::LEVEL_FULL), |
| 184 | 'Premium key valid' => $this->servicesChecker->isPremiumKeyValid(), |
| 185 | 'New subscriber notifications' => NewSubscriberNotificationMailer::isDisabled($this->settings->get(NewSubscriberNotificationMailer::SETTINGS_KEY)), |
| 186 | 'Number of active post notifications' => $newsletters['notifications_count'], |
| 187 | 'Number of active welcome emails' => $newsletters['welcome_newsletters_count'], |
| 188 | 'Total number of standard newsletters sent' => $newsletters['sent_newsletters_count'], |
| 189 | 'Number of segments' => isset($segments['dynamic']) ? (int)$segments['dynamic'] : 0, |
| 190 | 'Number of lists' => isset($segments['default']) ? (int)$segments['default'] : 0, |
| 191 | 'Number of subscriber tags' => $this->tagRepository->countBy([]), |
| 192 | 'Stop sending to inactive subscribers' => $inactiveSubscribersStatus, |
| 193 | 'CAPTCHA setting' => $this->settings->get(CaptchaConstants::TYPE_SETTING_NAME, '') ?: 'disabled', |
| 194 | 'Plugin > MailPoet Premium' => $this->wp->isPluginActive('mailpoet-premium/mailpoet-premium.php'), |
| 195 | 'Plugin > bounce add-on' => $this->wp->isPluginActive('mailpoet-bounce-handler/mailpoet-bounce-handler.php'), |
| 196 | 'Plugin > Bloom' => $this->wp->isPluginActive('bloom-for-publishers/bloom.php'), |
| 197 | 'Plugin > WP Holler' => $this->wp->isPluginActive('holler-box/holler-box.php'), |
| 198 | 'Plugin > WP-SMTP' => $this->wp->isPluginActive('wp-mail-smtp/wp_mail_smtp.php'), |
| 199 | 'Plugin > WooCommerce' => $hasWc, |
| 200 | 'Plugin > WooCommerce Subscription' => $this->wp->isPluginActive('woocommerce-subscriptions/woocommerce-subscriptions.php'), |
| 201 | 'Plugin > WooCommerce Follow Up Emails' => $this->wp->isPluginActive('woocommerce-follow-up-emails/woocommerce-follow-up-emails.php'), |
| 202 | 'Plugin > WooCommerce Email Customizer' => $this->wp->isPluginActive('woocommerce-email-customizer/woocommerce-email-customizer.php'), |
| 203 | 'Plugin > WooCommerce Memberships' => $this->wp->isPluginActive('woocommerce-memberships/woocommerce-memberships.php'), |
| 204 | 'Plugin > WooCommerce MailChimp' => $this->wp->isPluginActive('woocommerce-mailchimp/woocommerce-mailchimp.php'), |
| 205 | 'Plugin > MailChimp for WooCommerce' => $this->wp->isPluginActive('mailchimp-for-woocommerce/mailchimp-woocommerce.php'), |
| 206 | 'Plugin > The Event Calendar' => $this->wp->isPluginActive('the-events-calendar/the-events-calendar.php'), |
| 207 | 'Plugin > Gravity Forms' => $this->wp->isPluginActive('gravityforms/gravityforms.php'), |
| 208 | 'Plugin > Ninja Forms' => $this->wp->isPluginActive('ninja-forms/ninja-forms.php'), |
| 209 | 'Plugin > WPForms' => $this->wp->isPluginActive('wpforms-lite/wpforms.php'), |
| 210 | 'Plugin > Formidable Forms' => $this->wp->isPluginActive('formidable/formidable.php'), |
| 211 | 'Plugin > Contact Form 7' => $this->wp->isPluginActive('contact-form-7/wp-contact-form-7.php'), |
| 212 | 'Plugin > Easy Digital Downloads' => $this->wp->isPluginActive('easy-digital-downloads/easy-digital-downloads.php'), |
| 213 | 'Plugin > WooCommerce Multi-Currency' => $this->wp->isPluginActive('woocommerce-multi-currency/woocommerce-multi-currency.php'), |
| 214 | 'Plugin > Multi Currency for WooCommerce' => $this->wp->isPluginActive('woo-multi-currency/woo-multi-currency.php'), |
| 215 | 'Web host' => $this->settings->get('mta_group') == 'website' ? $this->settings->get('web_host') : null, |
| 216 | // Dynamic segment filters tracking -- start. If you extend segments tracking, please extend mapping in analytics.js |
| 217 | 'Segment > number of machine-opens' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_EMAIL, EmailOpensAbsoluteCountAction::MACHINE_TYPE), |
| 218 | 'Segment > number of opens' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_EMAIL, EmailOpensAbsoluteCountAction::TYPE), |
| 219 | 'Segment > number of orders' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceNumberOfOrders::ACTION_NUMBER_OF_ORDERS), |
| 220 | 'Segment > clicked' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_EMAIL, EmailAction::ACTION_CLICKED), |
| 221 | 'Segment > clicked any email' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_EMAIL, EmailActionClickAny::TYPE), |
| 222 | 'Segment > score' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberScore::TYPE), |
| 223 | 'Segment > subscribed to list' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberSegment::TYPE), |
| 224 | 'Segment > opened' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_EMAIL, EmailAction::ACTION_OPENED), |
| 225 | 'Segment > machine-opened' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_EMAIL, EmailAction::ACTION_MACHINE_OPENED), |
| 226 | 'Segment > is active member of' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE_MEMBERSHIP, WooCommerceMembership::ACTION_MEMBER_OF), |
| 227 | 'Segment > has an active subscription' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE_SUBSCRIPTION, WooCommerceSubscription::ACTION_HAS_ACTIVE), |
| 228 | 'Segment > is in country' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceCountry::ACTION_CUSTOMER_COUNTRY), |
| 229 | 'Segment > MailPoet custom field' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, MailPoetCustomFields::TYPE), |
| 230 | 'Segment > purchased in category' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceCategory::ACTION_CATEGORY), |
| 231 | 'Segment > purchased product' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceProduct::ACTION_PRODUCT), |
| 232 | 'Segment > purchased with tag' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceTag::ACTION), |
| 233 | 'Segment > subscribed date' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberDateField::SUBSCRIBED_DATE), |
| 234 | 'Segment > total spent' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceTotalSpent::ACTION_TOTAL_SPENT), |
| 235 | 'Segment > first order' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceFirstOrder::ACTION), |
| 236 | 'Segment > WordPress user role' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, UserRole::TYPE), |
| 237 | 'Segment > subscriber tags' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberTag::TYPE), |
| 238 | 'Segment > number of emails received' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_EMAIL, EmailsReceived::ACTION), |
| 239 | 'Segment > purchase date' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommercePurchaseDate::ACTION), |
| 240 | 'Segment > average order value' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceAverageSpent::ACTION), |
| 241 | 'Segment > single order value' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceSingleOrderValue::ACTION_SINGLE_ORDER_VALUE), |
| 242 | 'Segment > last engagement date' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberDateField::LAST_ENGAGEMENT_DATE), |
| 243 | 'Segment > last click date' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberDateField::LAST_CLICK_DATE), |
| 244 | 'Segment > last purchase date' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberDateField::LAST_PURCHASE_DATE), |
| 245 | 'Segment > last open date' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberDateField::LAST_OPEN_DATE), |
| 246 | 'Segment > last page view date' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberDateField::LAST_PAGE_VIEW_DATE), |
| 247 | 'Segment > last sending date' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberDateField::LAST_SENDING_DATE), |
| 248 | 'Segment > first name' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberTextField::FIRST_NAME), |
| 249 | 'Segment > last name' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberTextField::LAST_NAME), |
| 250 | 'Segment > email' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberTextField::EMAIL), |
| 251 | 'Segment > city' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceCustomerTextField::CITY), |
| 252 | 'Segment > postal code' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceCustomerTextField::POSTAL_CODE), |
| 253 | 'Segment > purchased with attribute' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommercePurchasedWithAttribute::ACTION), |
| 254 | 'Segment > used payment method' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceUsedPaymentMethod::ACTION), |
| 255 | 'Segment > used shipping method' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceUsedShippingMethod::ACTION), |
| 256 | 'Segment > number of reviews' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceNumberOfReviews::ACTION), |
| 257 | 'Segment > used coupon code' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_WOOCOMMERCE, WooCommerceUsedCouponCode::ACTION), |
| 258 | 'Segment > entered automation' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_AUTOMATIONS, AutomationsEvents::ENTERED_ACTION), |
| 259 | 'Segment > exited automation' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_AUTOMATIONS, AutomationsEvents::EXITED_ACTION), |
| 260 | 'Segment > was sent' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_EMAIL, EmailAction::ACTION_WAS_SENT), |
| 261 | 'Segment > subscribed via form' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_USER_ROLE, SubscriberSubscribedViaForm::TYPE), |
| 262 | 'Segment > number of clicks' => $this->isFilterTypeActive(DynamicSegmentFilterData::TYPE_EMAIL, NumberOfClicks::ACTION), |
| 263 | // Dynamic segment filters tracking -- end. If you extend segments tracking, please extend mapping in analytics.js |
| 264 | 'Number of segments with multiple conditions' => $this->segmentsRepository->getSegmentCountWithMultipleFilters(), |
| 265 | 'Support tier' => $this->subscribersFeature->hasPremiumSupport() ? 'premium' : 'free', |
| 266 | 'Unauthorized email notice shown' => !empty($this->settings->get(AuthorizedEmailsController::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING)), |
| 267 | 'Sign-up confirmation: Confirmation Template > using html email editor template' => (boolean)$this->settings->get(ConfirmationEmailCustomizer::SETTING_ENABLE_EMAIL_CUSTOMIZER, false), |
| 268 | 'Is WordPress.com' => $this->dotcomHelperFunctions->isDotcom() ? 'yes' : 'no', |
| 269 | 'WordPress.com plan' => $this->dotcomHelperFunctions->getDotcomPlan(), |
| 270 | ]; |
| 271 | |
| 272 | $result = array_merge( |
| 273 | $result, |
| 274 | $this->subscriberProperties(), |
| 275 | $this->automationProperties(), |
| 276 | $this->reporterCampaignData->getCampaignAnalyticsProperties(), |
| 277 | $this->unsubscribeReporter->getProperties() |
| 278 | ); |
| 279 | if ($hasWc) { |
| 280 | $result['WooCommerce version'] = $woocommerce->version; |
| 281 | $result['Number of WooCommerce subscribers'] = isset($segments['woocommerce_users']) ? (int)$segments['woocommerce_users'] : 0; |
| 282 | $result['WooCommerce: opt-in on checkout is active'] = $this->settings->get(Subscription::OPTIN_ENABLED_SETTING_NAME) ?: false; |
| 283 | $result['WooCommerce: opt-in on checkout position'] = $this->settings->get(Subscription::OPTIN_POSITION_SETTING_NAME) ?: ''; |
| 284 | $result['WooCommerce: set old customers as subscribed'] = $this->settings->get('mailpoet_subscribe_old_woocommerce_customers.enabled') ?: false; |
| 285 | $result['WooCommerce email customizer is active'] = $this->settings->get('woocommerce.use_mailpoet_editor') ?: false; |
| 286 | |
| 287 | $result['Number of active WooCommerce first purchase emails'] = $newsletters['first_purchase_emails_count']; |
| 288 | $result['Number of active WooCommerce purchased this product emails'] = $newsletters['product_purchased_emails_count']; |
| 289 | $result['Number of active purchased in this category'] = $newsletters['product_purchased_in_category_emails_count']; |
| 290 | $result['Number of active abandoned cart'] = $newsletters['abandoned_cart_emails_count']; |
| 291 | |
| 292 | $result['Installed via WooCommerce onboarding wizard'] = $this->woocommerceHelper->wasMailPoetInstalledViaWooCommerceOnboardingWizard(); |
| 293 | } |
| 294 | |
| 295 | return $result; |
| 296 | } |
| 297 | |
| 298 | private function automationProperties(): array { |
| 299 | $automations = $this->automationStorage->getAutomations(); |
| 300 | $activeAutomations = array_filter( |
| 301 | $automations, |
| 302 | function(Automation $automation): bool { |
| 303 | return $automation->getStatus() === Automation::STATUS_ACTIVE; |
| 304 | } |
| 305 | ); |
| 306 | $activeAutomationCount = count($activeAutomations); |
| 307 | $draftAutomations = array_filter( |
| 308 | $automations, |
| 309 | function(Automation $automation): bool { |
| 310 | return $automation->getStatus() === Automation::STATUS_DRAFT; |
| 311 | } |
| 312 | ); |
| 313 | $automationsWithCustomTrigger = array_filter( |
| 314 | $activeAutomations, |
| 315 | function(Automation $automation): bool { |
| 316 | return $automation->getTrigger('mailpoet:custom-trigger') !== null; |
| 317 | } |
| 318 | ); |
| 319 | $automationsWithWordPressUserSubscribesTrigger = array_filter( |
| 320 | $activeAutomations, |
| 321 | function(Automation $automation): bool { |
| 322 | return $automation->getTrigger('mailpoet:wp-user-registered') !== null; |
| 323 | } |
| 324 | ); |
| 325 | $automationsWithSomeoneSubscribesTrigger = array_filter( |
| 326 | $activeAutomations, |
| 327 | function(Automation $automation): bool { |
| 328 | return $automation->getTrigger('mailpoet:someone-subscribes') !== null; |
| 329 | } |
| 330 | ); |
| 331 | $automationsWithOrderStatusChangedTrigger = array_filter( |
| 332 | $activeAutomations, |
| 333 | function(Automation $automation): bool { |
| 334 | return $automation->getTrigger('woocommerce:order-status-changed') !== null; |
| 335 | } |
| 336 | ); |
| 337 | $automationsWithAbandonedCartTrigger = array_filter( |
| 338 | $activeAutomations, |
| 339 | function(Automation $automation): bool { |
| 340 | return $automation->getTrigger('woocommerce:abandoned-cart') !== null; |
| 341 | } |
| 342 | ); |
| 343 | |
| 344 | $totalSteps = 0; |
| 345 | $minSteps = null; |
| 346 | $maxSteps = 0; |
| 347 | foreach ($activeAutomations as $automation) { |
| 348 | $steps = array_filter( |
| 349 | $automation->getSteps(), |
| 350 | function(Step $step): bool { |
| 351 | return $step->getType() === Step::TYPE_ACTION; |
| 352 | } |
| 353 | ); |
| 354 | $stepCount = count($steps); |
| 355 | $minSteps = $minSteps !== null ? min($stepCount, $minSteps) : $stepCount; |
| 356 | $maxSteps = max($maxSteps, $stepCount); |
| 357 | $totalSteps += $stepCount; |
| 358 | } |
| 359 | $averageSteps = $activeAutomationCount > 0 ? $totalSteps / $activeAutomationCount : 0; |
| 360 | |
| 361 | $customTriggerHooks = array_unique(array_values(array_map( |
| 362 | function(Automation $automation): string { |
| 363 | $trigger = $automation->getTrigger('mailpoet:custom-trigger'); |
| 364 | return $trigger ? (string)$trigger->getArgs()['hook'] : ''; |
| 365 | }, |
| 366 | $automationsWithCustomTrigger |
| 367 | ))); |
| 368 | $customActionHooks = array_unique(array_values(array_map( |
| 369 | function(Automation $automation): array { |
| 370 | $customActionSteps = array_filter( |
| 371 | $automation->getSteps(), |
| 372 | function(Step $step): bool { |
| 373 | return $step->getKey() === 'mailpoet:custom-action'; |
| 374 | } |
| 375 | ); |
| 376 | if (!$customActionSteps) { |
| 377 | return []; |
| 378 | } |
| 379 | |
| 380 | return array_map( |
| 381 | function(Step $step): string { |
| 382 | return (string)$step->getArgs()['hook']; |
| 383 | }, |
| 384 | $customActionSteps |
| 385 | ); |
| 386 | |
| 387 | }, |
| 388 | $activeAutomations |
| 389 | ))); |
| 390 | $customActionHooks = array_values(array_filter(array_merge(...$customActionHooks))); |
| 391 | return [ |
| 392 | 'Automation > Number of active automations' => $activeAutomationCount, |
| 393 | 'Automation > Number of draft automations' => count($draftAutomations), |
| 394 | 'Automation > Number of "WordPress user registers" active automations' => count($automationsWithWordPressUserSubscribesTrigger), |
| 395 | 'Automation > Number of "Someone subscribes" active automations ' => count($automationsWithSomeoneSubscribesTrigger), |
| 396 | 'Automation > Number of "Order status changed" active automations ' => count($automationsWithOrderStatusChangedTrigger), |
| 397 | 'Automation > Number of "Subscriber abandons cart" active automations' => count($automationsWithAbandonedCartTrigger), |
| 398 | 'Automation > Number of steps in shortest active automation' => $minSteps, |
| 399 | 'Automation > Number of steps in longest active automation' => $maxSteps, |
| 400 | 'Automation > Average number of steps in active automations' => $averageSteps, |
| 401 | 'Automation > Custom Trigger Hooks' => $customTriggerHooks, |
| 402 | 'Automation > Custom Action Hooks' => $customActionHooks, |
| 403 | ]; |
| 404 | } |
| 405 | |
| 406 | private function subscriberProperties(): array { |
| 407 | $definition = new ListingDefinition(); |
| 408 | $groups = $this->subscriberListingRepository->getGroups($definition); |
| 409 | $properties = []; |
| 410 | foreach ($groups as $group) { |
| 411 | $properties['Subscribers > ' . $group['name']] = (int)$group['count']; |
| 412 | } |
| 413 | |
| 414 | return $properties; |
| 415 | } |
| 416 | |
| 417 | public function getTrackingData() { |
| 418 | $newsletters = $this->newslettersRepository->getAnalytics(); |
| 419 | $segments = $this->segmentsRepository->getCountsPerType(); |
| 420 | $mta = $this->settings->get('mta', []); |
| 421 | $installedAt = new Carbon($this->settings->get('installed_at')); |
| 422 | return [ |
| 423 | 'installedAtIso' => $installedAt->format(Carbon::ISO8601), |
| 424 | 'newslettersSent' => $newsletters['sent_newsletters_count'], |
| 425 | 'welcomeEmails' => $newsletters['welcome_newsletters_count'], |
| 426 | 'postnotificationEmails' => $newsletters['notifications_count'], |
| 427 | 'woocommerceEmails' => $newsletters['automatic_emails_count'], |
| 428 | 'subscribers' => $this->subscribersFeature->getSubscribersCount(), |
| 429 | 'lists' => isset($segments['default']) ? (int)$segments['default'] : 0, |
| 430 | 'sendingMethod' => isset($mta['method']) ? $mta['method'] : null, |
| 431 | 'woocommerceIsInstalled' => $this->woocommerceHelper->isWooCommerceActive(), |
| 432 | ]; |
| 433 | } |
| 434 | |
| 435 | private function isFilterTypeActive(string $filterType, string $action): bool { |
| 436 | if ($this->dynamicSegmentFilterRepository->findOnyByFilterTypeAndAction($filterType, $action)) { |
| 437 | return true; |
| 438 | } |
| 439 | return false; |
| 440 | } |
| 441 | } |
| 442 |