| @@ -49,17 +49,21 @@ | ||
| 49 | 49 | |
| 50 | 50 | $userStatClass = new UserStatClass(); |
| 51 | 51 | $userStat = $userStatClass->getOneByMailAndUserId($mailId, $userId); |
| 52 | 52 | |
| 53 | - if (empty($mail) || empty($userStat) || acym_getTimeFromUTCDate($userStat->send_date) > time() - 20 || acym_isRobot()) { | |
| 54 | - acym_redirect($this->resolveSubscriberTags($urlObject->url, $userId)); | |
| 53 | + // The mail has been deleted, or we didn't send this email to this user, or it's a bot | |
| 54 | + $delay = $this->config->get('tracking_delay', 0); | |
| 55 | + if (empty($mail) || empty($userStat) || acym_isRobot() || (!empty($delay) && acym_getTimeFromUTCDate($userStat->send_date) > time() - $delay)) { | |
| 56 | + acym_redirect($this->resolveSubscriberTags($urlObject->url, $userId), '', 'message', false); | |
| 55 | 57 | } |
| 56 | 58 | |
| 59 | + $anonymousStats = !empty($this->config->get('anonymous_stats', 0)); | |
| 60 | + | |
| 57 | 61 | $urlClick = new \stdClass(); |
| 58 | 62 | $urlClick->mail_id = $mailId; |
| 59 | 63 | $urlClick->url_id = $urlObject->id; |
| 60 | 64 | $urlClick->click = 1; |
| 61 | - $urlClick->user_id = $userId; | |
| 65 | + $urlClick->user_id = $anonymousStats ? 0 : $userId; | |
| 62 | 66 | $urlClick->date_click = acym_date('now', 'Y-m-d H:i:s', false); |
| 63 | 67 | |
| 64 | 68 | $mailStatClass = new MailStatClass(); |
| 65 | 69 | $urlClickClass = new UrlClickClass(); |
| @@ -64,26 +68,42 @@ | ||
| 64 | 68 | $mailStatClass = new MailStatClass(); |
| 65 | 69 | $urlClickClass = new UrlClickClass(); |
| 66 | 70 | $urlClickClass->save($urlClick); |
| 67 | 71 | |
| 68 | - if (empty($userStat->open)) { | |
| 69 | - $userStatToInsert = new \stdClass(); | |
| 70 | - $userStatToInsert->user_id = $userId; | |
| 71 | - $userStatToInsert->mail_id = $mailId; | |
| 72 | - $userStatToInsert->open = 1; | |
| 73 | - $userStatToInsert->open_date = acym_date('now', 'Y-m-d H:i:s', false); | |
| 74 | - $userStatClass->save($userStatToInsert); | |
| 72 | + UserStatClass::triggerActivity('user_click', $userId, $mailId); | |
| 75 | 73 | |
| 74 | + if (!$anonymousStats) { | |
| 75 | + if (empty($userStat->open)) { | |
| 76 | + $userStatToInsert = new \stdClass(); | |
| 77 | + $userStatToInsert->user_id = $userId; | |
| 78 | + $userStatToInsert->mail_id = $mailId; | |
| 79 | + $userStatToInsert->open = 1; | |
| 80 | + $userStatToInsert->open_date = acym_date('now', 'Y-m-d H:i:s', false); | |
| 81 | + $userStatClass->save($userStatToInsert); | |
| 82 | + | |
| 83 | + $mailStat = new \stdClass(); | |
| 84 | + $mailStat->mail_id = $mailId; | |
| 85 | + $mailStat->open_unique = 1; | |
| 86 | + $mailStat->open_total = 1; | |
| 87 | + $mailStatClass->save($mailStat); | |
| 88 | + | |
| 89 | + UserStatClass::triggerActivity('user_open', $userId, $mailId); | |
| 90 | + } | |
| 91 | + | |
| 92 | + $clickStats = $urlClickClass->getOneByMailIdAndUserId($mailId, $userId); | |
| 93 | + $mailStatClass->incrementClicks($mailId, $clickStats->click == 1); | |
| 94 | + } else { | |
| 95 | + $mailStatClass->incrementClicks($mailId, true); | |
| 96 | + | |
| 97 | + // Anonymous mode tracks totals only and keeps no per-recipient open state, so this is not deduplicated. | |
| 76 | 98 | $mailStat = new \stdClass(); |
| 77 | 99 | $mailStat->mail_id = $mailId; |
| 78 | 100 | $mailStat->open_unique = 1; |
| 79 | 101 | $mailStat->open_total = 1; |
| 80 | 102 | $mailStatClass->save($mailStat); |
| 103 | + $mailStatClass->incrementDetail($mailId, 'open_time', acym_date('now', 'Y-m-d H', false).':00:00'); | |
| 81 | 104 | } |
| 82 | 105 | |
| 83 | - $clickStats = $urlClickClass->getOneByMailIdAndUserId($mailId, $userId); | |
| 84 | - $mailStatClass->incrementClicks($mailId, $clickStats->click == 1); | |
| 85 | - | |
| 86 | 106 | $userClass = new UserClass(); |
| 87 | 107 | $subscriber = $userClass->getOneById($userId); |
| 88 | 108 | if (!empty($subscriber)) { |
| 89 | 109 | $subscriber->last_open_date = acym_date('now', 'Y-m-d H:i:s', false); |
| @@ -92,9 +112,9 @@ | ||
| 92 | 112 | $userClass->sendConf = false; |
| 93 | 113 | $userClass->save($subscriber); |
| 94 | 114 | } |
| 95 | 115 | |
| 96 | - acym_redirect($this->resolveSubscriberTags($urlObject->url, $userId)); | |
| 116 | + acym_redirect($this->resolveSubscriberTags($urlObject->url, $userId), '', 'message', false); | |
| 97 | 117 | } |
| 98 | 118 | |
| 99 | 119 | private function resolveSubscriberTags(string $url, int $userId): string |
| 100 | 120 | { |