2023-01-19 15:31:56 +01:00
|
|
|
<?php
|
2023-01-27 09:07:09 +01:00
|
|
|
/**
|
2023-05-23 10:49:40 +02: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-27 09:07:09 +01:00
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
2023-05-23 10:49:40 +02:00
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
2023-01-19 15:31:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\GoogleAnalytics4\Modules\Core;
|
|
|
|
|
2023-06-26 17:41: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;
|
|
|
|
|
|
|
|
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-27 08:59:06 +01:00
|
|
|
$this->sContainerId = $this->getConfig()->getConfigParam('d3_gtm_sContainerID');
|
2023-01-19 15:31:56 +01:00
|
|
|
}
|
|
|
|
return $this->sContainerId;
|
|
|
|
}
|
|
|
|
|
2023-05-23 14:33:35 +02:00
|
|
|
/**
|
2023-06-26 17:41:00 +02:00
|
|
|
* @return void
|
2023-05-23 14:33:35 +02:00
|
|
|
*/
|
2023-06-26 17:41:00 +02:00
|
|
|
public function defineCookieManagerType() :void
|
2023-04-04 10:15:15 +02:00
|
|
|
{
|
|
|
|
if ($this->sCookieManagerType === null)
|
|
|
|
{
|
2023-06-26 17:41:00 +02:00
|
|
|
/** @var ManagerHandler $oManagerHandler */
|
|
|
|
$oManagerHandler = oxNew(ManagerHandler::class);
|
|
|
|
$this->sCookieManagerType = $oManagerHandler->getCurrManager();
|
2023-04-04 10:15:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-31 14:11:50 +02:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2023-06-26 17:41:00 +02:00
|
|
|
public function shallUseOwnCookieManager() :bool
|
2023-05-31 14:11:50 +02:00
|
|
|
{
|
|
|
|
return (bool) Registry::getConfig()->getConfigParam('d3_gtm_settings_hasOwnCookieManager');
|
|
|
|
}
|
|
|
|
|
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-06-26 17:41:00 +02:00
|
|
|
if (!$this->shallUseOwnCookieManager()) {
|
2023-02-01 15:32:28 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-26 17:41:00 +02:00
|
|
|
$this->defineCookieManagerType();
|
|
|
|
|
2023-06-27 09:39:43 +02:00
|
|
|
$sCookieID = trim($oConfig->getConfigParam('d3_gtm_settings_cookieName'));
|
2023-04-04 10:15:15 +02:00
|
|
|
|
|
|
|
// Netensio Cookie Manager
|
2023-06-26 17:41: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-06-26 17:41: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-06-26 17:41: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-05-23 14:52:07 +02:00
|
|
|
// UserCentrics or consentmanager
|
2023-06-26 17:41:00 +02:00
|
|
|
if (
|
|
|
|
$this->sCookieManagerType === ManagerTypes::USERCENTRICS_MODULE
|
|
|
|
or $this->sCookieManagerType === ManagerTypes::USERCENTRICS_MANUALLY
|
|
|
|
or $this->sCookieManagerType === ManagerTypes::CONSENTMANAGER
|
2023-06-27 09:39:43 +02:00
|
|
|
or $this->sCookieManagerType === ManagerTypes::COOKIEFIRST
|
2023-06-26 17:41: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-06-26 17:41:00 +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-06-26 17:41:00 +02:00
|
|
|
public function getGtmScriptAttributes() :string
|
2023-04-04 10:15:15 +02:00
|
|
|
{
|
2023-06-27 09:39:43 +02:00
|
|
|
$sCookieId = trim(Registry::getConfig()->getConfigParam('d3_gtm_settings_cookieName'));
|
2023-05-15 15:06:25 +02:00
|
|
|
|
2023-05-31 14:11:50 +02:00
|
|
|
if (false === $this->shallUseOwnCookieManager()){
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-06-26 17:41:00 +02:00
|
|
|
if (
|
|
|
|
$this->sCookieManagerType === ManagerTypes::USERCENTRICS_MODULE
|
|
|
|
or $this->sCookieManagerType === ManagerTypes::USERCENTRICS_MANUALLY
|
|
|
|
)
|
|
|
|
{
|
2023-04-04 10:15:15 +02:00
|
|
|
if ($sCookieId) {
|
2023-05-26 13:49:50 +02:00
|
|
|
return 'data-usercentrics="' . $sCookieId . '" type="text/plain" async=""';
|
2023-04-04 10:15:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 17:41:00 +02:00
|
|
|
if ($this->sCookieManagerType === ManagerTypes::CONSENTMANAGER)
|
|
|
|
{
|
2023-05-15 15:06:25 +02:00
|
|
|
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"
|
|
|
|
';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 09:39:43 +02:00
|
|
|
if ($this->sCookieManagerType === ManagerTypes::COOKIEFIRST){
|
|
|
|
return 'type="text/plain" data-cookiefirst-category="' . $sCookieId .'"';
|
|
|
|
}
|
|
|
|
|
2023-04-04 10:15:15 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-01-19 15:31:56 +01:00
|
|
|
private $blGA4enabled = null;
|
|
|
|
|
|
|
|
public function isGA4enabled()
|
|
|
|
{
|
|
|
|
if ($this->blGA4enabled === null)
|
|
|
|
{
|
2023-01-27 08:59:06 +01:00
|
|
|
$this->sContainerId = $this->getConfig()->getConfigParam('d3_gtm_blEnableGA4');
|
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"
|
|
|
|
];
|
|
|
|
|
|
|
|
return json_encode([$dataLayer], JSON_PRETTY_PRINT);
|
2023-01-27 09:07:09 +01:00
|
|
|
}
|
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
|
|
|
}
|