PluginProbe ʕ •ᴥ•ʔ
MailPoet – Newsletters, Email Marketing, and Automation / 5.0.1
MailPoet – Newsletters, Email Marketing, and Automation v5.0.1
5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 4.44.0 4.44.1 4.45.0 4.46.0 4.47.0 4.48.0 4.48.1 4.48.2 4.49.0 4.49.1 4.5.0 4.5.1 4.5.2 4.50.0 4.50.1 4.51.0 4.51.1 4.51.2 4.52.0 4.53.0 4.54.0 4.55.0 4.56.0 4.57.0 4.58.0 4.58.1 4.58.2 4.6.0 4.6.1 4.6.2 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 5.0.0 5.0.1 5.0.2 5.1.0 5.1.1 5.10.0 5.10.1 5.11.0 5.12.0 5.12.1 5.12.10 5.12.11 5.12.12 5.12.13 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13.0 5.13.1 5.13.2 5.14.0 5.14.1 5.14.2 5.14.3 5.15.0 5.15.1 5.16.0 5.16.1 5.16.2 5.16.3 5.16.4 5.17.0 5.17.1 5.17.2 5.17.3 5.17.4 5.17.5 5.17.6 5.18.0 5.19.0 5.2.0 5.2.1 5.2.2 5.2.3 5.20.0 5.21.0 5.21.1 5.21.2 5.21.3 5.22.0 5.22.1 5.22.2 5.22.3 5.22.4 5.23.0 5.23.1 5.23.2 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.7.0 5.7.1 5.8.0 5.8.1 5.9.0 3.0.0-beta.15 3.7.1 3.0.0-beta.16 3.7.2 3.0.0-beta.17 3.7.3 3.0.0-beta.18 3.7.4 3.0.0-beta.19 3.7.5 3.0.0-beta.2 3.7.6 3.0.0-beta.20 3.7.8 3.0.0-beta.21 3.70.0 3.0.0-beta.22 3.71.0 3.0.0-beta.23 3.71.1 3.0.0-beta.23.1 3.71.2 3.0.0-beta.23.2 3.71.3 3.0.0-beta.24 3.72.0 3.0.0-beta.25 3.73.0 3.0.0-beta.26 3.73.1 3.0.0-beta.27 3.73.2 3.0.0-beta.28 3.74.0 3.0.0-beta.29 3.74.1 3.0.0-beta.3 3.74.2 3.0.0-beta.30 3.74.3 3.0.0-beta.31 3.75.0 3.0.0-beta.32 3.75.1 3.0.0-beta.33 3.76.0 3.0.0-beta.33.1 3.77.0 3.0.0-beta.34.0.0 3.77.1 3.0.0-beta.36.0.0 3.78.0 3.0.0-beta.36.0.1 3.79.0 3.0.0-beta.36.2.0 3.8 3.0.0-beta.36.3.0 3.8.1 3.0.0-beta.36.3.1 3.8.2 3.0.0-beta.37.0.0 3.8.3 3.0.0-beta.4 3.8.4 3.0.0-beta.5 3.8.5 3.0.0-beta.6 3.8.6 3.0.0-beta.7 3.80.0 3.0.0-beta.7.1 3.81.0 3.0.0-beta.8 3.82.0 3.0.0-beta.9 3.83.0 3.0.0-rc.1.0.0 3.84.0 3.0.0-rc.1.0.1 3.84.1 3.0.0-rc.1.0.2 3.85.0 3.0.0-rc.1.0.3 3.85.1 3.0.0-rc.1.0.4 3.86.0 3.0.0-rc.2.0.0 3.87.0 3.0.0-rc.2.0.1 3.87.1 3.0.0-rc.2.0.2 3.87.2 3.0.0-rc.2.0.3 3.88.0 3.0.1 3.88.1 3.0.2 3.88.2 3.0.3 3.89.0 3.0.4 3.89.1 3.0.5 3.89.2 3.0.6 3.89.3 3.0.7 3.89.4 3.0.8 3.9.0 3.0.9 3.9.1 3.1.0 3.90.0 3.10 3.90.1 3.10.1 3.90.2 3.100.0 3.91.0 3.100.1 3.91.1 3.100.2 3.92.0 3.101.0 3.92.1 3.101.1 3.93.0 3.102.0 3.93.1 3.102.1 3.94.0 3.103.0 3.95.0 3.103.1 3.95.1 3.11.0 3.96.0 3.11.1 3.96.1 3.11.2 3.97.0 3.11.3 3.98.0 3.11.4 3.98.1 3.11.5 3.99.0 3.12.0 3.99.1 3.12.1 4.0.0 3.13.0 4.0.1 3.14.0 4.1.0 3.14.1 4.1.1 3.15.0 4.10.0 3.16.0 4.11.0 3.16.1 4.11.1 3.16.2 4.12.0 3.16.3 4.12.1 3.17.0 4.12.2 3.17.1 4.13.0 3.17.2 4.14.0 3.18.0 4.15.0 3.18.1 4.16.0 3.18.2 4.17.0 3.19.0 4.17.1 3.19.1 4.18.0 3.19.2 4.18.1 3.19.3 4.19.0 3.2.0 4.2.0 3.2.1 4.20.0 3.2.2 4.20.1 3.2.3 4.20.2 3.2.4 4.21.0 3.2.5 4.22.0 3.20.0 4.22.1 3.21.0 4.22.2 3.21.1 4.23.0 3.22.0 4.24.0 3.23.0 4.25.0 3.23.1 4.26.0 3.23.2 4.26.1 3.24.0 4.27.0 3.25.0 4.28.0 3.25.1 4.29.0 3.26.0 4.3.0 3.26.1 4.3.1 3.27.0 4.30.0 3.28.0 4.31.0 3.29.0 4.31.1 3.3.0 4.32.0 3.3.1 4.33.0 3.3.2 4.34.0 3.3.3 4.35.0 3.3.4 4.35.1 3.3.5 4.36.0 3.3.6 4.37.0 3.30.0 4.38.0 3.31.0 4.39.0 3.31.1 4.4.0 3.32.0 4.40.0 3.32.1 4.41.0 3.32.2 4.41.1 3.33.0 4.41.2 3.34.0 4.41.3 3.34.1 4.42.0 3.34.2 4.42.1 3.34.3 3.34.4 3.35.0 3.35.1 3.35.3 3.35.4 3.36.0 3.37.0 3.37.1 3.37.2 3.37.3 3.38.0 3.38.1 3.39.0 3.39.1 3.39.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.40.0 3.40.1 3.41.0 3.41.1 3.41.2 3.42.0 3.42.1 3.42.2 3.42.3 3.43.0 3.43.1 3.44.0 3.45.0 3.45.1 3.46.0 3.46.1 3.46.10 3.46.11 3.46.12 3.46.13 3.46.14 3.46.2 3.46.3 3.46.4 3.46.5 3.46.6 3.46.7 3.46.8 3.46.9 3.47.0 3.47.1 3.47.10 3.47.11 3.47.2 3.47.3 3.47.5 3.47.6 3.47.7 3.47.9 3.48.0 3.48.1 3.49.0 3.49.1 3.5.0 3.5.1 3.50.0 3.51.0 3.51.1 3.51.2 3.52.0 3.53.0 3.54.0 3.54.1 3.54.2 3.54.3 3.55.0 3.55.1 3.56.0 3.56.1 3.56.2 3.57.0 3.57.1 3.58.0 3.59.0 3.59.1 3.59.2 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.60.0 3.60.1 3.60.10 3.60.11 3.60.12 3.60.2 3.60.3 3.60.4 3.60.6 3.60.7 3.60.8 3.60.9 3.61.0 3.62.0 3.62.1 3.63.0 3.64.0 3.64.1 3.64.2 3.64.3 3.65.0 trunk 3.65.1 3.0.0 3.66.0 3.0.0-beta.1 3.67.0 3.0.0-beta.10 3.67.1 3.0.0-beta.11 3.68.0 3.0.0-beta.12 3.69.0 3.0.0-beta.13 3.69.1 3.0.0-beta.14 3.7.0
mailpoet / lib / Analytics / Reporter.php
mailpoet / lib / Analytics Last commit date
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