From f7bef420aa989d3cf444ee752640df64fdbb3fa3 Mon Sep 17 00:00:00 2001 From: MaxBuhe01 Date: Mon, 16 Dec 2024 17:37:12 +0100 Subject: [PATCH] [OST614872][Added] method for additional globals --- Modules/Core/ViewConfig.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Modules/Core/ViewConfig.php b/Modules/Core/ViewConfig.php index e2fc6a6..7268380 100644 --- a/Modules/Core/ViewConfig.php +++ b/Modules/Core/ViewConfig.php @@ -207,10 +207,34 @@ class ViewConfig extends ViewConfig_parent 'sessionid' => session_id(), //'httpref' => $_SERVER["HTTP_REFERER"] ?? "unknown" ]; + + $dataLayer = $this->d3AdditionalGlobalAnalyticsVariables($dataLayer); return json_encode([$dataLayer], JSON_PRETTY_PRINT); } - + + /** + * @param array $dataLayerGlobals + * @return array + */ + public function d3AdditionalGlobalAnalyticsVariables(array $dataLayerGlobals) :array + { + /** @var User $oUser */ + $oUser = Registry::getSession()->getUser(); + if ($oUser and $oUser->getFieldData('OXUSERNAME')){ + $sUsername = $oUser->getFieldData('OXUSERNAME') ?: ""; + $iCustNr = $oUser->getFieldData('OXCUSTNR') ?: ""; + $iZipCode = $oUser->getFieldData('OXZIP') ?: ""; + + return array_merge($dataLayerGlobals, [ + 'custnr' => $iCustNr, + 'email' => $sUsername, + 'zipcode' => $iZipCode + ]); + } + return $dataLayerGlobals; + } + public function isDebugModeOn() :bool { return $this->d3GetModuleConfigParam("_blEnableDebug")?: false;