2023-01-19 15:31:56 +01:00
|
|
|
<?php
|
2023-01-27 09:07:09 +01:00
|
|
|
/**
|
2023-01-27 11:04:23 +01:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
2023-01-19 15:31:56 +01:00
|
|
|
*
|
2023-01-27 09:07:09 +01:00
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
2023-01-27 11:04:23 +01:00
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
2023-01-19 15:31:56 +01:00
|
|
|
*/
|
|
|
|
|
2023-01-20 11:24:30 +01:00
|
|
|
namespace D3\GoogleAnalytics4\Modules\Core;
|
2023-01-19 15:31:56 +01:00
|
|
|
|
2024-05-29 15:51:16 +02:00
|
|
|
use D3\GoogleAnalytics4\Application\Model\CMP\Usercentrics;
|
2024-03-25 09:06:22 +01:00
|
|
|
use D3\GoogleAnalytics4\Application\Model\Constants;
|
2023-05-31 12:17:00 +02:00
|
|
|
use D3\GoogleAnalytics4\Application\Model\ManagerHandler;
|
|
|
|
use D3\GoogleAnalytics4\Application\Model\ManagerTypes;
|
2023-01-19 15:31:56 +01:00
|
|
|
use OxidEsales\Eshop\Application\Controller\FrontendController;
|
2023-05-15 15:06:25 +02:00
|
|
|
use OxidEsales\Eshop\Core\Config;
|
2024-01-22 11:13:05 +01:00
|
|
|
use OxidEsales\Eshop\Application\Model\User;use OxidEsales\Eshop\Core\Registry;
|
2023-01-27 13:43:29 +01:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface;
|
2023-09-13 14:56:05 +02:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2023-01-19 15:31:56 +01:00
|
|
|
|
|
|
|
class ViewConfig extends ViewConfig_parent
|
|
|
|
{
|
|
|
|
|
|
|
|
// Google Tag Manager Container ID
|
|
|
|
private $sContainerId = null;
|
2024-05-29 12:15:55 +02:00
|
|
|
|
|
|
|
// used CMP
|
|
|
|
private $sCookieManagerType = null;#
|
|
|
|
|
|
|
|
// isModule Activated properly?
|
|
|
|
private $blGA4enabled = null;
|
2023-01-19 15:31:56 +01:00
|
|
|
|
|
|
|
public function getGtmContainerId()
|
|
|
|
{
|
|
|
|
if ($this->sContainerId === null)
|
|
|
|
{
|
2024-05-29 11:59:38 +02:00
|
|
|
$this->sContainerId = $this->d3GetModuleConfigParam("_sContainerID");
|
2023-01-19 15:31:56 +01:00
|
|
|
}
|
|
|
|
return $this->sContainerId;
|
|
|
|
}
|
|
|
|
|
2023-05-23 14:33:35 +02:00
|
|
|
/**
|
2023-05-31 12:17:00 +02:00
|
|
|
* @return void
|
2023-05-23 14:33:35 +02:00
|
|
|
*/
|
2023-05-31 12:17:00 +02:00
|
|
|
public function defineCookieManagerType() :void
|
2023-05-23 14:33:35 +02:00
|
|
|
{
|
2023-05-31 12:17:00 +02:00
|
|
|
if ($this->sCookieManagerType === null)
|
|
|
|
{
|
|
|
|
/** @var ManagerHandler $oManagerHandler */
|
|
|
|
$oManagerHandler = oxNew(ManagerHandler::class);
|
|
|
|
$this->sCookieManagerType = $oManagerHandler->getCurrManager();
|
|
|
|
}
|
2023-05-23 14:33:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-05-31 12:17:00 +02:00
|
|
|
* @return bool
|
2023-05-23 14:33:35 +02:00
|
|
|
*/
|
2023-05-31 12:17:00 +02:00
|
|
|
public function shallUseOwnCookieManager() :bool
|
2023-04-04 10:15:15 +02:00
|
|
|
{
|
2024-05-29 11:59:38 +02:00
|
|
|
return (bool) $this->d3GetModuleConfigParam('_blEnableOwnCookieManager');
|
2023-04-04 10:15:15 +02:00
|
|
|
}
|
|
|
|
|
2023-02-01 15:32:28 +01:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2023-04-04 10:15:15 +02:00
|
|
|
public function D3blShowGtmScript()
|
2023-02-01 15:32:28 +01:00
|
|
|
{
|
2023-05-15 15:06:25 +02:00
|
|
|
/** @var Config $oConfig */
|
|
|
|
$oConfig = Registry::getConfig();
|
2023-02-01 15:32:28 +01:00
|
|
|
|
2024-05-29 12:16:22 +02:00
|
|
|
if (false === $this->isGA4enabled()){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-04-04 10:15:15 +02:00
|
|
|
// No Cookie Manager in use
|
2023-05-31 12:17:00 +02:00
|
|
|
if (!$this->shallUseOwnCookieManager()) {
|
2023-02-01 15:32:28 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:17:00 +02:00
|
|
|
$this->defineCookieManagerType();
|
|
|
|
|
2024-05-29 11:59:38 +02:00
|
|
|
$sCookieID = trim($this->d3GetModuleConfigParam('_sControlParameter'));
|
2023-04-04 10:15:15 +02:00
|
|
|
|
|
|
|
// Netensio Cookie Manager
|
2023-05-31 12:17:00 +02:00
|
|
|
if ($this->sCookieManagerType === ManagerTypes::NET_COOKIE_MANAGER) {
|
2023-04-04 10:15:15 +02:00
|
|
|
$oSession = Registry::getSession();
|
|
|
|
$aCookies = $oSession->getVariable("aCookieSel");
|
|
|
|
|
2023-05-31 12:17:00 +02:00
|
|
|
return (is_array($aCookies) && array_key_exists($sCookieID, $aCookies) && $aCookies[$sCookieID] == "1");
|
2023-04-04 10:15:15 +02:00
|
|
|
}
|
|
|
|
|
2023-03-17 10:59:50 +01:00
|
|
|
// Aggrosoft Cookie Consent
|
2023-05-31 12:17:00 +02:00
|
|
|
if ($this->sCookieManagerType === ManagerTypes::AGCOOKIECOMPLIANCE) {
|
2023-04-04 10:15:15 +02:00
|
|
|
if (method_exists($this, "isCookieCategoryEnabled")) {
|
|
|
|
return $this->isCookieCategoryEnabled($sCookieID);
|
|
|
|
}
|
2023-03-17 10:59:50 +01:00
|
|
|
}
|
|
|
|
|
2023-05-23 14:52:07 +02:00
|
|
|
// UserCentrics or consentmanager
|
2023-05-31 12:17:00 +02:00
|
|
|
if (
|
2024-05-31 15:18:26 +02:00
|
|
|
$this->sCookieManagerType === Usercentrics::sModuleIncludationInternalName
|
|
|
|
or $this->sCookieManagerType === Usercentrics::sExternalIncludationInternalName
|
2023-05-31 12:17:00 +02:00
|
|
|
or $this->sCookieManagerType === ManagerTypes::CONSENTMANAGER
|
2023-06-27 08:58:05 +02:00
|
|
|
or $this->sCookieManagerType === ManagerTypes::COOKIEFIRST
|
2023-09-07 15:08:06 +02:00
|
|
|
or $this->sCookieManagerType === ManagerTypes::COOKIEBOT
|
2023-05-31 12:17:00 +02:00
|
|
|
or $this->sCookieManagerType === ManagerTypes::EXTERNAL_SERVICE
|
|
|
|
)
|
|
|
|
{
|
2023-04-04 10:15:15 +02:00
|
|
|
// Always needs the script-tags delivered to the DOM.
|
|
|
|
return true;
|
2023-03-17 10:59:50 +01:00
|
|
|
}
|
|
|
|
|
2023-04-04 10:15:15 +02:00
|
|
|
// Cookie Manager not (yet) supported
|
2023-02-01 15:32:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-04-04 10:15:15 +02:00
|
|
|
/**
|
|
|
|
* Get additional attributes for script tags.
|
|
|
|
* This is especially important for UserCentrics.
|
|
|
|
* @return string
|
|
|
|
*/
|
2023-05-31 12:17:00 +02:00
|
|
|
public function getGtmScriptAttributes() :string
|
2023-04-04 10:15:15 +02:00
|
|
|
{
|
2024-05-29 11:59:38 +02:00
|
|
|
$sControlParameter = trim($this->d3GetModuleConfigParam('_sControlParameter'));
|
2023-05-15 15:06:25 +02:00
|
|
|
|
2023-09-13 15:13:35 +02:00
|
|
|
if (false === $this->shallUseOwnCookieManager() or ($sControlParameter === '')){
|
2023-05-31 12:17:00 +02:00
|
|
|
return "";
|
|
|
|
}
|
2023-04-04 10:15:15 +02:00
|
|
|
|
2023-05-31 12:17:00 +02:00
|
|
|
if (
|
2024-05-31 15:18:26 +02:00
|
|
|
$this->sCookieManagerType === Usercentrics::sModuleIncludationInternalName
|
|
|
|
or $this->sCookieManagerType === Usercentrics::sExternalIncludationInternalName
|
2023-05-31 12:17:00 +02:00
|
|
|
)
|
|
|
|
{
|
2023-09-13 15:13:35 +02:00
|
|
|
return 'data-usercentrics="' . $sControlParameter . '" type="text/plain" async=""';
|
2023-04-04 10:15:15 +02:00
|
|
|
}
|
|
|
|
|
2023-05-31 12:17:00 +02:00
|
|
|
if ($this->sCookieManagerType === ManagerTypes::CONSENTMANAGER)
|
|
|
|
{
|
2023-09-13 15:13:35 +02:00
|
|
|
return 'type="text/plain" class="cmplazyload" data-cmp-vendor="'.$sControlParameter.'"';
|
2023-05-15 15:06:25 +02:00
|
|
|
}
|
|
|
|
|
2023-06-27 08:46:51 +02:00
|
|
|
if ($this->sCookieManagerType === ManagerTypes::COOKIEFIRST){
|
2023-09-13 14:56:05 +02:00
|
|
|
return 'type="text/plain" data-cookiefirst-category="' . $sControlParameter .'"';
|
2023-06-27 08:46:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-07 15:08:06 +02:00
|
|
|
if ($this->sCookieManagerType === ManagerTypes::COOKIEBOT){
|
2023-09-13 14:56:05 +02:00
|
|
|
return 'type="text/plain" data-cookieconsent="' . $sControlParameter .'"';
|
2023-09-07 15:08:06 +02:00
|
|
|
}
|
|
|
|
|
2023-04-04 10:15:15 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-09-13 14:56:05 +02:00
|
|
|
/**
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
*/
|
2023-01-19 15:31:56 +01:00
|
|
|
public function isGA4enabled()
|
|
|
|
{
|
|
|
|
if ($this->blGA4enabled === null)
|
|
|
|
{
|
2024-05-29 12:15:55 +02:00
|
|
|
$this->blGA4enabled = $this->d3GetModuleConfigParam("_blEnableGA4");
|
2023-01-19 15:31:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->blGA4enabled;
|
|
|
|
}
|
|
|
|
|
2024-04-02 08:59:17 +02:00
|
|
|
public function isGtmConsentModeSetActivated() :bool
|
|
|
|
{
|
2024-05-29 12:15:55 +02:00
|
|
|
return $this->d3GetModuleConfigParam("_blEnableConsentMode");
|
2024-04-02 08:59:17 +02:00
|
|
|
}
|
|
|
|
|
2023-01-19 15:31:56 +01:00
|
|
|
public function getGtmDataLayer()
|
|
|
|
{
|
|
|
|
if (!$this->getGtmContainerId()) return "[]";
|
|
|
|
|
|
|
|
$oConfig = Registry::getConfig();
|
|
|
|
$oView = $oConfig->getTopActiveView();
|
2024-01-19 11:54:48 +01:00
|
|
|
/** @var User|false|null $oUser */
|
2023-01-19 15:31:56 +01:00
|
|
|
$oUser = $oConfig->getUser();
|
|
|
|
|
2023-03-17 08:58:15 +01:00
|
|
|
$cl = $this->getTopActiveClassName();
|
2023-01-19 15:31:56 +01:00
|
|
|
$aPageTypes = [
|
|
|
|
"content" => "cms",
|
|
|
|
"details" => "product",
|
|
|
|
"alist" => "listing",
|
|
|
|
"search" => "listing",
|
|
|
|
"basket" => "checkout",
|
|
|
|
"user" => "checkout",
|
|
|
|
"payment" => "checkout",
|
|
|
|
"order" => "checkout",
|
|
|
|
"thankyou" => "checkout",
|
2023-03-17 08:58:15 +01:00
|
|
|
"start" => "start",
|
2023-01-19 15:31:56 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
$dataLayer = [
|
|
|
|
'page' => [
|
|
|
|
'type' => $aPageTypes[$cl] ?? "unknown",
|
|
|
|
'title' => $oView->getTitle(),
|
|
|
|
'cl' => $cl,
|
|
|
|
],
|
2024-01-19 11:54:48 +01:00
|
|
|
'userid' => $oUser instanceof User ? $oUser->getId() : false,
|
2024-01-17 15:53:51 +01:00
|
|
|
'sessionid' => session_id(),
|
2023-01-19 15:31:56 +01:00
|
|
|
//'httpref' => $_SERVER["HTTP_REFERER"] ?? "unknown"
|
|
|
|
];
|
|
|
|
|
2023-01-20 11:24:30 +01:00
|
|
|
return json_encode([$dataLayer], JSON_PRETTY_PRINT);
|
2023-01-19 15:31:56 +01:00
|
|
|
}
|
|
|
|
|
2023-08-16 10:44:50 +02:00
|
|
|
public function isDebugModeOn() :bool
|
|
|
|
{
|
2024-05-29 11:59:38 +02:00
|
|
|
return $this->d3GetModuleConfigParam("_blEnableDebug");
|
2023-08-16 10:44:50 +02:00
|
|
|
}
|
|
|
|
|
2024-03-19 09:22:07 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
*/
|
|
|
|
public function getServerSidetaggingJsDomain() :string
|
|
|
|
{
|
2024-05-29 11:59:38 +02:00
|
|
|
return $this->d3GetModuleConfigParam("_sServersidetagging_js");
|
2024-03-19 09:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
*/
|
|
|
|
public function getServerSidetaggingNoJsDomain() :string
|
|
|
|
{
|
2024-05-29 11:59:38 +02:00
|
|
|
return $this->d3GetModuleConfigParam('_sServersidetagging_nojs');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $configParamName
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function d3GetModuleConfigParam(string $configParamName)
|
|
|
|
{
|
|
|
|
return Registry::getConfig()->getShopConfVar(Constants::OXID_MODULE_ID.$configParamName, null, Constants::OXID_MODULE_ID);
|
2024-03-19 09:22:07 +01:00
|
|
|
}
|
2024-05-29 15:51:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function d3IsUsercentricsCMPChosen() :bool
|
|
|
|
{
|
2024-05-31 15:18:26 +02:00
|
|
|
$sCMPPubName = $this->d3GetModuleConfigParam('_HAS_STD_MANAGER');
|
|
|
|
$aPossibleCMP = (oxNew(ManagerTypes::class))->getManagerList();
|
|
|
|
|
|
|
|
return (bool) ($sCMPPubName === Usercentrics::sExternalIncludationInternalName
|
|
|
|
or $sCMPPubName === Usercentrics::sModuleIncludationInternalName);
|
2024-05-29 15:51:16 +02:00
|
|
|
}
|
2018-07-04 15:47:37 +02:00
|
|
|
}
|