2023-01-19 15:31:56 +01:00
|
|
|
<?php
|
2023-01-27 09:07:09 +01:00
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
* http://www.shopmodule.com
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
2023-01-19 15:31:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\GoogleAnalytics4\Modules\Core;
|
|
|
|
|
|
|
|
use OxidEsales\Eshop\Application\Controller\FrontendController;
|
|
|
|
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 09:07:09 +01:00
|
|
|
|
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-04-04 10:15:15 +02:00
|
|
|
public function getCookieManagerType()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->sCookieManagerType;
|
|
|
|
}
|
|
|
|
|
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-04-04 10:15:15 +02:00
|
|
|
$oConfig = $this->getConfig();
|
2023-02-01 15:32:28 +01:00
|
|
|
|
2023-04-04 10:15:15 +02:00
|
|
|
// No Cookie Manager in use
|
|
|
|
if (!$oConfig->getConfigParam('d3_gtm_settings_hasOwnCookieManager')) {
|
2023-02-01 15:32:28 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-04-04 10:15:15 +02:00
|
|
|
$sCookieID = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
|
|
|
|
|
|
|
|
// Netensio Cookie Manager
|
|
|
|
if ($this->getCookieManagerType() == "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");
|
|
|
|
}
|
|
|
|
|
2023-03-17 10:59:50 +01:00
|
|
|
// Aggrosoft Cookie Consent
|
2023-04-04 10:15:15 +02:00
|
|
|
if ($this->getCookieManagerType() == "agcookiecompliance") {
|
|
|
|
if (method_exists($this, "isCookieCategoryEnabled")) {
|
|
|
|
return $this->isCookieCategoryEnabled($sCookieID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserCentrics
|
|
|
|
if ($this->getCookieManagerType() == "oxps_usercentrics") {
|
|
|
|
// 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
|
|
|
|
*/
|
|
|
|
public function getGtmScriptAttributes()
|
|
|
|
{
|
|
|
|
if ($this->getCookieManagerType() == "oxps_usercentrics") {
|
|
|
|
$oConfig = $this->getConfig();
|
|
|
|
$sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
|
|
|
|
|
|
|
|
if ($sCookieId) {
|
|
|
|
return 'type="text/plain" data-usercentrics="' . $sCookieId . '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2023-01-27 09:07:09 +01:00
|
|
|
|
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,
|
|
|
|
],
|
|
|
|
'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
|
|
|
}
|