From f9a0834d26d63ea861c6422cc5677ad55e0fec80 Mon Sep 17 00:00:00 2001 From: MaxBUhe Date: Mon, 15 May 2023 15:06:25 +0200 Subject: [PATCH] add settings-entry; add consentmanager-option --- Application/views/admin/de/module_options.php | 5 ++- Modules/Core/ViewConfig.php | 32 +++++++++++++++++-- metadata.php | 7 ++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Application/views/admin/de/module_options.php b/Application/views/admin/de/module_options.php index 2508743..aa522b8 100755 --- a/Application/views/admin/de/module_options.php +++ b/Application/views/admin/de/module_options.php @@ -34,5 +34,8 @@ $aLang = [ // for cookie manager settings 'SHOP_MODULE_GROUP_d3_gtm_settings_cookiemanager' => 'Cookie Manager Einstellungen', 'SHOP_MODULE_d3_gtm_settings_hasOwnCookieManager' => 'Cookie Manager nutzen?', - 'SHOP_MODULE_d3_gtm_settings_cookieName' => 'CookieID', + 'SHOP_MODULE_d3_gtm_settings_HAS_CONSENTMANAGER' => 'Nutzen Sie die Consentmanager-Einbindung?', + 'SHOP_MODULE_d3_gtm_settings_HAS_CONSENTMANAGER_NO' => 'Nein', + 'SHOP_MODULE_d3_gtm_settings_HAS_CONSENTMANAGER_YES' => 'Ja', + 'SHOP_MODULE_d3_gtm_settings_cookieName' => 'CookieID', ]; diff --git a/Modules/Core/ViewConfig.php b/Modules/Core/ViewConfig.php index 5362364..4f69a14 100644 --- a/Modules/Core/ViewConfig.php +++ b/Modules/Core/ViewConfig.php @@ -14,6 +14,7 @@ namespace D3\GoogleAnalytics4\Modules\Core; use OxidEsales\Eshop\Application\Controller\FrontendController; +use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Registry; class ViewConfig extends ViewConfig_parent @@ -33,6 +34,11 @@ class ViewConfig extends ViewConfig_parent return $this->sContainerId; } + public function getModuleConsentmanagerSettingSelectValue() :bool + { + return Registry::getConfig()->getConfigParam('d3_gtm_settings_HAS_CONSENTMANAGER') === 'YES'; + } + public function getCookieManagerType() { if ($this->sCookieManagerType === null) @@ -52,6 +58,11 @@ class ViewConfig extends ViewConfig_parent } } } + + if ($this->sCookieManagerType === false and $this->getModuleConsentmanagerSettingSelectValue()){ + return "consentmanager"; + } + return $this->sCookieManagerType; } @@ -60,7 +71,8 @@ class ViewConfig extends ViewConfig_parent */ public function D3blShowGtmScript() { - $oConfig = $this->getConfig(); + /** @var Config $oConfig */ + $oConfig = Registry::getConfig(); // No Cookie Manager in use if (!$oConfig->getConfigParam('d3_gtm_settings_hasOwnCookieManager')) { @@ -85,7 +97,7 @@ class ViewConfig extends ViewConfig_parent } // UserCentrics - if ($this->getCookieManagerType() == "oxps_usercentrics") { + if ($this->getCookieManagerType() === "oxps_usercentrics" or $this->getCookieManagerType() === 'consentmanager') { // Always needs the script-tags delivered to the DOM. return true; } @@ -101,8 +113,9 @@ class ViewConfig extends ViewConfig_parent */ public function getGtmScriptAttributes() { + $oConfig = Registry::getConfig(); + if ($this->getCookieManagerType() == "oxps_usercentrics") { - $oConfig = $this->getConfig(); $sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName'); if ($sCookieId) { @@ -110,6 +123,19 @@ class ViewConfig extends ViewConfig_parent } } + if ($this->getCookieManagerType() == "consentmanager") { + $sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName'); + + if ($sCookieId) { + return 'async + type="text/plain" + data-cmp-src="https://www.googletagmanager.com/gtm.js?id='.$this->getGtmContainerId().'" + class="cmplazyload" + data-cmp-vendor="s905" + '; + } + } + return ""; } diff --git a/metadata.php b/metadata.php index 440231d..5122de4 100755 --- a/metadata.php +++ b/metadata.php @@ -126,5 +126,12 @@ $aModule = [ 'value' => 'example', 'position' => 999 ], + [ + 'group' => 'd3_gtm_settings_cookiemanager', + 'name' => 'd3_gtm_settings_HAS_CONSENTMANAGER', + 'type' => 'select', + 'value' => 'none', + 'constraints' => 'NO|YES', + ], ] ]; \ No newline at end of file