Improve list level unsubscribe stats
We want to show admin how many subscribers subscribed to a list and how many unsubscribed within last 30 days so that they see the change. If someone subscribed and also unsubscribed within those 30 days we skip him. We don't have data to detect they were really subscribed at some point. [MAILPOET-4828]
This commit is contained in:
committed by
Aschepikov
parent
e3897fa04e
commit
9e157da66d
@@ -432,6 +432,7 @@ class SubscribersRepository extends Repository {
|
|||||||
->join('ss.subscriber', 's')
|
->join('ss.subscriber', 's')
|
||||||
->join('ss.segment', 'seg')
|
->join('ss.segment', 'seg')
|
||||||
->where('ss.updatedAt > :date')
|
->where('ss.updatedAt > :date')
|
||||||
|
->where('ss.createdAt < :date') // ignore those who subscribed and unsubscribed within the date range
|
||||||
->andWhere('s.status = :status')
|
->andWhere('s.status = :status')
|
||||||
->andWhere('ss.status = :segment_status')
|
->andWhere('ss.status = :segment_status')
|
||||||
->andWhere('s.deletedAt IS NULL')
|
->andWhere('s.deletedAt IS NULL')
|
||||||
|
@@ -312,12 +312,13 @@ class HomepageDataControllerTest extends \MailPoetTest {
|
|||||||
$segment = (new Segment())->withName('Segment')->create();
|
$segment = (new Segment())->withName('Segment')->create();
|
||||||
// Unsubscribed 29 days ago - only this one counts as unsubscribed on list level
|
// Unsubscribed 29 days ago - only this one counts as unsubscribed on list level
|
||||||
$newUnsubscribed = (new Subscriber())
|
$newUnsubscribed = (new Subscriber())
|
||||||
->withCreatedAt($twentyNineDaysAgo)
|
->withCreatedAt($thirtyOneDaysAgo)
|
||||||
->withStatus(SubscriberEntity::STATUS_UNSUBSCRIBED)
|
->withStatus(SubscriberEntity::STATUS_UNSUBSCRIBED)
|
||||||
->withSegments([$segment])
|
->withSegments([$segment])
|
||||||
->create();
|
->create();
|
||||||
$subscriberSegment = $newUnsubscribed->getSubscriberSegments()->first();
|
$subscriberSegment = $newUnsubscribed->getSubscriberSegments()->first();
|
||||||
$this->assertInstanceOf(SubscriberSegmentEntity::class, $subscriberSegment);
|
$this->assertInstanceOf(SubscriberSegmentEntity::class, $subscriberSegment);
|
||||||
|
$subscriberSegment->setCreatedAt($thirtyOneDaysAgo);
|
||||||
$subscriberSegment->setUpdatedAt($twentyNineDaysAgo);
|
$subscriberSegment->setUpdatedAt($twentyNineDaysAgo);
|
||||||
$subscriberSegment->setStatus(SubscriberEntity::STATUS_UNSUBSCRIBED);
|
$subscriberSegment->setStatus(SubscriberEntity::STATUS_UNSUBSCRIBED);
|
||||||
// Unsubscribed 31 days ago - ignored because unsubscribed too far in the past
|
// Unsubscribed 31 days ago - ignored because unsubscribed too far in the past
|
||||||
@@ -328,6 +329,7 @@ class HomepageDataControllerTest extends \MailPoetTest {
|
|||||||
->create();
|
->create();
|
||||||
$subscriberSegment = $newUnsubscribed->getSubscriberSegments()->first();
|
$subscriberSegment = $newUnsubscribed->getSubscriberSegments()->first();
|
||||||
$this->assertInstanceOf(SubscriberSegmentEntity::class, $subscriberSegment);
|
$this->assertInstanceOf(SubscriberSegmentEntity::class, $subscriberSegment);
|
||||||
|
$subscriberSegment->setCreatedAt($thirtyOneDaysAgo);
|
||||||
$subscriberSegment->setUpdatedAt($thirtyOneDaysAgo);
|
$subscriberSegment->setUpdatedAt($thirtyOneDaysAgo);
|
||||||
$subscriberSegment->setStatus(SubscriberEntity::STATUS_UNSUBSCRIBED);
|
$subscriberSegment->setStatus(SubscriberEntity::STATUS_UNSUBSCRIBED);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user