Automations
1 year ago
KeyCheck
1 year ago
SendingQueue
4 days ago
StatsNotifications
2 months ago
AuthorizedSendingEmailsCheck.php
3 years ago
BackfillEngagementData.php
1 year ago
Bounce.php
4 days ago
BounceTaskSubscribersCleanup.php
1 month ago
BulkConfirmationEmailResend.php
2 months ago
ExportFilesCleanup.php
2 months ago
InactiveSubscribersMaintenance.php
2 weeks ago
LogCleanup.php
10 months ago
Mixpanel.php
9 months ago
NewsletterTemplateThumbnails.php
1 year ago
ReEngagementEmailsScheduler.php
1 year ago
Scheduler.php
2 months ago
SendingQueueBodyCleanup.php
2 months ago
SendingTaskSubscribersCleanup.php
2 months ago
SimpleWorker.php
1 year ago
StatisticsExport.php
2 months ago
SubscriberLimitNotificationWorker.php
2 months ago
SubscriberLinkTokens.php
1 year ago
SubscribersCountCacheRecalculation.php
2 weeks ago
SubscribersEngagementScore.php
3 days ago
SubscribersLastEngagement.php
2 months ago
SubscribersSegmentsCountSync.php
2 weeks ago
SubscribersStatsReport.php
1 year ago
Tracks.php
9 months ago
UnconfirmedSubscribersCleanup.php
2 months ago
UnsubscribeTokens.php
1 month ago
WooCommercePastOrders.php
1 year ago
WooCommerceSync.php
3 years ago
WorkersFactory.php
2 weeks ago
index.php
3 years ago
Mixpanel.php
65 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Cron\Workers; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Analytics\Analytics; |
| 9 | use MailPoet\Entities\ScheduledTaskEntity; |
| 10 | use Mixpanel as MixpanelLibrary; |
| 11 | |
| 12 | class Mixpanel extends SimpleWorker { |
| 13 | |
| 14 | const PRODUCTION_PROJECT_ID = '8cce373b255e5a76fb22d57b85db0c92'; |
| 15 | |
| 16 | /** @var Analytics */ |
| 17 | private $analytics; |
| 18 | |
| 19 | const TASK_TYPE = 'mixpanel'; |
| 20 | |
| 21 | private MixpanelLibrary $mixpanel; |
| 22 | |
| 23 | public function __construct( |
| 24 | Analytics $analytics |
| 25 | ) { |
| 26 | parent::__construct(); |
| 27 | $this->analytics = $analytics; |
| 28 | $this->mixpanel = MixpanelLibrary::getInstance(self::PRODUCTION_PROJECT_ID); |
| 29 | $this->mixpanel->register('Platform', 'Plugin'); |
| 30 | } |
| 31 | |
| 32 | public function processTaskStrategy(ScheduledTaskEntity $task, $timer) { |
| 33 | return $this->maybeReportAnalyticsToMixpanel(); |
| 34 | } |
| 35 | |
| 36 | public function maybeReportAnalyticsToMixpanel(): bool { |
| 37 | if (!$this->analytics->shouldSendToMixpanel()) { |
| 38 | return true; |
| 39 | } |
| 40 | return $this->reportAnalyticsToMixpanel(); |
| 41 | } |
| 42 | |
| 43 | public function reportAnalyticsToMixpanel(): bool { |
| 44 | $publicId = $this->analytics->getPublicId(); |
| 45 | |
| 46 | if (strlen($publicId) < 1) { |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | $data = $this->analytics->getAnalyticsData(); |
| 51 | |
| 52 | $this->mixpanel->identify($publicId); |
| 53 | $this->mixpanel->people->set($publicId, $data); |
| 54 | $this->mixpanel->track('User Properties', $data); |
| 55 | |
| 56 | $this->analytics->recordMixpanelDataSent(); |
| 57 | |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | public function getNextRunDate() { |
| 62 | return $this->analytics->getNextSendDateForMixpanel()->addMinutes(rand(0, 59)); |
| 63 | } |
| 64 | } |
| 65 |