Add method of tracking when tracking unsubscriptions
[MAILPOET-4733]
This commit is contained in:
@@ -22,6 +22,9 @@ class StatisticsUnsubscribeEntity {
|
||||
const SOURCE_ORDER_CHECKOUT = 'order_checkout';
|
||||
const SOURCE_AUTOMATION = 'automation';
|
||||
|
||||
const METHOD_LINK = 'link';
|
||||
const METHOD_ONE_CLICK = 'one_click';
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="MailPoet\Entities\NewsletterEntity")
|
||||
* @ORM\JoinColumn(name="newsletter_id", referencedColumnName="id")
|
||||
@@ -115,6 +118,13 @@ class StatisticsUnsubscribeEntity {
|
||||
return $this->meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
*/
|
||||
public function setMethod(string $method) {
|
||||
$this->method = $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace MailPoet\Router\Endpoints;
|
||||
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Entities\StatisticsUnsubscribeEntity;
|
||||
use MailPoet\Subscription as UserSubscription;
|
||||
use MailPoet\Util\Request;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
@@ -102,7 +103,7 @@ class Subscription {
|
||||
exit;
|
||||
} else {
|
||||
$subscription = $this->initSubscriptionPage(UserSubscription\Pages::ACTION_UNSUBSCRIBE, $data);
|
||||
$subscription->unsubscribe();
|
||||
$subscription->unsubscribe(StatisticsUnsubscribeEntity::METHOD_LINK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +120,6 @@ class Subscription {
|
||||
return;
|
||||
}
|
||||
$subscription = $this->initSubscriptionPage(UserSubscription\Pages::ACTION_UNSUBSCRIBE, $data);
|
||||
$subscription->unsubscribe();
|
||||
$subscription->unsubscribe(StatisticsUnsubscribeEntity::METHOD_ONE_CLICK);
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,13 @@ class Unsubscribes {
|
||||
$this->subscribersRepository = $subscribersRepository;
|
||||
}
|
||||
|
||||
public function track(int $subscriberId, string $source, int $queueId = null, string $meta = null) {
|
||||
public function track(
|
||||
int $subscriberId,
|
||||
string $source,
|
||||
int $queueId = null,
|
||||
string $meta = null,
|
||||
string $method = 'unknown'
|
||||
) {
|
||||
$queue = null;
|
||||
$statistics = null;
|
||||
if ($queueId) {
|
||||
@@ -65,6 +71,7 @@ class Unsubscribes {
|
||||
$statistics->setMeta($meta);
|
||||
}
|
||||
$statistics->setSource($source);
|
||||
$statistics->setMethod($method);
|
||||
$this->statisticsUnsubscribesRepository->persist($statistics);
|
||||
$this->statisticsUnsubscribesRepository->flush();
|
||||
}
|
||||
|
@@ -227,7 +227,7 @@ class Pages {
|
||||
}
|
||||
}
|
||||
|
||||
public function unsubscribe() {
|
||||
public function unsubscribe(string $method): void {
|
||||
if (
|
||||
!$this->isPreview()
|
||||
&& ($this->subscriber !== null)
|
||||
@@ -237,7 +237,9 @@ class Pages {
|
||||
$this->unsubscribesTracker->track(
|
||||
(int)$this->subscriber->id,
|
||||
StatisticsUnsubscribeEntity::SOURCE_NEWSLETTER,
|
||||
(int)$this->data['queueId']
|
||||
(int)$this->data['queueId'],
|
||||
null,
|
||||
$method
|
||||
);
|
||||
}
|
||||
$this->subscriber->setStatus(SubscriberEntity::STATUS_UNSUBSCRIBED);
|
||||
|
@@ -164,7 +164,7 @@ class PagesTest extends \MailPoetTest {
|
||||
$this->createSubscriberSegment($segment);
|
||||
|
||||
$pages = $this->getPages()->init($action = 'unsubscribe', $this->testData);
|
||||
$pages->unsubscribe();
|
||||
$pages->unsubscribe(StatisticsUnsubscribeEntity::METHOD_LINK);
|
||||
|
||||
$updatedSubscriber = $this->subscribersRepository->findOneById($this->subscriber->getId());
|
||||
$this->assertInstanceOf(SubscriberEntity::class, $updatedSubscriber);
|
||||
@@ -181,7 +181,7 @@ class PagesTest extends \MailPoetTest {
|
||||
$this->testData['queueId'] = 1;
|
||||
SettingsController::getInstance()->set('tracking.level', TrackingConfig::LEVEL_PARTIAL);
|
||||
$pages = $this->getPages(null, $unsubscribesMock)->init($action = 'unsubscribe', $this->testData);
|
||||
$pages->unsubscribe();
|
||||
$pages->unsubscribe(StatisticsUnsubscribeEntity::METHOD_LINK);
|
||||
}
|
||||
|
||||
public function testItDontTrackUnsubscribeWhenTrackingIsDisabled() {
|
||||
@@ -189,13 +189,13 @@ class PagesTest extends \MailPoetTest {
|
||||
$this->testData['queueId'] = 1;
|
||||
SettingsController::getInstance()->set('tracking.level', TrackingConfig::LEVEL_BASIC);
|
||||
$pages = $this->getPages(null, $unsubscribesMock)->init($action = 'unsubscribe', $this->testData);
|
||||
$pages->unsubscribe();
|
||||
$pages->unsubscribe(StatisticsUnsubscribeEntity::METHOD_LINK);
|
||||
}
|
||||
|
||||
public function testItDoesntUnsubscribeWhenPreviewing() {
|
||||
$this->testData['preview'] = 1;
|
||||
$pages = $this->getPages()->init($action = 'unsubscribe', $this->testData);
|
||||
$pages->unsubscribe();
|
||||
$pages->unsubscribe(StatisticsUnsubscribeEntity::METHOD_LINK);
|
||||
|
||||
$updatedSubscriber = $this->subscribersRepository->findOneById($this->subscriber->getId());
|
||||
$this->assertInstanceOf(SubscriberEntity::class, $updatedSubscriber);
|
||||
|
Reference in New Issue
Block a user