Exclude non-content related clicks from segment clicked any
[MAILPOET-3223]
This commit is contained in:
committed by
Veljko V
parent
be7437ed5c
commit
a6dcd7a22c
@@ -3,6 +3,7 @@
|
|||||||
namespace MailPoet\Segments\DynamicSegments\Filters;
|
namespace MailPoet\Segments\DynamicSegments\Filters;
|
||||||
|
|
||||||
use MailPoet\Entities\DynamicSegmentFilterEntity;
|
use MailPoet\Entities\DynamicSegmentFilterEntity;
|
||||||
|
use MailPoet\Entities\NewsletterLinkEntity;
|
||||||
use MailPoet\Entities\StatisticsClickEntity;
|
use MailPoet\Entities\StatisticsClickEntity;
|
||||||
use MailPoet\Entities\StatisticsNewsletterEntity;
|
use MailPoet\Entities\StatisticsNewsletterEntity;
|
||||||
use MailPoet\Entities\StatisticsOpenEntity;
|
use MailPoet\Entities\StatisticsOpenEntity;
|
||||||
@@ -47,6 +48,7 @@ class EmailAction implements Filter {
|
|||||||
|
|
||||||
$statsSentTable = $this->entityManager->getClassMetadata(StatisticsNewsletterEntity::class)->getTableName();
|
$statsSentTable = $this->entityManager->getClassMetadata(StatisticsNewsletterEntity::class)->getTableName();
|
||||||
$subscribersTable = $this->entityManager->getClassMetadata(SubscriberEntity::class)->getTableName();
|
$subscribersTable = $this->entityManager->getClassMetadata(SubscriberEntity::class)->getTableName();
|
||||||
|
$newsletterLinksTable = $this->entityManager->getClassMetadata(NewsletterLinkEntity::class)->getTableName();
|
||||||
if (in_array($action, self::CLICK_ACTIONS, true)) {
|
if (in_array($action, self::CLICK_ACTIONS, true)) {
|
||||||
$statsTable = $this->entityManager->getClassMetadata(StatisticsClickEntity::class)->getTableName();
|
$statsTable = $this->entityManager->getClassMetadata(StatisticsClickEntity::class)->getTableName();
|
||||||
} else {
|
} else {
|
||||||
@@ -69,11 +71,22 @@ class EmailAction implements Filter {
|
|||||||
)->setParameter('newsletter' . $filter->getId(), $newsletterId);
|
)->setParameter('newsletter' . $filter->getId(), $newsletterId);
|
||||||
$where .= ' AND stats.id IS NULL';
|
$where .= ' AND stats.id IS NULL';
|
||||||
} else if ($action === self::ACTION_CLICKED_ANY) {
|
} else if ($action === self::ACTION_CLICKED_ANY) {
|
||||||
|
$excludedLinks = [
|
||||||
|
'[link:subscription_unsubscribe_url]',
|
||||||
|
'[link:subscription_instant_unsubscribe_url]',
|
||||||
|
'[link:newsletter_view_in_browser_url]',
|
||||||
|
'[link:subscription_manage_url]',
|
||||||
|
];
|
||||||
$queryBuilder = $queryBuilder->innerJoin(
|
$queryBuilder = $queryBuilder->innerJoin(
|
||||||
$subscribersTable,
|
$subscribersTable,
|
||||||
$statsTable,
|
$statsTable,
|
||||||
'stats',
|
'stats',
|
||||||
"stats.subscriber_id = $subscribersTable.id"
|
"stats.subscriber_id = $subscribersTable.id"
|
||||||
|
)->innerJoin(
|
||||||
|
'stats',
|
||||||
|
$newsletterLinksTable,
|
||||||
|
'newsletterLinks',
|
||||||
|
"stats.link_id = newsletterLinks.id AND newsletterLinks.URL NOT IN ('" . join("', '", $excludedLinks) . "')"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$queryBuilder = $queryBuilder->innerJoin(
|
$queryBuilder = $queryBuilder->innerJoin(
|
||||||
|
@@ -55,19 +55,7 @@ class EmailActionTest extends \MailPoetTest {
|
|||||||
$this->createStatisticsOpens($this->subscriberOpenedClicked);
|
$this->createStatisticsOpens($this->subscriberOpenedClicked);
|
||||||
$this->createStatisticsOpens($this->subscriberOpenedNotClicked);
|
$this->createStatisticsOpens($this->subscriberOpenedNotClicked);
|
||||||
|
|
||||||
|
$this->addClickedToLink('http://example.com', $this->newsletter, $this->subscriberOpenedClicked);
|
||||||
$link = new NewsletterLinkEntity($this->newsletter, $queue, 'http://example.com', 'asdfgh');
|
|
||||||
$this->entityManager->persist($link);
|
|
||||||
$this->entityManager->flush();
|
|
||||||
$click = new StatisticsClickEntity(
|
|
||||||
$this->newsletter,
|
|
||||||
$queue,
|
|
||||||
$this->subscriberOpenedClicked,
|
|
||||||
$link,
|
|
||||||
1
|
|
||||||
);
|
|
||||||
$this->entityManager->persist($click);
|
|
||||||
$this->entityManager->flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetOpened() {
|
public function testGetOpened() {
|
||||||
@@ -140,6 +128,14 @@ class EmailActionTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testGetClickedAnyLink() {
|
public function testGetClickedAnyLink() {
|
||||||
|
$subscriberClickedExcludedLinks = $this->createSubscriber('opened_clicked_excluded@example.com');
|
||||||
|
$this->createStatsNewsletter($subscriberClickedExcludedLinks);
|
||||||
|
$this->createStatisticsOpens($subscriberClickedExcludedLinks);
|
||||||
|
$this->addClickedToLink('[link:subscription_unsubscribe_url]', $this->newsletter, $subscriberClickedExcludedLinks);
|
||||||
|
$this->addClickedToLink('[link:subscription_instant_unsubscribe_url]', $this->newsletter, $subscriberClickedExcludedLinks);
|
||||||
|
$this->addClickedToLink('[link:newsletter_view_in_browser_url]', $this->newsletter, $subscriberClickedExcludedLinks);
|
||||||
|
$this->addClickedToLink('[link:subscription_manage_url]', $this->newsletter, $subscriberClickedExcludedLinks);
|
||||||
|
|
||||||
$segmentFilter = $this->getSegmentFilter(EmailAction::ACTION_CLICKED_ANY);
|
$segmentFilter = $this->getSegmentFilter(EmailAction::ACTION_CLICKED_ANY);
|
||||||
$statement = $this->emailAction->apply($this->getQueryBuilder(), $segmentFilter)->execute();
|
$statement = $this->emailAction->apply($this->getQueryBuilder(), $segmentFilter)->execute();
|
||||||
$this->assertInstanceOf(Statement::class, $statement);
|
$this->assertInstanceOf(Statement::class, $statement);
|
||||||
@@ -234,6 +230,23 @@ class EmailActionTest extends \MailPoetTest {
|
|||||||
return $open;
|
return $open;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addClickedToLink(string $link, NewsletterEntity $newsletter, SubscriberEntity $subscriber) {
|
||||||
|
$queue = $newsletter->getLatestQueue();
|
||||||
|
$this->assertInstanceOf(SendingQueueEntity::class, $queue);
|
||||||
|
$link = new NewsletterLinkEntity($this->newsletter, $queue, $link, uniqid());
|
||||||
|
$this->entityManager->persist($link);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$click = new StatisticsClickEntity(
|
||||||
|
$newsletter,
|
||||||
|
$queue,
|
||||||
|
$subscriber,
|
||||||
|
$link,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
$this->entityManager->persist($click);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
public function _after() {
|
public function _after() {
|
||||||
$this->cleanData();
|
$this->cleanData();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user