diff --git a/Model/Config.php b/Model/Config.php index 71e2db6..8190804 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -13,6 +13,7 @@ class Config public const XML_PATH_COOKIEBOT_ID = 'web/cookiebot/id'; public const XML_PATH_DATA_CULTURE = 'web/cookiebot/data_culture'; public const XML_PATH_USE_EU_CDN = 'web/cookiebot/use_eu_cdn'; + public const XML_PATH_USE_GOOGLE_CONSENT_MODE = 'web/cookiebot/use_google_consent_mode'; /** * @var ScopeConfigInterface @@ -43,4 +44,9 @@ public function useEuCdn(): bool { return $this->scopeConfig->isSetFlag(self::XML_PATH_USE_EU_CDN, ScopeInterface::SCOPE_STORE); } + + public function isGoogleConsentModeEnabled(): bool + { + return $this->scopeConfig->isSetFlag(self::XML_PATH_USE_GOOGLE_CONSENT_MODE, ScopeInterface::SCOPE_STORE); + } } diff --git a/Test/Integration/AddScriptTest.php b/Test/Integration/AddScriptTest.php index 5b90bff..3450b4f 100644 --- a/Test/Integration/AddScriptTest.php +++ b/Test/Integration/AddScriptTest.php @@ -30,6 +30,16 @@ public function testScriptAddedOnHomepage(): void self::assertStringContainsString($this->script, $this->getResponse()->getBody()); } + /** + * @magentoConfigFixture current_store web/cookiebot/use_google_consent_mode 1 + * @magentoConfigFixture current_store web/cookiebot/id 123-456-789 + */ + public function testGoogleConsentScriptAddedOnHomepage(): void + { + $this->dispatch('/'); + self::assertStringContainsString('gtag("set", "ads_data_redaction", true);', $this->getResponse()->getBody()); + } + /** * @magentoDataFixture Magento/Catalog/_files/product_simple.php * @magentoConfigFixture current_store web/cookiebot/enabled 1 diff --git a/ViewModel/Script.php b/ViewModel/Script.php index 096c788..715d9d6 100644 --- a/ViewModel/Script.php +++ b/ViewModel/Script.php @@ -34,4 +34,9 @@ public function getScript(): string return $this->scriptGenerator->generate(); } + + public function isGoogleConsentModeEnabled(): bool + { + return $this->config->isGoogleConsentModeEnabled(); + } } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index fd4af28..08586c7 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -25,6 +25,10 @@ Magento\Config\Model\Config\Source\Yesno + + + Magento\Config\Model\Config\Source\Yesno + diff --git a/etc/config.xml b/etc/config.xml index 2bd5237..f7d8063 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -8,6 +8,7 @@ 0 + 1 diff --git a/view/frontend/templates/script.phtml b/view/frontend/templates/script.phtml index b1f6a0a..aebbb83 100644 --- a/view/frontend/templates/script.phtml +++ b/view/frontend/templates/script.phtml @@ -2,3 +2,28 @@ getData('view_model') ?> getScript() ?> + +isGoogleConsentModeEnabled()): + ?> + +