Charsets.php
3 years ago
Hosts.php
2 months ago
Pages.php
9 months ago
SettingsChangeHandler.php
2 weeks ago
SettingsController.php
4 days ago
SettingsRepository.php
1 year ago
TrackingConfig.php
5 months ago
UserFlagsController.php
1 year ago
UserFlagsRepository.php
3 years ago
index.php
3 years ago
TrackingConfig.php
60 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Settings; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WP\Functions as WPFunctions; |
| 9 | |
| 10 | class TrackingConfig { |
| 11 | const LEVEL_FULL = 'full'; |
| 12 | const LEVEL_PARTIAL = 'partial'; |
| 13 | const LEVEL_BASIC = 'basic'; |
| 14 | |
| 15 | const OPENS_MERGED = 'merged'; |
| 16 | const OPENS_SEPARATED = 'separated'; |
| 17 | |
| 18 | private SettingsController $settings; |
| 19 | |
| 20 | private WPFunctions $wp; |
| 21 | |
| 22 | public function __construct( |
| 23 | SettingsController $settings, |
| 24 | WPFunctions $wp |
| 25 | ) { |
| 26 | $this->settings = $settings; |
| 27 | $this->wp = $wp; |
| 28 | } |
| 29 | |
| 30 | public function isEmailTrackingEnabled(?string $level = null): bool { |
| 31 | $level = $level ?? $this->settings->get('tracking.level', self::LEVEL_FULL); |
| 32 | return in_array($level, [self::LEVEL_PARTIAL, self::LEVEL_FULL], true); |
| 33 | } |
| 34 | |
| 35 | public function isCookieTrackingEnabled(?string $level = null): bool { |
| 36 | $level = $level ?? $this->settings->get('tracking.level', self::LEVEL_FULL); |
| 37 | return (bool)$this->wp->applyFilters('mailpoet_is_cookie_tracking_enabled', $level === self::LEVEL_FULL); |
| 38 | } |
| 39 | |
| 40 | public function areOpensMerged(?string $opens = null): bool { |
| 41 | $opens = $opens ?? $this->settings->get('tracking.opens', self::OPENS_MERGED); |
| 42 | return $opens !== self::OPENS_SEPARATED; |
| 43 | } |
| 44 | |
| 45 | public function areOpensSeparated(?string $opens = null): bool { |
| 46 | return !$this->areOpensMerged($opens); |
| 47 | } |
| 48 | |
| 49 | public function getConfig(): array { |
| 50 | return [ |
| 51 | 'level' => $this->settings->get('tracking.level', self::LEVEL_FULL), |
| 52 | 'emailTrackingEnabled' => $this->isEmailTrackingEnabled(), |
| 53 | 'cookieTrackingEnabled' => $this->isCookieTrackingEnabled(), |
| 54 | 'opens' => $this->settings->get('tracking.opens', self::OPENS_MERGED), |
| 55 | 'opensMerged' => $this->areOpensMerged(), |
| 56 | 'opensSeparated' => $this->areOpensSeparated(), |
| 57 | ]; |
| 58 | } |
| 59 | } |
| 60 |