diff --git a/mailpoet/lib/Analytics/Reporter.php b/mailpoet/lib/Analytics/Reporter.php index 5388736123..dd2c05cb93 100644 --- a/mailpoet/lib/Analytics/Reporter.php +++ b/mailpoet/lib/Analytics/Reporter.php @@ -175,9 +175,6 @@ class Reporter { 'Tracking level' => $this->settings->get('tracking.level', TrackingConfig::LEVEL_FULL), 'Premium key valid' => $this->servicesChecker->isPremiumKeyValid(), 'New subscriber notifications' => NewSubscriberNotificationMailer::isDisabled($this->settings->get(NewSubscriberNotificationMailer::SETTINGS_KEY)), - 'Number of standard newsletters sent in last 7 days' => $newsletters['sent_newsletters_7_days'], - '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'], 'Total number of standard newsletters sent' => $newsletters['sent_newsletters_count'], @@ -267,6 +264,7 @@ class Reporter { $result, $this->subscriberProperties(), $this->automationProperties(), + $this->getCampaignAnalyticsProperties(), $this->unsubscribeReporter->getProperties() ); if ($hasWc) { @@ -424,7 +422,7 @@ class Reporter { ]; } - public function getCampaignAnalyticsData(): array { + public function getCampaignAnalyticsProperties(): array { $matchingCampaignIds = [ 'Number of standard newsletters sent in last 7 days' => [], 'Number of standard newsletters sent in last 3 months' => [], @@ -799,7 +797,6 @@ class Reporter { } } } else { - $existingData = $processedResults[$campaignId]; if ($sendingInfo['segmentType'] === 'dynamic') { $processedResults[$campaignId]['sentToSegment'] = true; } diff --git a/mailpoet/tests/integration/Analytics/ReporterTest.php b/mailpoet/tests/integration/Analytics/ReporterTest.php index 97de45d672..88baf617ae 100644 --- a/mailpoet/tests/integration/Analytics/ReporterTest.php +++ b/mailpoet/tests/integration/Analytics/ReporterTest.php @@ -21,7 +21,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(2), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(8), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(89), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3']]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(1, $processed['Number of standard newsletters sent in last 7 days']); $this->assertEquals(2, $processed['Number of standard newsletters sent in last 30 days']); @@ -33,7 +33,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(2), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(8), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(89), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3']]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(1, $processed['Number of standard newsletters sent in last 7 days']); $this->assertEquals(2, $processed['Number of standard newsletters sent in last 30 days']); @@ -48,7 +48,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(2), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1', 'filterSegment' => ['theDataDoesNot' => 'matter']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(8), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2', 'filterSegment' => ['theDataDoesNot' => 'matter']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(89), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3', 'filterSegment' => ['theDataDoesNot' => 'matter']]]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(1, $processed['Number of standard newsletters sent in last 7 days']); $this->assertEquals(2, $processed['Number of standard newsletters sent in last 30 days']); @@ -66,7 +66,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(2), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(8), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(89), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3']]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(1, $processed['Number of post notification campaigns sent in the last 7 days']); $this->assertEquals(2, $processed['Number of post notification campaigns sent in the last 30 days']); @@ -78,7 +78,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(2), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(8), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(89), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3']]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(1, $processed['Number of post notification campaigns sent in the last 7 days']); $this->assertEquals(2, $processed['Number of post notification campaigns sent in the last 30 days']); @@ -93,7 +93,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(2), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1', 'filterSegment' => ['not' => 'relevant']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(8), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2', 'filterSegment' => ['not' => 'relevant']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(89), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3', 'filterSegment' => ['not' => 'relevant']]]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(1, $processed['Number of post notification campaigns sent in the last 7 days']); $this->assertEquals(2, $processed['Number of post notification campaigns sent in the last 30 days']); @@ -111,7 +111,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_RE_ENGAGEMENT, Carbon::now()->subDays(2), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_RE_ENGAGEMENT, Carbon::now()->subDays(8), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_RE_ENGAGEMENT, Carbon::now()->subDays(89), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3']]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(1, $processed['Number of re-engagement campaigns sent in the last 7 days']); $this->assertEquals(2, $processed['Number of re-engagement campaigns sent in the last 30 days']); @@ -123,7 +123,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_RE_ENGAGEMENT, Carbon::now()->subDays(2), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_RE_ENGAGEMENT, Carbon::now()->subDays(8), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_RE_ENGAGEMENT, Carbon::now()->subDays(89), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3']]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(1, $processed['Number of re-engagement campaigns sent in the last 7 days']); $this->assertEquals(2, $processed['Number of re-engagement campaigns sent in the last 30 days']); @@ -138,7 +138,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_RE_ENGAGEMENT, Carbon::now()->subDays(2), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1', 'filterSegment' => ['theDataDoesNot' => 'matter']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_RE_ENGAGEMENT, Carbon::now()->subDays(8), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2', 'filterSegment' => ['theDataDoesNot' => 'matter']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_RE_ENGAGEMENT, Carbon::now()->subDays(89), [$dynamicSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3', 'filterSegment' => ['theDataDoesNot' => 'matter']]]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(1, $processed['Number of re-engagement campaigns sent in the last 7 days']); $this->assertEquals(2, $processed['Number of re-engagement campaigns sent in the last 30 days']); @@ -155,7 +155,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_WELCOME, Carbon::now()->subDays(2), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_WELCOME, Carbon::now()->subDays(8), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_WELCOME, Carbon::now()->subDays(89), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3']]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertSame(1, $processed['Number of legacy welcome email campaigns sent in the last 7 days']); $this->assertSame(2, $processed['Number of legacy welcome email campaigns sent in the last 30 days']); $this->assertSame(3, $processed['Number of legacy welcome email campaigns sent in the last 3 months']); @@ -165,7 +165,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(2), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1', 'cart_product_ids' => ['123']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(8), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2', 'cart_product_ids' => ['1234']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(89), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3', 'cart_product_ids' => ['1235']]]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertSame(1, $processed['Number of legacy abandoned cart campaigns sent in the last 7 days']); $this->assertSame(2, $processed['Number of legacy abandoned cart campaigns sent in the last 30 days']); $this->assertSame(3, $processed['Number of legacy abandoned cart campaigns sent in the last 3 months']); @@ -175,7 +175,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(2), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1', 'orderedProducts' => ['123']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(8), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2', 'orderedProducts' => ['1234']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(89), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3', 'orderedProducts' => ['1235']]]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertSame(1, $processed['Number of legacy purchased product campaigns sent in the last 7 days']); $this->assertSame(2, $processed['Number of legacy purchased product campaigns sent in the last 30 days']); $this->assertSame(3, $processed['Number of legacy purchased product campaigns sent in the last 3 months']); @@ -185,7 +185,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(2), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1', 'orderedProductCategories' => ['123']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(8), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2', 'orderedProductCategories' => ['1234']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(89), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3', 'orderedProductCategories' => ['1235']]]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertSame(1, $processed['Number of legacy purchased in category campaigns sent in the last 7 days']); $this->assertSame(2, $processed['Number of legacy purchased in category campaigns sent in the last 30 days']); $this->assertSame(3, $processed['Number of legacy purchased in category campaigns sent in the last 3 months']); @@ -195,7 +195,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(2), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1', 'order_amount' => 123, 'order_date' => '2024-03-01', 'order_id' => '1']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(8), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2', 'order_amount' => 123, 'order_date' => '2024-03-01', 'order_id' => '2']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATIC, Carbon::now()->subDays(89), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3', 'order_amount' => 123, 'order_date' => '2024-03-01', 'order_id' => '3']]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertSame(1, $processed['Number of legacy first purchase campaigns sent in the last 7 days']); $this->assertSame(2, $processed['Number of legacy first purchase campaigns sent in the last 30 days']); $this->assertSame(3, $processed['Number of legacy first purchase campaigns sent in the last 3 months']); @@ -206,7 +206,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATION, Carbon::now()->subDays(8), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '2', 'orderedProductCategories' => ['1234']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_AUTOMATION, Carbon::now()->subDays(89), [], ['sendingQueueOptions' => ['meta' => ['campaignId' => '3', 'orderedProductCategories' => ['1235']]]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertSame(1, $processed['Number of automations campaigns sent in the last 7 days']); $this->assertSame(2, $processed['Number of automations campaigns sent in the last 30 days']); @@ -228,7 +228,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(8), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '8', 'filterSegment' => ['theDataDoesNot' => 'matter']]]]); $this->createSentNewsletter(NewsletterEntity::TYPE_STANDARD, Carbon::now()->subDays(89), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '9', 'filterSegment' => ['theDataDoesNot' => 'matter']]]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(3, $processed['Number of campaigns sent in the last 7 days']); $this->assertEquals(6, $processed['Number of campaigns sent in the last 30 days']); $this->assertEquals(9, $processed['Number of campaigns sent in the last 3 months']); @@ -247,7 +247,7 @@ class ReporterTest extends \MailPoetTest { $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(2), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(8), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1']]]); $this->createSentNewsletter(NewsletterEntity::TYPE_NOTIFICATION_HISTORY, Carbon::now()->subDays(89), [$defaultSegment], ['sendingQueueOptions' => ['meta' => ['campaignId' => '1']]]); - $processed = $this->reporter->getCampaignAnalyticsData(); + $processed = $this->reporter->getCampaignAnalyticsProperties(); $this->assertEquals(1, $processed['Number of post notification campaigns sent in the last 7 days']); $this->assertEquals(1, $processed['Number of post notification campaigns sent in the last 30 days']);