diff --git a/Application/Controller/Admin/GA4AdminUserInterface_main.php b/Application/Controller/Admin/GA4AdminUserInterface_main.php index 2782469..f23e577 100644 --- a/Application/Controller/Admin/GA4AdminUserInterface_main.php +++ b/Application/Controller/Admin/GA4AdminUserInterface_main.php @@ -37,6 +37,7 @@ class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controlle '_blEnableDebug', '_blEnableConsentMode', '_blEnableOwnCookieManager', + '_blUseRealCategoyTitles', '_blEnableMeasurementCapabilities', '_blEnableUsercentricsConsentModeApi', ]; diff --git a/Application/views/de/d3googleanalytics4_lang.php b/Application/views/de/d3googleanalytics4_lang.php index 3b3a0cc..e8c3c32 100644 --- a/Application/views/de/d3googleanalytics4_lang.php +++ b/Application/views/de/d3googleanalytics4_lang.php @@ -39,6 +39,11 @@ return [
Ein einfaches anschalten dieser Funktion regelt noch nicht die völlige Funktionsweise aller beteiligten Instanzen; diese bedarf eine detailliertere Konfiguration!
", + 'D3USEREALCATTITLES' => "Für 'item_category'-Werte die Kategorie-Titel verwenden?", + 'D3USEREALCATTITLES_HELP' => "Für die 'item_category' Werte keine URL-Teile, sondern die Klartext-Kategorie-Titel verwenden, also z.B. 'Haarbürsten' statt 'haarbuersten'.", + + 'D3REPLACECHARS' => "Zeichen ersetzen", + 'D3REPLACECHARS_HELP' => 'Hier alle Zeichen, die aus Kategorie-Titeln entfernt werden sollen, eintragen, also z.B. " um ein Zoll-Zeichen zu entfernen oder "0-9 um das Zollzeichen und alle Ziffern zu entfernen.', // Use CMP? 'D3CMPTABTITLE' => 'Cookie Manager Einstellungen', diff --git a/Modules/Application/Model/articleTreeStructure.php b/Modules/Application/Model/articleTreeStructure.php index a3b12df..718e991 100644 --- a/Modules/Application/Model/articleTreeStructure.php +++ b/Modules/Application/Model/articleTreeStructure.php @@ -2,16 +2,56 @@ namespace D3\GoogleAnalytics4\Modules\Application\Model; +use OxidEsales\Eshop\Core\Registry; +use OxidEsales\Eshop\Core\ViewConfig; + trait articleTreeStructure { + /** + * Get all parent category titles, starting from the base category. + * + * @return array + */ + protected function getParentCategoryTitles() :array + { + $parentTitles[] = $this->getTitle(); + // we may be in Manufacturer, Vendor, etc. + if (method_exists($this, 'getParentCategory')) { + $parent = $this->getParentCategory(); + while ($parent != null) { + $parentTitles[] = $parent->getTitle(); + $parent = $parent->getParentCategory(); + } + } + return array_reverse(array_map([$this, 'cleanUpTitle'], $parentTitles)); + } + /** + * Cleanup title, decode entities, remove some chars and trim + * + * @param string $title + * @return string + */ + public function cleanUpTitle($title) :string + { + // decode encoded characters + $title = html_entity_decode($title, ENT_QUOTES); + // remove unwanted characters, e.g. Zoll " + $charsToReplace = Registry::get(ViewConfig::class)->getCharsToReplaceInCategorTitles(); + $title = preg_replace('/[' . $charsToReplace . ']/', '', $title); + // trim whitespace from both ends of the string + $title = trim($title); + return $title; + } + /** * @param int $indexOfArray * @return string */ public function getSplitCategoryArray(int $indexOfArray = -1, bool $bShallTakeStd = false): string { - if ($bShallTakeStd) { - $splitCatArray = + if ($bShallTakeStd){ + $bUseRealCatTitles = (bool)Registry::get(ViewConfig::class)->d3GetModuleConfigParam('_blUseRealCategoyTitles'); + $splitCatArray = $bUseRealCatTitles ? $this->getParentCategoryTitles() : array_values( array_filter( explode( diff --git a/Modules/Core/ViewConfig.php b/Modules/Core/ViewConfig.php index be32ccb..71da8a1 100644 --- a/Modules/Core/ViewConfig.php +++ b/Modules/Core/ViewConfig.php @@ -66,6 +66,14 @@ class ViewConfig extends ViewConfig_parent return (bool) $this->d3GetModuleConfigParam('_blEnableOwnCookieManager'); } + /** + * @return string + */ + public function getCharsToReplaceInCategorTitles(): string + { + return (string) $this->d3GetModuleConfigParam('_sReplaceChars'); + } + /** * @return bool */ @@ -208,9 +216,20 @@ class ViewConfig extends ViewConfig_parent return json_encode([$dataLayer], JSON_PRETTY_PRINT); } - public function isDebugModeOn(): bool + /** + * @return bool + */ + public function isDebugModeOn() :bool { - return $this->d3GetModuleConfigParam("_blEnableDebug") ?: false; + return $this->d3GetModuleConfigParam("_blEnableDebug")?: false; + } + + /** + * @return bool + */ + public function useRealCategoryTitles(): bool + { + return $this->d3GetModuleConfigParam("_blUseRealCategoyTitles") ?: false; } /** diff --git a/views/smarty/admin/d3googleanalytics4_main.tpl b/views/smarty/admin/d3googleanalytics4_main.tpl index 34c66d7..022730d 100644 --- a/views/smarty/admin/d3googleanalytics4_main.tpl +++ b/views/smarty/admin/d3googleanalytics4_main.tpl @@ -54,6 +54,24 @@ [{oxmultilang ident="D3USEGOOGLECONSENTMODE"}][{oxinputhelp ident="D3USEGOOGLECONSENTMODE_HELP"}] +
+ d3GetModuleConfigParam('_blUseRealCategoyTitles')}]checked[{/if}]> + +
+
+
+ [{oxmultilang ident="D3REPLACECHARS"}] + +
+
[{oxmultilang ident="D3REPLACECHARS_HELP"}]
+
diff --git a/views/smarty/event/add_payment_info.tpl b/views/smarty/event/add_payment_info.tpl index 0d32043..db47cdc 100644 --- a/views/smarty/event/add_payment_info.tpl +++ b/views/smarty/event/add_payment_info.tpl @@ -28,13 +28,14 @@ { 'item_oxid': '[{$gtmCartArticles[$basketindex]->getFieldData('oxid')}]', 'item_id': '[{$gtmCartArticles[$basketindex]->getFieldData('oxartnum')}]', - 'item_name': '[{$gtmCartArticles[$basketindex]->getFieldData('oxtitle')}]', + 'item_name': '[{$gtmCartArticles[$basketindex]->getRawFieldData('oxtitle')}]', 'item_variant': '[{$gtmCartArticles[$basketindex]->getFieldData('oxvarselect')}]', + 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', [{if $gtmBasketItemCategory}] 'item_category': '[{$gtmBasketItemCategory->getSplitCategoryArray(0, true)}]', - 'item_category_2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]', - 'item_category_3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]', - 'item_category_4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]', + 'item_category2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]', + 'item_category3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]', + 'item_category4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]', 'item_list_name': '[{$gtmBasketItemCategory->getSplitCategoryArray()}]', [{/if}] 'price': [{$gtmItemPriceObject->getPrice()}], diff --git a/views/smarty/event/add_to_cart.tpl b/views/smarty/event/add_to_cart.tpl index 6766066..aee818a 100644 --- a/views/smarty/event/add_to_cart.tpl +++ b/views/smarty/event/add_to_cart.tpl @@ -37,16 +37,16 @@ { 'item_oxid': '[{$oGtmProduct->getFieldData('oxid')}]', 'item_id': '[{$oGtmProduct->getFieldData('oxartnum')}]', - 'item_name': '[{$oGtmProduct->getFieldData('oxtitle')}]', - 'price': [{$d3PriceObject->getPrice()}], + 'item_name': '[{$oGtmProduct->getRawFieldData('oxtitle')}]', + [{oxhasrights ident="SHOWARTICLEPRICE"}]'price': [{$d3PriceObject->getPrice()}],[{/oxhasrights}] 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', 'item_variant': '[{if $oGtmProduct->getFieldData('oxvarselect')}][{$oGtmProduct->getFieldData('oxvarselect')}][{/if}]', [{if $gtmCategory}] 'item_category': '[{$gtmCategory->getSplitCategoryArray(0, true)}]', - 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1, true)}]', - 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2, true)}]', - 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3, true)}]', - 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', + 'item_category2': '[{$gtmCategory->getSplitCategoryArray(1, true)}]', + 'item_category3': '[{$gtmCategory->getSplitCategoryArray(2, true)}]', + 'item_category4': '[{$gtmCategory->getSplitCategoryArray(3, true)}]', + 'item_list_name': '[{$gtmCategory->getSplitCategoryArray()}]', [{/if}] 'quantity': iArtQuantity } diff --git a/views/smarty/event/begin_checkout.tpl b/views/smarty/event/begin_checkout.tpl index 41eb3b5..0f8b555 100644 --- a/views/smarty/event/begin_checkout.tpl +++ b/views/smarty/event/begin_checkout.tpl @@ -24,16 +24,18 @@ [{assign var="d3oItemPrice" value=$basketitem->getPrice()}] [{assign var="gtmBasketItem" value=$basketitem->getArticle()}] [{assign var="gtmBasketItemCategory" value=$gtmBasketItem->getCategory()}] + [{assign var="gtmManufacturer" value=$gtmBasketItem->getManufacturer()}] { 'item_oxid': '[{$gtmCartArticles[$basketindex]->getFieldData('oxid')}]', 'item_id': '[{$gtmCartArticles[$basketindex]->getFieldData('oxartnum')}]', - 'item_name': '[{$gtmCartArticles[$basketindex]->getFieldData('oxtitle')}]', + 'item_name': '[{$gtmCartArticles[$basketindex]->getRawFieldData('oxtitle')}]', 'item_variant': '[{$gtmCartArticles[$basketindex]->getFieldData('oxvarselect')}]', + 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', [{if $gtmBasketItemCategory}] 'item_category': '[{$gtmBasketItemCategory->getSplitCategoryArray(0, true)}]', - 'item_category_2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]', - 'item_category_3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]', - 'item_category_4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]', + 'item_category2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]', + 'item_category3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]', + 'item_category4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]', 'item_list_name': '[{$gtmBasketItemCategory->getSplitCategoryArray()}]', [{/if}] 'price': [{$d3oItemPrice->getPrice()}], diff --git a/views/smarty/event/purchase.tpl b/views/smarty/event/purchase.tpl index 9dca5ef..2d5aae5 100644 --- a/views/smarty/event/purchase.tpl +++ b/views/smarty/event/purchase.tpl @@ -26,19 +26,21 @@ [{assign var="gtmPurchaseItemPriceObject" value=$gtmBasketItem->getPrice()}] [{assign var="gtmPurchaseItem" value=$gtmBasketItem->getArticle()}] [{assign var="gtmPurchaseItemCategory" value=$gtmPurchaseItem->getCategory()}] + [{assign var="gtmManufacturer" value=$gtmPurchaseItem->getManufacturer()}] { 'item_oxid': '[{$gtmBasketItem->getFieldData("oxid")}]', 'item_id': '[{$gtmBasketItem->getFieldData("oxartnum")}]', - 'item_name': '[{$gtmBasketItem->getFieldData("oxtitle")}]', - 'affiliation': '[{$gtmBasketItem->getFieldData("oxtitle")}]', + 'item_name': '[{$gtmBasketItem->getRawFieldData("oxtitle")}]', + 'affiliation': '[{$gtmBasketItem->getRawFieldData("oxtitle")}]', 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]', 'item_variant': '[{$gtmBasketItem->getFieldData("oxselvariant")}]', + 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', [{if $gtmPurchaseItemCategory}] 'item_category': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(0, true)}]', - 'item_category_2': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(1, true)}]', - 'item_category_3': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(2, true)}]', - 'item_category_4': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(3, true)}]', + 'item_category2': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(1, true)}]', + 'item_category3': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(2, true)}]', + 'item_category4': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(3, true)}]', 'item_list_name': '[{$gtmPurchaseItemCategory->getSplitCategoryArray()}]', [{/if}] 'price': [{$gtmPurchaseItemPriceObject->getPrice()}], diff --git a/views/smarty/event/remove_from_cart.tpl b/views/smarty/event/remove_from_cart.tpl index 8ea274e..92dcb7c 100644 --- a/views/smarty/event/remove_from_cart.tpl +++ b/views/smarty/event/remove_from_cart.tpl @@ -20,13 +20,13 @@ { 'item_oxid': '[{$rmItem->getFieldData('oxid')}]', 'item_id': '[{$rmItem->getFieldData('oxartnum')}]', - 'item_name': '[{$rmItem->getFieldData('oxtitle')}]', + 'item_name': '[{$rmItem->getRawFieldData('oxtitle')}]', 'item_variant': '[{$rmItem->getFieldData('oxvarselect')}]', [{if $gtmBasketItemCategory}] 'item_category': '[{$gtmBasketItemCategory->getSplitCategoryArray(0, true)}]', - 'item_category_2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]', - 'item_category_3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]', - 'item_category_4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]', + 'item_category2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]', + 'item_category3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]', + 'item_category4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]', 'item_list_name': '[{$gtmBasketItemCategory->getSplitCategoryArray()}]', [{/if}] 'price': [{$d3oItemPrice->getPrice()}], diff --git a/views/smarty/event/view_cart.tpl b/views/smarty/event/view_cart.tpl index da14c8b..83f0dbd 100644 --- a/views/smarty/event/view_cart.tpl +++ b/views/smarty/event/view_cart.tpl @@ -25,13 +25,13 @@ { 'item_oxid': '[{$gtmCartArticles[$basketindex]->getFieldData('oxid')}]', 'item_id': '[{$gtmCartArticles[$basketindex]->getFieldData('oxartnum')}]', - 'item_name': '[{$gtmCartArticles[$basketindex]->getFieldData('oxtitle')}]', + 'item_name': '[{$gtmCartArticles[$basketindex]->getRawFieldData('oxtitle')}]', 'item_variant': '[{$gtmCartArticles[$basketindex]->getFieldData('oxvarselect')}]', [{if $gtmBasketItemCategory}] 'item_category': '[{$gtmBasketItemCategory->getSplitCategoryArray(0, true)}]', - 'item_category_2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]', - 'item_category_3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]', - 'item_category_4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]', + 'item_category2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]', + 'item_category3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]', + 'item_category4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]', 'item_list_name': '[{$gtmBasketItemCategory->getSplitCategoryArray()}]', [{/if}] 'price': [{$d3oItemPrice->getPrice()}], diff --git a/views/smarty/event/view_item.tpl b/views/smarty/event/view_item.tpl index 5aae25a..bf90999 100644 --- a/views/smarty/event/view_item.tpl +++ b/views/smarty/event/view_item.tpl @@ -22,11 +22,11 @@ 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', 'item_variant': '[{if $gtmProduct->getFieldData("oxvarselect")}][{$gtmProduct->getFieldData("oxvarselect")}][{/if}]', [{if $gtmCategory}] - 'item_category': '[{$gtmCategory->getSplitCategoryArray(0, true)}]', - 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1, true)}]', - 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2, true)}]', - 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3, true)}]', - 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', + 'item_category': '[{$gtmCategory->getSplitCategoryArray(0, true)}]', + 'item_category2': '[{$gtmCategory->getSplitCategoryArray(1, true)}]', + 'item_category3': '[{$gtmCategory->getSplitCategoryArray(2, true)}]', + 'item_category4': '[{$gtmCategory->getSplitCategoryArray(3, true)}]', + 'item_list_name': '[{$gtmCategory->getSplitCategoryArray()}]', [{/if}] [{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] 'price': [{$d3PriceObject->getPrice()}] diff --git a/views/smarty/event/view_item_list.tpl b/views/smarty/event/view_item_list.tpl index a1e4de1..4def6eb 100644 --- a/views/smarty/event/view_item_list.tpl +++ b/views/smarty/event/view_item_list.tpl @@ -22,14 +22,14 @@ { 'item_oxid': '[{$gtmProduct->getFieldData("oxid")}]', 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', - 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', - 'price': [{$d3PriceObject->getPrice()}], + 'item_name': '[{$gtmProduct->getRawFieldData("oxtitle")}]', + [{oxhasrights ident="SHOWARTICLEPRICE"}]'price': [{$d3PriceObject->getPrice()}],[{/oxhasrights}] 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', [{if $gtmCategory}] - 'item_category': '[{$gtmCategory->getSplitCategoryArray(0, true)}]', - 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1, true)}]', - 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2, true)}]', - 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3, true)}]', + 'item_category': '[{$gtmCategory->getSplitCategoryArray(0, true)}]', + 'item_category2': '[{$gtmCategory->getSplitCategoryArray(1, true)}]', + 'item_category3': '[{$gtmCategory->getSplitCategoryArray(2, true)}]', + 'item_category4': '[{$gtmCategory->getSplitCategoryArray(3, true)}]', [{/if}] 'quantity': 1 }[{if !$smarty.foreach.gtmProducts.last}],[{/if}] diff --git a/views/smarty/event/view_search_result.tpl b/views/smarty/event/view_search_result.tpl index e92e97e..decd878 100644 --- a/views/smarty/event/view_search_result.tpl +++ b/views/smarty/event/view_search_result.tpl @@ -23,9 +23,9 @@ 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', [{if $gtmCategory}] 'item_category': '[{$gtmCategory->getSplitCategoryArray(0, true)}]', - 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1, true)}]', - 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2, true)}]', - 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3, true)}]', + 'item_category2': '[{$gtmCategory->getSplitCategoryArray(1, true)}]', + 'item_category3': '[{$gtmCategory->getSplitCategoryArray(2, true)}]', + 'item_category4': '[{$gtmCategory->getSplitCategoryArray(3, true)}]', 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', [{/if}] 'quantity': 1