rework 'Manager Type Handling'; add ManagerHandler + ManagerTypes
This commit is contained in:
parent
1d194d445a
commit
95e0cab68c
53
Application/Model/ManagerHandler.php
Normal file
53
Application/Model/ManagerHandler.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace D3\GoogleAnalytics4\Application\Model;
|
||||||
|
|
||||||
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
|
use OxidEsales\Eshop\Core\ViewConfig;
|
||||||
|
|
||||||
|
class ManagerHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getCurrManager() :string
|
||||||
|
{
|
||||||
|
/** @var ManagerTypes $oManagerTypes */
|
||||||
|
$oManagerTypes = oxNew(ManagerTypes::class);
|
||||||
|
|
||||||
|
/** @var ViewConfig $oViewConfig */
|
||||||
|
$oViewConfig = oxNew(ViewConfig::class);
|
||||||
|
|
||||||
|
$aManagerList = $oManagerTypes->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
|
||||||
|
: ManagerTypes::EXTERNAL_SERVICE;
|
||||||
|
}
|
||||||
|
}
|
60
Application/Model/ManagerTypes.php
Normal file
60
Application/Model/ManagerTypes.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace D3\GoogleAnalytics4\Application\Model;
|
||||||
|
|
||||||
|
class ManagerTypes
|
||||||
|
{
|
||||||
|
#ToDo: make own classes for each of the manager
|
||||||
|
|
||||||
|
|
||||||
|
const EXTERNAL_SERVICE = "externalService";
|
||||||
|
const NET_COOKIE_MANAGER = "net_cookie_manager";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Further information's:
|
||||||
|
* https://github.com/aggrosoft/oxid-cookie-compliance
|
||||||
|
*/
|
||||||
|
const AGCOOKIECOMPLIANCE = "agcookiecompliance";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used the OXID Module.
|
||||||
|
*
|
||||||
|
* Further information's:
|
||||||
|
* https://docs.oxid-esales.com/modules/usercentrics/de/latest/einfuehrung.html
|
||||||
|
*
|
||||||
|
* Usercentrics homepage:
|
||||||
|
* https://usercentrics.com
|
||||||
|
*/
|
||||||
|
const USERCENTRICS_MODULE = "oxps_usercentrics";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* manually included usercentrics script
|
||||||
|
*/
|
||||||
|
const USERCENTRICS_MANUALLY = "USERCENTRICS";
|
||||||
|
|
||||||
|
const CONSENTMANAGER = "CONSENTMANAGER";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getManagerList(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
"externalService" => 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);
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
namespace D3\GoogleAnalytics4\Modules\Core;
|
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\Application\Controller\FrontendController;
|
||||||
use OxidEsales\Eshop\Core\Config;
|
use OxidEsales\Eshop\Core\Config;
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
@ -38,47 +40,24 @@ class ViewConfig extends ViewConfig_parent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function getModuleSettingExplicitManagerSelectValue()
|
public function defineCookieManagerType() :void
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
if ($this->sCookieManagerType === null)
|
if ($this->sCookieManagerType === null)
|
||||||
{
|
{
|
||||||
$this->sCookieManagerType = false;
|
/** @var ManagerHandler $oManagerHandler */
|
||||||
|
$oManagerHandler = oxNew(ManagerHandler::class);
|
||||||
$allowedManagerTypes = [
|
$this->sCookieManagerType = $oManagerHandler->getCurrManager();
|
||||||
'net_cookie_manager',
|
|
||||||
'agcookiecompliance',
|
|
||||||
'oxps_usercentrics'
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($allowedManagerTypes as $type) {
|
|
||||||
if ($this->isModuleActive($type)) {
|
|
||||||
$this->sCookieManagerType = $type;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->sCookieManagerType === false and $this->getExplicitManager()){
|
/**
|
||||||
return "externalService";
|
* @return bool
|
||||||
}
|
*/
|
||||||
|
public function shallUseOwnCookieManager() :bool
|
||||||
return $this->sCookieManagerType;
|
{
|
||||||
|
return (bool) Registry::getConfig()->getConfigParam('d3_gtm_settings_hasOwnCookieManager');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,29 +69,37 @@ class ViewConfig extends ViewConfig_parent
|
|||||||
$oConfig = Registry::getConfig();
|
$oConfig = Registry::getConfig();
|
||||||
|
|
||||||
// No Cookie Manager in use
|
// No Cookie Manager in use
|
||||||
if (!$oConfig->getConfigParam('d3_gtm_settings_hasOwnCookieManager')) {
|
if (!$this->shallUseOwnCookieManager()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->defineCookieManagerType();
|
||||||
|
|
||||||
$sCookieID = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
|
$sCookieID = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
|
||||||
|
|
||||||
// Netensio Cookie Manager
|
// Netensio Cookie Manager
|
||||||
if ($this->getCookieManagerType() == "net_cookie_manager") {
|
if ($this->sCookieManagerType === ManagerTypes::NET_COOKIE_MANAGER) {
|
||||||
$oSession = Registry::getSession();
|
$oSession = Registry::getSession();
|
||||||
$aCookies = $oSession->getVariable("aCookieSel");
|
$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
|
// Aggrosoft Cookie Consent
|
||||||
if ($this->getCookieManagerType() == "agcookiecompliance") {
|
if ($this->sCookieManagerType === ManagerTypes::AGCOOKIECOMPLIANCE) {
|
||||||
if (method_exists($this, "isCookieCategoryEnabled")) {
|
if (method_exists($this, "isCookieCategoryEnabled")) {
|
||||||
return $this->isCookieCategoryEnabled($sCookieID);
|
return $this->isCookieCategoryEnabled($sCookieID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserCentrics or consentmanager
|
// 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.
|
// Always needs the script-tags delivered to the DOM.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -126,21 +113,27 @@ class ViewConfig extends ViewConfig_parent
|
|||||||
* This is especially important for UserCentrics.
|
* This is especially important for UserCentrics.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getGtmScriptAttributes()
|
public function getGtmScriptAttributes() :string
|
||||||
{
|
{
|
||||||
$oConfig = Registry::getConfig();
|
$oConfig = Registry::getConfig();
|
||||||
|
$sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
|
||||||
|
|
||||||
if ($this->getCookieManagerType() === "oxps_usercentrics" or $this->getExplicitManager() === 'USERCENTRICS') {
|
if (false === $this->shallUseOwnCookieManager()){
|
||||||
$sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
$this->sCookieManagerType === ManagerTypes::USERCENTRICS_MODULE
|
||||||
|
or $this->sCookieManagerType === ManagerTypes::USERCENTRICS_MANUALLY
|
||||||
|
)
|
||||||
|
{
|
||||||
if ($sCookieId) {
|
if ($sCookieId) {
|
||||||
return 'data-usercentrics="' . $sCookieId . '" type="text/plain" async=""';
|
return 'data-usercentrics="' . $sCookieId . '" type="text/plain" async=""';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getCookieManagerType() === "externalService" and $this->getExplicitManager() === 'CONSENTMANAGER') {
|
if ($this->sCookieManagerType === ManagerTypes::CONSENTMANAGER)
|
||||||
$sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
|
{
|
||||||
|
|
||||||
if ($sCookieId) {
|
if ($sCookieId) {
|
||||||
return 'async
|
return 'async
|
||||||
type="text/plain"
|
type="text/plain"
|
||||||
|
Loading…
Reference in New Issue
Block a user