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;
|
|
|
|
|
|
|
|
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 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-05-23 14:33:35 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getModuleSettingExplicitManagerSelectValue()
|
|
|
|
{
|
|
|
|
return Registry::getConfig()->getConfigParam('d3_gtm_settings_HAS_STD_MANAGER');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return false|mixed
|
|
|
|
*/
|
|
|
|
public function getExplicitManager()
|
2023-05-15 15:06:25 +02:00
|
|
|
{
|
2023-05-23 14:33:35 +02:00
|
|
|
$sManagerName = $this->getModuleSettingExplicitManagerSelectValue();
|
2023-05-23 14:52:07 +02:00
|
|
|
return $sManagerName === "NONE" ? false : $sManagerName;
|
2023-05-15 15:06:25 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-15 15:06:25 +02:00
|
|
|
|
2023-05-23 14:33:35 +02:00
|
|
|
if ($this->sCookieManagerType === false and $this->getExplicitManager()){
|
|
|
|
return "externalService";
|
2023-05-15 15:06:25 +02:00
|
|
|
}
|
|
|
|
|
2023-04-04 10:15:15 +02:00
|
|
|
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-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
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 14:52:07 +02:00
|
|
|
// UserCentrics or consentmanager
|
2023-05-23 14:33:35 +02:00
|
|
|
if ($this->getCookieManagerType() === "oxps_usercentrics" or $this->getCookieManagerType() === 'externalService') {
|
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
|
|
|
|
*/
|
|
|
|
public function getGtmScriptAttributes()
|
|
|
|
{
|
2023-05-15 15:06:25 +02:00
|
|
|
$oConfig = Registry::getConfig();
|
|
|
|
|
2023-05-23 14:52:07 +02:00
|
|
|
if ($this->getCookieManagerType() === "oxps_usercentrics" or $this->getExplicitManager() === 'USERCENTRICS') {
|
2023-04-04 10:15:15 +02:00
|
|
|
$sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
|
|
|
|
|
|
|
|
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-05-23 14:52:07 +02:00
|
|
|
if ($this->getCookieManagerType() === "externalService" and $this->getExplicitManager() === 'CONSENTMANAGER') {
|
2023-05-15 15:06:25 +02:00
|
|
|
$sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
|
|
|
|
|
|
|
|
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-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
|
|
|
}
|