ConfirmationEmailTemplate
1 month ago
ImportExport
2 weeks ago
RestApi
3 days ago
Statistics
1 month ago
BulkActionController.php
3 days ago
BulkActionException.php
2 months ago
BulkConfirmationEmailResender.php
2 months ago
ConfirmationEmailCustomizer.php
2 months ago
ConfirmationEmailMailer.php
2 months ago
ConfirmationEmailResolver.php
2 months ago
EngagementDataBackfiller.php
2 months ago
InactiveSubscribersController.php
5 days ago
LinkTokens.php
2 months ago
NewSubscriberNotificationMailer.php
2 months ago
RequiredCustomFieldValidator.php
2 months ago
SegmentsCountRecalculator.php
2 weeks ago
Source.php
2 months ago
SubscriberActions.php
2 months ago
SubscriberCustomFieldRepository.php
3 years ago
SubscriberIPsRepository.php
2 years ago
SubscriberLimitNotificationEvaluator.php
2 months ago
SubscriberLimitNotificationMailer.php
2 months ago
SubscriberLimitNotificationScheduler.php
2 months ago
SubscriberListingRepository.php
2 weeks ago
SubscriberPersonalDataEraser.php
2 months ago
SubscriberSaveController.php
3 days ago
SubscriberSegmentRepository.php
2 weeks ago
SubscriberSubscribeController.php
2 weeks ago
SubscriberTagRepository.php
4 years ago
SubscribersCountsController.php
2 weeks ago
SubscribersEmailCountsController.php
2 weeks ago
SubscribersRepository.php
3 days ago
TrackingConsentController.php
5 days ago
index.php
3 years ago
TrackingConsentController.php
72 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Subscribers; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\SubscriberEntity; |
| 9 | use MailPoet\Settings\SettingsController; |
| 10 | use MailPoet\Settings\TrackingConfig; |
| 11 | |
| 12 | /** |
| 13 | * The single answer to "may we track this subscriber?" (CNIL/Garante). |
| 14 | * |
| 15 | * Used by BOTH enforcement points — send-time pixel removal and serve-time |
| 16 | * recording suppression — so they can never drift apart. |
| 17 | */ |
| 18 | class TrackingConsentController { |
| 19 | const SETTING_TRACK_UNKNOWN = 'tracking.consent.track_unknown'; |
| 20 | |
| 21 | private SettingsController $settings; |
| 22 | |
| 23 | private TrackingConfig $trackingConfig; |
| 24 | |
| 25 | public function __construct( |
| 26 | SettingsController $settings, |
| 27 | TrackingConfig $trackingConfig |
| 28 | ) { |
| 29 | $this->settings = $settings; |
| 30 | $this->trackingConfig = $trackingConfig; |
| 31 | } |
| 32 | |
| 33 | public function isTrackingAllowed(SubscriberEntity $subscriber): bool { |
| 34 | // The existing global switch still wins. Settings > Advanced > basic |
| 35 | // already means "no engagement tracking at all" for the whole site. |
| 36 | if (!$this->trackingConfig->isEmailTrackingEnabled()) { |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | switch ($subscriber->getTrackingConsent()) { |
| 41 | case SubscriberEntity::TRACKING_CONSENT_GRANTED: |
| 42 | return true; |
| 43 | case SubscriberEntity::TRACKING_CONSENT_UNKNOWN: |
| 44 | // 'unknown' = we never asked. Sites under the opt-in regime (new FR |
| 45 | // and IT contacts) set this to false; everyone else keeps today's |
| 46 | // behaviour. |
| 47 | return $this->shouldTrackUnknownConsent(); |
| 48 | case SubscriberEntity::TRACKING_CONSENT_DENIED: |
| 49 | default: |
| 50 | // Denied — and, defensively, any unrecognised value — is never tracked. |
| 51 | // Storage is constrained to the three states (Assert\Choice on the |
| 52 | // entity), so 'default' should be unreachable; deny rather than fall |
| 53 | // back to the permissive unknown path for a compliance-critical flag. |
| 54 | return false; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Whether subscribers who have never been asked ('unknown' consent) may be |
| 60 | * treated as trackable. Default true (existing behaviour). When false (strict |
| 61 | * opt-in mode), only subscribers who explicitly granted consent are tracked. |
| 62 | * |
| 63 | * Background jobs that infer intent from missing engagement (inactive sweep, |
| 64 | * resend to non-openers, re-engagement) use this so that, in strict mode, |
| 65 | * untracked 'unknown' subscribers are excluded the same way 'denied' ones |
| 66 | * are — otherwise their frozen engagement would wrongly mark them disengaged. |
| 67 | */ |
| 68 | public function shouldTrackUnknownConsent(): bool { |
| 69 | return (bool)$this->settings->get(self::SETTING_TRACK_UNKNOWN, true); |
| 70 | } |
| 71 | } |
| 72 |