Track opens, clicks, purchases, and page views
MAILPOET-4998
This commit is contained in:
committed by
Aschepikov
parent
1e82378df2
commit
0e9b96d0b7
@@ -340,7 +340,7 @@ class SubscribersRepository extends Repository {
|
||||
}
|
||||
|
||||
public function maybeUpdateLastEngagement(SubscriberEntity $subscriberEntity): void {
|
||||
$now = CarbonImmutable::createFromTimestamp((int)$this->wp->currentTime('timestamp'));
|
||||
$now = $this->getCurrentDateTime();
|
||||
// Do not update engagement if was recently updated to avoid unnecessary updates in DB
|
||||
if ($subscriberEntity->getLastEngagementAt() && $subscriberEntity->getLastEngagementAt() > $now->subMinute()) {
|
||||
return;
|
||||
@@ -350,6 +350,50 @@ class SubscribersRepository extends Repository {
|
||||
$this->flush();
|
||||
}
|
||||
|
||||
public function maybeUpdateLastOpenAt(SubscriberEntity $subscriberEntity): void {
|
||||
$now = $this->getCurrentDateTime();
|
||||
// Avoid unnecessary DB calls
|
||||
if ($subscriberEntity->getLastOpenAt() && $subscriberEntity->getLastOpenAt() > $now->subMinute()) {
|
||||
return;
|
||||
}
|
||||
$subscriberEntity->setLastOpenAt($now);
|
||||
$subscriberEntity->setLastEngagementAt($now);
|
||||
$this->flush();
|
||||
}
|
||||
|
||||
public function maybeUpdateLastClickAt(SubscriberEntity $subscriberEntity): void {
|
||||
$now = $this->getCurrentDateTime();
|
||||
// Avoid unnecessary DB calls
|
||||
if ($subscriberEntity->getLastClickAt() && $subscriberEntity->getLastClickAt() > $now->subMinute()) {
|
||||
return;
|
||||
}
|
||||
$subscriberEntity->setLastClickAt($now);
|
||||
$subscriberEntity->setLastEngagementAt($now);
|
||||
$this->flush();
|
||||
}
|
||||
|
||||
public function maybeUpdateLastPurchaseAt(SubscriberEntity $subscriberEntity): void {
|
||||
$now = $this->getCurrentDateTime();
|
||||
// Avoid unnecessary DB calls
|
||||
if ($subscriberEntity->getLastPurchaseAt() && $subscriberEntity->getLastPurchaseAt() > $now->subMinute()) {
|
||||
return;
|
||||
}
|
||||
$subscriberEntity->setLastPurchaseAt($now);
|
||||
$subscriberEntity->setLastEngagementAt($now);
|
||||
$this->flush();
|
||||
}
|
||||
|
||||
public function maybeUpdateLastPageViewAt(SubscriberEntity $subscriberEntity): void {
|
||||
$now = $this->getCurrentDateTime();
|
||||
// Avoid unnecessary DB calls
|
||||
if ($subscriberEntity->getLastPageViewAt() && $subscriberEntity->getLastPageViewAt() > $now->subMinute()) {
|
||||
return;
|
||||
}
|
||||
$subscriberEntity->setLastPageViewAt($now);
|
||||
$subscriberEntity->setLastEngagementAt($now);
|
||||
$this->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @return string[]
|
||||
@@ -501,4 +545,8 @@ class SubscribersRepository extends Repository {
|
||||
|
||||
return count($subscribers);
|
||||
}
|
||||
|
||||
private function getCurrentDateTime(): CarbonImmutable {
|
||||
return CarbonImmutable::createFromTimestamp((int)$this->wp->currentTime('timestamp'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user