add settings-entry; add consentmanager-option

This commit is contained in:
MaxBUhe 2023-05-15 15:06:25 +02:00
parent bb70cda626
commit f9a0834d26
3 changed files with 40 additions and 4 deletions

View File

@ -34,5 +34,8 @@ $aLang = [
// for cookie manager settings // for cookie manager settings
'SHOP_MODULE_GROUP_d3_gtm_settings_cookiemanager' => 'Cookie Manager Einstellungen', 'SHOP_MODULE_GROUP_d3_gtm_settings_cookiemanager' => 'Cookie Manager Einstellungen',
'SHOP_MODULE_d3_gtm_settings_hasOwnCookieManager' => 'Cookie Manager nutzen?', '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',
]; ];

View File

@ -14,6 +14,7 @@
namespace D3\GoogleAnalytics4\Modules\Core; namespace D3\GoogleAnalytics4\Modules\Core;
use OxidEsales\Eshop\Application\Controller\FrontendController; use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
class ViewConfig extends ViewConfig_parent class ViewConfig extends ViewConfig_parent
@ -33,6 +34,11 @@ class ViewConfig extends ViewConfig_parent
return $this->sContainerId; return $this->sContainerId;
} }
public function getModuleConsentmanagerSettingSelectValue() :bool
{
return Registry::getConfig()->getConfigParam('d3_gtm_settings_HAS_CONSENTMANAGER') === 'YES';
}
public function getCookieManagerType() public function getCookieManagerType()
{ {
if ($this->sCookieManagerType === null) 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; return $this->sCookieManagerType;
} }
@ -60,7 +71,8 @@ class ViewConfig extends ViewConfig_parent
*/ */
public function D3blShowGtmScript() public function D3blShowGtmScript()
{ {
$oConfig = $this->getConfig(); /** @var Config $oConfig */
$oConfig = Registry::getConfig();
// No Cookie Manager in use // No Cookie Manager in use
if (!$oConfig->getConfigParam('d3_gtm_settings_hasOwnCookieManager')) { if (!$oConfig->getConfigParam('d3_gtm_settings_hasOwnCookieManager')) {
@ -85,7 +97,7 @@ class ViewConfig extends ViewConfig_parent
} }
// UserCentrics // UserCentrics
if ($this->getCookieManagerType() == "oxps_usercentrics") { if ($this->getCookieManagerType() === "oxps_usercentrics" or $this->getCookieManagerType() === 'consentmanager') {
// Always needs the script-tags delivered to the DOM. // Always needs the script-tags delivered to the DOM.
return true; return true;
} }
@ -101,8 +113,9 @@ class ViewConfig extends ViewConfig_parent
*/ */
public function getGtmScriptAttributes() public function getGtmScriptAttributes()
{ {
$oConfig = Registry::getConfig();
if ($this->getCookieManagerType() == "oxps_usercentrics") { if ($this->getCookieManagerType() == "oxps_usercentrics") {
$oConfig = $this->getConfig();
$sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName'); $sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
if ($sCookieId) { 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 ""; return "";
} }

View File

@ -126,5 +126,12 @@ $aModule = [
'value' => 'example', 'value' => 'example',
'position' => 999 'position' => 999
], ],
[
'group' => 'd3_gtm_settings_cookiemanager',
'name' => 'd3_gtm_settings_HAS_CONSENTMANAGER',
'type' => 'select',
'value' => 'none',
'constraints' => 'NO|YES',
],
] ]
]; ];