diff --git a/Application/Model/ManagerHandler.php b/Application/Model/ManagerHandler.php new file mode 100644 index 0000000..ef64abc --- /dev/null +++ b/Application/Model/ManagerHandler.php @@ -0,0 +1,53 @@ +getManagerList(); + + foreach ($aManagerList as $managerName){ + if ($oViewConfig->isModuleActive($managerName)){ + return $managerName; + } + } + + return $this->getExplicitManager(); + } + + /** + * @return string + */ + public function getModuleSettingExplicitManagerSelectValue() :string + { + return Registry::getConfig()->getConfigParam('d3_gtm_settings_HAS_STD_MANAGER'); + } + + /** + * @return string + */ + public function getExplicitManager() :string + { + $sPotentialManagerName = $this->getModuleSettingExplicitManagerSelectValue(); + + /** @var ManagerTypes $oManagerTypes */ + $oManagerTypes = oxNew(ManagerTypes::class); + return $oManagerTypes->isManagerInList($sPotentialManagerName) + ? $sPotentialManagerName + : "NONE"; + } +} \ No newline at end of file diff --git a/Application/Model/ManagerTypes.php b/Application/Model/ManagerTypes.php new file mode 100644 index 0000000..7ebda76 --- /dev/null +++ b/Application/Model/ManagerTypes.php @@ -0,0 +1,60 @@ + self::EXTERNAL_SERVICE, + "agcookiecompliance" => self::AGCOOKIECOMPLIANCE, + "net_cookie_manager" => self::NET_COOKIE_MANAGER, + "oxps_usercentrics" => self::USERCENTRICS_MODULE, + "usercentrics" => self::USERCENTRICS_MANUALLY, + "consentmanager" => self::CONSENTMANAGER + ]; + } + + /** + * @param string $sManager + * @return bool + */ + public function isManagerInList(string $sManager) :bool + { + return in_array($sManager, $this->getManagerList(), true); + } +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b81719b..0c9155d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.6.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.5.0...2.6.0) - 2023-05-31 +### Added +- add settings to explicit choose an external service (usercentrics/ consentmanager) +- position to block-extension +- extended instructions to check for in readme +### Fixed +- usercentrics script +- missing right articleList-getter +### Changed +- view_item_list-template block extension +- cookieManager handling +### Removed +- additional check for cookieManagerType + ## [2.5.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.4.0...2.5.0) - 2023-05-23 ### Added - additional settings to explicitly indicate that consentmanager is used @@ -72,6 +86,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - genuine code cleanup - usercentrics includation script +## [1.8.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.7.0...1.8.0) - 2023-05-31 +### Fixed +- bug in explicit manager selection + +## [1.7.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.6.0...1.7.0) - 2023-05-31 +### Added +- extended call to read the technical documentation +### Changed +- block-extension for view_item_list +- way of getting list-articles in view_item_list + +## [1.6.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.5.0...1.6.0) - 2023-05-30 +### Added +- possibility to choose between consentmanager && usercentrics +- position to block extension +### Changed +- genuine code cleanup +- usercentrics includation script + ## [1.5.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.4.0...1.5.0) - 2023-05-23 ### Added - additional settings to explicitly indicate that consentmanager is used diff --git a/Modules/Core/ViewConfig.php b/Modules/Core/ViewConfig.php index affee8b..f1f9751 100644 --- a/Modules/Core/ViewConfig.php +++ b/Modules/Core/ViewConfig.php @@ -12,6 +12,8 @@ namespace D3\GoogleAnalytics4\Modules\Core; +use D3\GoogleAnalytics4\Application\Model\ManagerHandler; +use D3\GoogleAnalytics4\Application\Model\ManagerTypes; use OxidEsales\Eshop\Application\Controller\FrontendController; use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Registry; @@ -38,47 +40,23 @@ class ViewConfig extends ViewConfig_parent } /** - * @return mixed + * @return void */ - public function getModuleSettingExplicitManagerSelectValue() - { - return Registry::getConfig()->getConfigParam('d3_gtm_settings_HAS_STD_MANAGER'); - } - - /** - * @return false|mixed - */ - public function getExplicitManager() - { - $sManagerName = $this->getModuleSettingExplicitManagerSelectValue(); - return $sManagerName === "NONE" ? false : $sManagerName; - } - - public function getCookieManagerType() + public function defineCookieManagerType() :void { if ($this->sCookieManagerType === null) { - $this->sCookieManagerType = false; - - $allowedManagerTypes = [ - 'net_cookie_manager', - 'agcookiecompliance', - 'oxps_usercentrics' - ]; - - foreach ($allowedManagerTypes as $type) { - if ($this->isModuleActive($type)) { - $this->sCookieManagerType = $type; - break; - } - } + /** @var ManagerHandler $oManagerHandler */ + $oManagerHandler = oxNew(ManagerHandler::class); + $this->sCookieManagerType = $oManagerHandler->getCurrManager(); } - - if ($this->sCookieManagerType === false and $this->getExplicitManager()){ - return "externalService"; - } - - return $this->sCookieManagerType; + } + /** + * @return bool + */ + public function shallUseOwnCookieManager() :bool + { + return (bool) Registry::getConfig()->getConfigParam('d3_gtm_settings_hasOwnCookieManager'); } /** @@ -98,29 +76,37 @@ class ViewConfig extends ViewConfig_parent $oConfig = Registry::getConfig(); // No Cookie Manager in use - if (false === $this->shallUseOwnCookieManager()) { + if (!$this->shallUseOwnCookieManager()) { return true; } + $this->defineCookieManagerType(); + $sCookieID = $oConfig->getConfigParam('d3_gtm_settings_cookieName'); // Netensio Cookie Manager - if ($this->getCookieManagerType() == "net_cookie_manager") { + if ($this->sCookieManagerType === ManagerTypes::NET_COOKIE_MANAGER) { $oSession = Registry::getSession(); $aCookies = $oSession->getVariable("aCookieSel"); - return (!is_null($aCookies) && is_array($aCookies) && array_key_exists($sCookieID, $aCookies) && $aCookies[$sCookieID] == "1"); + return (is_array($aCookies) && array_key_exists($sCookieID, $aCookies) && $aCookies[$sCookieID] == "1"); } // Aggrosoft Cookie Consent - if ($this->getCookieManagerType() == "agcookiecompliance") { + if ($this->sCookieManagerType === ManagerTypes::AGCOOKIECOMPLIANCE) { if (method_exists($this, "isCookieCategoryEnabled")) { return $this->isCookieCategoryEnabled($sCookieID); } } // UserCentrics or consentmanager - if ($this->getCookieManagerType() === "oxps_usercentrics" or $this->getCookieManagerType() === 'externalService') { + if ( + $this->sCookieManagerType === ManagerTypes::USERCENTRICS_MODULE + or $this->sCookieManagerType === ManagerTypes::USERCENTRICS_MANUALLY + or $this->sCookieManagerType === ManagerTypes::CONSENTMANAGER + or $this->sCookieManagerType === ManagerTypes::EXTERNAL_SERVICE + ) + { // Always needs the script-tags delivered to the DOM. return true; } @@ -133,24 +119,27 @@ class ViewConfig extends ViewConfig_parent * This is especially important for UserCentrics. * @return string */ - public function getGtmScriptAttributes() + public function getGtmScriptAttributes() :string { $oConfig = Registry::getConfig(); + $sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName'); if (false === $this->shallUseOwnCookieManager()){ return ""; } - if ($this->getCookieManagerType() === "oxps_usercentrics" or $this->getExplicitManager() === 'USERCENTRICS') { - $sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName'); - + if ( + $this->sCookieManagerType === ManagerTypes::USERCENTRICS_MODULE + or $this->sCookieManagerType === ManagerTypes::USERCENTRICS_MANUALLY + ) + { if ($sCookieId) { return 'data-usercentrics="' . $sCookieId . '" type="text/plain" async=""'; } } - if ($this->getCookieManagerType() === "externalService" and $this->getExplicitManager() === 'CONSENTMANAGER') { - $sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName'); + if ($this->sCookieManagerType === ManagerTypes::CONSENTMANAGER) + { if ($sCookieId) { return 'async type="text/plain" diff --git a/README.md b/README.md index dc71f7b..36792ae 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,9 @@ Sofern nötig, bestätigen Sie bitte, dass Sie `package-name` erlauben, Code aus Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module". -> ### Wichtig! -> Bitte stellen Sie sicher, dass die nötigen Blöcke im OXID-Shop zur Verfügung stehen. -> Lesen Sie mehr in der [technischen Doku](./Docs/README.md) unter "Blöcke"! +### Wichtig! +Bitte stellen Sie sicher, dass die nötigen Template-Blöcke im OXID-Shop zur Verfügung stehen. +Lesen Sie mehr in der [technischen Doku](./Docs/README.md) unter "Blöcke"! ## Verwendung ### Grundfunktionalität diff --git a/metadata.php b/metadata.php index b21f73b..a4d8b37 100755 --- a/metadata.php +++ b/metadata.php @@ -17,7 +17,7 @@ $aModule = [ Die Entwicklung basiert auf einem Fork von Marat Bedoev - Github-Link ", 'thumbnail' => 'thumbnail.png', - 'version' => '1.8.0', + 'version' => '2.6.0', 'author' => 'Data Development (Inh.: Thomas Dartsch)', 'email' => 'support@shopmodule.com', 'url' => 'https://www.oxidmodule.com/',