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
|
|
|
|
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;
|
2023-01-19 15:31:56 +01:00
|
|
|
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;
|
2023-04-04 10:15:15 +02:00
|
|
|
private $sCookieManagerType = null;
|
2023-01-19 15:31:56 +01:00
|
|
|
|
|
|
|
public function getGtmContainerId()
|
|
|
|
{
|
|
|
|
if ($this->sContainerId === null)
|
|
|
|
{
|
2023-01-20 11:24:30 +01:00
|
|
|
$this->sContainerId = ContainerFactory::getInstance()
|
|
|
|
->getContainer()
|
|
|
|
->get(ModuleSettingBridgeInterface::class)
|
2023-01-27 08:59:06 +01:00
|
|
|
->get('d3_gtm_sContainerID', 'd3googleanalytics4');
|
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
|
|
|
{
|
2023-05-31 12:17:00 +02:00
|
|
|
return (bool) Registry::getConfig()->getConfigParam('d3_gtm_settings_hasOwnCookieManager');
|
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
|
|
|
|
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();
|
|
|
|
|
2023-09-13 15:08:58 +02:00
|
|
|
$sCookieID = trim($oConfig->getConfigParam('d3_gtm_settings_controlParameter'));
|
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 (
|
|
|
|
$this->sCookieManagerType === ManagerTypes::USERCENTRICS_MODULE
|
|
|
|
or $this->sCookieManagerType === ManagerTypes::USERCENTRICS_MANUALLY
|
|
|
|
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
|
|
|
{
|
2023-09-13 15:08:58 +02:00
|
|
|
$sControlParameter = trim(Registry::getConfig()->getConfigParam('d3_gtm_settings_controlParameter'));
|
2023-05-15 15:06:25 +02:00
|
|
|
|
2023-05-31 12:17:00 +02:00
|
|
|
if (false === $this->shallUseOwnCookieManager()){
|
|
|
|
return "";
|
|
|
|
}
|
2023-04-04 10:15:15 +02:00
|
|
|
|
2023-05-31 12:17:00 +02:00
|
|
|
if (
|
|
|
|
$this->sCookieManagerType === ManagerTypes::USERCENTRICS_MODULE
|
|
|
|
or $this->sCookieManagerType === ManagerTypes::USERCENTRICS_MANUALLY
|
|
|
|
)
|
|
|
|
{
|
2023-09-13 14:56:05 +02:00
|
|
|
if ($sControlParameter) {
|
|
|
|
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 14:56:05 +02:00
|
|
|
if ($sControlParameter) {
|
|
|
|
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-01-19 15:31:56 +01:00
|
|
|
private $blGA4enabled = null;
|
|
|
|
|
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)
|
|
|
|
{
|
2023-01-20 11:24:30 +01:00
|
|
|
$this->sContainerId = ContainerFactory::getInstance()
|
|
|
|
->getContainer()
|
|
|
|
->get(ModuleSettingBridgeInterface::class)
|
2023-01-27 08:59:06 +01:00
|
|
|
->get('d3_gtm_blEnableGA4', 'd3googleanalytics4');
|
2023-01-19 15:31:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->blGA4enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getGtmDataLayer()
|
|
|
|
{
|
|
|
|
if (!$this->getGtmContainerId()) return "[]";
|
|
|
|
|
|
|
|
$oConfig = Registry::getConfig();
|
|
|
|
$oView = $oConfig->getTopActiveView();
|
|
|
|
/** @var FrontendController $oShop */
|
|
|
|
$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,
|
|
|
|
],
|
|
|
|
'userid' => ($oUser ? $oUser->getId() : false),
|
|
|
|
'sessionid' => session_id() ?? false,
|
|
|
|
//'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
|
|
|
|
{
|
|
|
|
return Registry::getConfig()->getConfigParam('d3_gtm_blEnableDebug');
|
|
|
|
}
|
|
|
|
|
2023-01-19 15:31:56 +01:00
|
|
|
public function isPromotionList($listId)
|
|
|
|
{
|
|
|
|
$oConfig = Registry::getConfig();
|
|
|
|
$aPromotionListIds = $oConfig->getConfigParam("") ?? ['bargainItems', 'newItems', 'topBox', 'alsoBought', 'accessories', 'cross'];
|
|
|
|
}
|
2018-07-04 15:47:37 +02:00
|
|
|
}
|