diff --git a/Block/GtmCode.php b/Block/GtmCode.php index 352469f..59e985f 100644 --- a/Block/GtmCode.php +++ b/Block/GtmCode.php @@ -104,6 +104,16 @@ public function isCookieRestrictionModeEnabled() return $this->config->isCookieRestrictionModeEnabled(); } + /** + * Retrieve true if mf cookie consent extension is enabled + * + * @return bool + */ + public function isMfCookieConsentExtensionEnabled() + { + return $this->config->isMfCookieConsentExtensionEnabled(); + } + /** * Get current website ID * diff --git a/Model/Config.php b/Model/Config.php index a246379..14baa47 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -11,6 +11,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; use Magento\Config\Model\Config\Backend\Admin\Custom; +use Magento\Framework\Module\Manager as ModuleManager; class Config { @@ -61,20 +62,33 @@ class Config public const XML_PATH_SPEED_OPTIMIZATION_ENABLED = 'mfgoogletagmanager/page_speed_optimization/enabled'; public const XML_PATH_THIRD_PARTY_GA = 'mfgoogletagmanager/third_party_ga/enabled'; + /** + * MF cookie consent extension enabled + */ + public const XML_PATH_MF_COOKIE_CONSENT_EXTENSION_ENABLED = 'mf_cookie_consent/general/enabled'; + /** * @var ScopeConfigInterface */ private $scopeConfig; + /** + * @var ModuleManager + */ + protected $moduleManager; + /** * Config constructor. * * @param ScopeConfigInterface $scopeConfig + * @param ModuleManager $moduleManager */ public function __construct( - ScopeConfigInterface $scopeConfig + ScopeConfigInterface $scopeConfig, + ModuleManager $moduleManager ) { $this->scopeConfig = $scopeConfig; + $this->moduleManager = $moduleManager; } /** @@ -259,6 +273,18 @@ public function isCookieRestrictionModeEnabled(string $storeId = null) return (bool)$this->getConfig(Custom::XML_PATH_WEB_COOKIE_RESTRICTION, $storeId); } + /** + * Retrieve true if mf cookie consent extension is enabled + * + * @param string|null $storeId + * @return bool + */ + public function isMfCookieConsentExtensionEnabled(string $storeId = null) + { + return $this->moduleManager->isEnabled('Magefan_CookieConsent') + && $this->getConfig(self::XML_PATH_MF_COOKIE_CONSENT_EXTENSION_ENABLED , $storeId); + } + /* * Retrieve Magento product categories * diff --git a/view/frontend/templates/js_code.phtml b/view/frontend/templates/js_code.phtml index 634097a..9acd75b 100644 --- a/view/frontend/templates/js_code.phtml +++ b/view/frontend/templates/js_code.phtml @@ -17,6 +17,9 @@ if (!isset($escaper)) { $script = ''; ?> + +getLayout()->createBlock(\Magefan\Community\Block\JsScript::class)->setMethod('getCookie')->toHtml() ?> + isSpeedOptimizationEnabled() && $block->getRequest()->getModuleName() !== 'checkout') { ?> isProtectCustomerDataEnabled()) { ?> - + isMfCookieConsentExtensionEnabled()) { + $script .= " + gtag('consent', 'default', { + 'ad_user_data': 'denied', + 'ad_personalization': 'denied', + 'ad_storage': 'denied', + 'analytics_storage': 'denied', + /* cookieyes.com start */ + + 'functionality_storage': 'denied', + 'personalization_storage': 'denied', + 'security_storage': 'granted', + /* cookieyes.com end */ + + 'wait_for_update': 2000 + }); + /* cookieyes.com start */ + gtag('set', 'ads_data_redaction', true); + gtag('set', 'url_passthrough', true); + /* cookieyes.com end */ + "; + } + ?> isLoadBeforeConsent()) { ?> escapeHtml(\Magento\Cookie\Helper\Cookie::IS_USER_ALLOWED_SAVE_COOKIE)}' ); @@ -107,7 +121,10 @@ $script = ''; function grantConsent() { window.mfGtmUserCookiesAllowed = true; - gtag('consent', 'update', { + "; + + if (!$block->isMfCookieConsentExtensionEnabled()) { + $script .= "gtag('consent', 'update', { 'ad_user_data': 'granted', 'ad_personalization': 'granted', 'ad_storage': 'granted', @@ -115,7 +132,10 @@ $script = ''; 'functionality_storage': 'granted', 'personalization_storage': 'granted', 'security_storage': 'granted' - }); + });"; + } + + $script .= " }; if (customerDataAllowed()) {