110 lines
3.5 KiB
PHP
110 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*
|
|
* https://www.d3data.de
|
|
*
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
* @link https://www.oxidmodule.com
|
|
*/
|
|
|
|
namespace D3\GoogleAnalytics4\Modules\Core;
|
|
|
|
use OxidEsales\Eshop\Application\Controller\FrontendController;
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface;
|
|
|
|
class ViewConfig extends ViewConfig_parent
|
|
{
|
|
|
|
// Google Tag Manager Container ID
|
|
private $sContainerId = null;
|
|
|
|
public function getGtmContainerId()
|
|
{
|
|
if ($this->sContainerId === null)
|
|
{
|
|
$this->sContainerId = ContainerFactory::getInstance()
|
|
->getContainer()
|
|
->get(ModuleSettingBridgeInterface::class)
|
|
->get('d3_gtm_sContainerID', 'd3googleanalytics4');
|
|
}
|
|
return $this->sContainerId;
|
|
}
|
|
|
|
/**
|
|
* @param $sCookieID
|
|
* @return bool
|
|
*/
|
|
public function D3blAcceptedCookie($sCookieID)
|
|
{
|
|
$oSession = Registry::getSession();
|
|
$aCookies = $oSession->getVariable("aCookieSel");
|
|
|
|
if (!is_null($aCookies) && is_array($aCookies) && array_key_exists($sCookieID, $aCookies) && $aCookies[$sCookieID] == "1") {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private $blGA4enabled = null;
|
|
|
|
public function isGA4enabled()
|
|
{
|
|
if ($this->blGA4enabled === null)
|
|
{
|
|
$this->sContainerId = ContainerFactory::getInstance()
|
|
->getContainer()
|
|
->get(ModuleSettingBridgeInterface::class)
|
|
->get('d3_gtm_blEnableGA4', 'd3googleanalytics4');
|
|
}
|
|
|
|
return $this->blGA4enabled;
|
|
}
|
|
|
|
public function getGtmDataLayer()
|
|
{
|
|
if (!$this->getGtmContainerId()) return "[]";
|
|
|
|
$oConfig = Registry::getConfig();
|
|
$oView = $oConfig->getTopActiveView();
|
|
/** @var FrontendController $oShop */
|
|
$oUser = $oConfig->getUser();
|
|
|
|
$cl = $this->getTopActionClassName();
|
|
$aPageTypes = [
|
|
"content" => "cms",
|
|
"details" => "product",
|
|
"alist" => "listing",
|
|
"search" => "listing",
|
|
"basket" => "checkout",
|
|
"user" => "checkout",
|
|
"payment" => "checkout",
|
|
"order" => "checkout",
|
|
"thankyou" => "checkout",
|
|
];
|
|
|
|
$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);
|
|
}
|
|
|
|
public function isPromotionList($listId)
|
|
{
|
|
$oConfig = Registry::getConfig();
|
|
$aPromotionListIds = $oConfig->getConfigParam("") ?? ['bargainItems', 'newItems', 'topBox', 'alsoBought', 'accessories', 'cross'];
|
|
}
|
|
} |