add settings-entry; add consentmanager-option

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

View File

@ -31,5 +31,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',
];

View File

@ -13,6 +13,7 @@
namespace D3\GoogleAnalytics4\Modules\Core;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface;
@ -36,6 +37,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)
@ -55,6 +61,11 @@ class ViewConfig extends ViewConfig_parent
}
}
}
if ($this->sCookieManagerType === false and $this->getModuleConsentmanagerSettingSelectValue()){
return "consentmanager";
}
return $this->sCookieManagerType;
}
@ -63,7 +74,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')) {
@ -88,7 +100,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;
}
@ -104,8 +116,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) {
@ -113,6 +126,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 "";
}

View File

@ -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',
],
]
];