From 2b8192da2676dcefb56d56a39dd4aaa747ba6509 Mon Sep 17 00:00:00 2001 From: MaxBUhe Date: Tue, 10 Jun 2025 14:24:09 +0200 Subject: [PATCH] - Change item_category_X to item_categoryX etc. - add item_brand to all events - add option to use real category titles instead of url parts for item_categoryX - add option to replace chars in item_categoryX values thanks to Stefan Moisees@beffy@proudcommerce.com --- .../Admin/GA4AdminUserInterface_main.php | 1 + .../admin/de/d3googleanalytics4_lang.php | 5 ++ Application/views/admin/de/module_options.php | 1 + .../admin/tpl/d3googleanalytics4_main.tpl | 18 +++++++ Application/views/event/add_payment_info.tpl | 9 ++-- Application/views/event/add_to_cart.tpl | 10 ++-- Application/views/event/begin_checkout.tpl | 10 ++-- Application/views/event/purchase.tpl | 12 +++-- Application/views/event/remove_from_cart.tpl | 8 ++-- Application/views/event/view_cart.tpl | 8 ++-- Application/views/event/view_item.tpl | 10 ++-- Application/views/event/view_item_list.tpl | 10 ++-- .../views/event/view_search_result.tpl | 8 ++-- Application/views/ga4/remove_from_cart.tpl | 48 ------------------- Application/views/ga4/view_search_result.tpl | 44 ----------------- .../Model/articleTreeStructure.php | 42 +++++++++++++++- Modules/Core/ViewConfig.php | 21 +++++++- 17 files changed, 131 insertions(+), 134 deletions(-) delete mode 100644 Application/views/ga4/remove_from_cart.tpl delete mode 100644 Application/views/ga4/view_search_result.tpl diff --git a/Application/Controller/Admin/GA4AdminUserInterface_main.php b/Application/Controller/Admin/GA4AdminUserInterface_main.php index d55e9f1..91b7669 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/admin/de/d3googleanalytics4_lang.php b/Application/views/admin/de/d3googleanalytics4_lang.php index 67944a6..1781620 100644 --- a/Application/views/admin/de/d3googleanalytics4_lang.php +++ b/Application/views/admin/de/d3googleanalytics4_lang.php @@ -42,6 +42,11 @@ $aLang = array(
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/Application/views/admin/de/module_options.php b/Application/views/admin/de/module_options.php index fed5414..8c0efed 100755 --- a/Application/views/admin/de/module_options.php +++ b/Application/views/admin/de/module_options.php @@ -31,6 +31,7 @@ $aLang = [ 'SHOP_MODULE_'.Constants::OXID_MODULE_ID.'_blGA4enab' => 'GA4 Aktivieren', 'SHOP_MODULE_'.Constants::OXID_MODULE_ID.'_blUAenabled' => 'UA Aktivieren', 'SHOP_MODULE_'.Constants::OXID_MODULE_ID.'_blEnableDebug' => 'Debug-Modus aktivieren', + 'SHOP_MODULE_'.Constants::OXID_MODULE_ID.'_blUseRealCategoyTitles' => 'Statt URL-Teilen die tatsächlichen Kategorie-Titel verwenden (item_category)', // Serverside - tagging 'SHOP_MODULE_GROUP_'.Constants::OXID_MODULE_ID.'_serversidetagging' => 'Server-Side tagging', diff --git a/Application/views/admin/tpl/d3googleanalytics4_main.tpl b/Application/views/admin/tpl/d3googleanalytics4_main.tpl index 57a8b51..699f366 100644 --- a/Application/views/admin/tpl/d3googleanalytics4_main.tpl +++ b/Application/views/admin/tpl/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/Application/views/event/add_payment_info.tpl b/Application/views/event/add_payment_info.tpl index 731504f..8ed4543 100644 --- a/Application/views/event/add_payment_info.tpl +++ b/Application/views/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}] [{oxhasrights ident="SHOWARTICLEPRICE"}]'price': [{$gtmItemPriceObject->getPrice()}],[{/oxhasrights}] diff --git a/Application/views/event/add_to_cart.tpl b/Application/views/event/add_to_cart.tpl index cdaf369..aee818a 100644 --- a/Application/views/event/add_to_cart.tpl +++ b/Application/views/event/add_to_cart.tpl @@ -37,16 +37,16 @@ { 'item_oxid': '[{$oGtmProduct->getFieldData('oxid')}]', 'item_id': '[{$oGtmProduct->getFieldData('oxartnum')}]', - 'item_name': '[{$oGtmProduct->getFieldData('oxtitle')}]', + '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/Application/views/event/begin_checkout.tpl b/Application/views/event/begin_checkout.tpl index 5fab3ac..89eb44a 100644 --- a/Application/views/event/begin_checkout.tpl +++ b/Application/views/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}] [{oxhasrights ident="SHOWARTICLEPRICE"}]'price': [{$d3oItemPrice->getPrice()}],[{/oxhasrights}] diff --git a/Application/views/event/purchase.tpl b/Application/views/event/purchase.tpl index 6acf274..91984b4 100644 --- a/Application/views/event/purchase.tpl +++ b/Application/views/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}] [{oxhasrights ident="SHOWARTICLEPRICE"}]'price': [{$gtmPurchaseItemPriceObject->getPrice()}],[{/oxhasrights}] diff --git a/Application/views/event/remove_from_cart.tpl b/Application/views/event/remove_from_cart.tpl index dfcad04..380d6eb 100644 --- a/Application/views/event/remove_from_cart.tpl +++ b/Application/views/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}] [{oxhasrights ident="SHOWARTICLEPRICE"}]'price': [{$d3oItemPrice->getPrice()}],[{/oxhasrights}] diff --git a/Application/views/event/view_cart.tpl b/Application/views/event/view_cart.tpl index 01c5ac5..d1df8b6 100644 --- a/Application/views/event/view_cart.tpl +++ b/Application/views/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}] [{oxhasrights ident="SHOWARTICLEPRICE"}]'price': [{$d3oItemPrice->getPrice()}],[{/oxhasrights}] diff --git a/Application/views/event/view_item.tpl b/Application/views/event/view_item.tpl index f008e14..0b3c8eb 100644 --- a/Application/views/event/view_item.tpl +++ b/Application/views/event/view_item.tpl @@ -21,11 +21,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()}] [{oxhasrights ident="SHOWARTICLEPRICE"}]'price': [{$d3PriceObject->getPrice()}][{/oxhasrights}] diff --git a/Application/views/event/view_item_list.tpl b/Application/views/event/view_item_list.tpl index 1367ec9..4def6eb 100644 --- a/Application/views/event/view_item_list.tpl +++ b/Application/views/event/view_item_list.tpl @@ -22,14 +22,14 @@ { 'item_oxid': '[{$gtmProduct->getFieldData("oxid")}]', 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', - 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', + '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/Application/views/event/view_search_result.tpl b/Application/views/event/view_search_result.tpl index ab724de..065ea2e 100644 --- a/Application/views/event/view_search_result.tpl +++ b/Application/views/event/view_search_result.tpl @@ -18,14 +18,14 @@ { 'item_oxid': '[{$gtmProduct->getFieldData("oxid")}]', 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', - 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', + '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_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 diff --git a/Application/views/ga4/remove_from_cart.tpl b/Application/views/ga4/remove_from_cart.tpl deleted file mode 100644 index 6b3111f..0000000 --- a/Application/views/ga4/remove_from_cart.tpl +++ /dev/null @@ -1,48 +0,0 @@ -[{$smarty.block.parent}] - -[{block name="d3_ga4_remove_from_cart_block"}] - [{if $hasBeenReloaded}] - [{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}] - [{capture assign=d3_ga4_remove_from_cart}] - [{strip}] - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - dataLayer.push({ - 'isRemoveFromCart': true, - 'event': 'remove_from_cart', - 'eventLabel':'remove_from_cart', - 'ecommerce': { - 'actionField': "step: 1", - 'currency': "[{$currency->name}]", - 'value': [{$d3BasketPrice->getPrice()}], - 'coupon': '[{foreach from=$oxcmp_basket->getVouchers() item=sVoucher key=key name=Voucher}][{$sVoucher->sVoucherNr}][{if !$smarty.foreach.Voucher.last}], [{/if}][{/foreach}]', - 'items': [ - [{foreach from=$toRemoveArticles->getArray() name=gtmRemovedItems item=rmItem key=rmItemindex}] - [{assign var="d3oItemPrice" value=$rmItem->getPrice()}] - [{assign var="gtmBasketItemCategory" value=$rmItem->getCategory()}] - { - 'item_id': '[{$rmItem->getFieldData('oxartnum')}]', - 'item_name': '[{$rmItem->getFieldData('oxtitle')}]', - 'item_variant': '[{$rmItem->getFieldData('oxvarselect')}]', - [{if $gtmBasketItemCategory}] - 'item_category': '[{$gtmBasketItemCategory->getSplitCategoryArray(0)}]', - 'item_category_2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1)}]', - 'item_category_3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2)}]', - 'item_category_4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3)}]', - 'item_list_name': '[{$gtmBasketItemCategory->getSplitCategoryArray()}]', - [{/if}] - [{oxhasrights ident="SHOWARTICLEPRICE"}]'price': [{$d3oItemPrice->getPrice()}],[{/oxhasrights}] - 'coupon': '[{foreach from=$oxcmp_basket->getVouchers() item=sVoucher key=key name=Voucher}][{$sVoucher->sVoucherNr}][{if !$smarty.foreach.Voucher.last}], [{/if}][{/foreach}]', - 'quantity': '[{$rmItem->getFieldData('d3AmountThatGotRemoved')}]', - 'position': [{$smarty.foreach.gtmRemovedItems.index}] - }[{if !$smarty.foreach.gtmRemovedItems.last}],[{/if}] - [{/foreach}] - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }); - [{/strip}] - [{/capture}] - [{oxscript add=$d3_ga4_remove_from_cart}] - [{/if}] -[{/block}] \ No newline at end of file diff --git a/Application/views/ga4/view_search_result.tpl b/Application/views/ga4/view_search_result.tpl deleted file mode 100644 index b1ca51c..0000000 --- a/Application/views/ga4/view_search_result.tpl +++ /dev/null @@ -1,44 +0,0 @@ -[{$smarty.block.parent}] - -[{assign var="gtmProducts" value=$oView->getArticleList()}] - -[{block name="d3_ga4_view_search_result_block"}] - [{if $gtmProducts}] - [{capture assign=d3_ga4_view_search_result}] - [{strip}] - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - dataLayer.push({ - 'event': 'view_search_result', - 'eventLabel':'view_search_result[{if $oViewConf->isDebugModeOn()}]_test[{/if}]', - 'ecommerce': { - 'search_term': '[{$searchparamforhtml}]', - 'items': [ - [{foreach from=$gtmProducts name="gtmProducts" item="gtmProduct"}] - [{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] - [{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] - [{assign var="gtmCategory" value=$gtmProduct->getCategory()}] - { - 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', - 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', - [{oxhasrights ident="SHOWARTICLEPRICE"}]'price': [{$d3PriceObject->getPrice()}],[{/oxhasrights}] - 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', - [{if $gtmCategory}] - 'item_category': '[{$gtmCategory->getSplitCategoryArray(0)}]', - 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1)}]', - 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2)}]', - 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3)}]', - 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', - [{/if}] - 'quantity': 1 - }[{if !$smarty.foreach.gtmProducts.last}],[{/if}] - [{/foreach}] - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }); - [{/strip}] - [{/capture}] - [{oxscript add=$d3_ga4_view_search_result}] - [{/if}] -[{/block}] \ No newline at end of file diff --git a/Modules/Application/Model/articleTreeStructure.php b/Modules/Application/Model/articleTreeStructure.php index 2389f88..80d0f5c 100644 --- a/Modules/Application/Model/articleTreeStructure.php +++ b/Modules/Application/Model/articleTreeStructure.php @@ -2,8 +2,47 @@ 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 @@ -11,7 +50,8 @@ trait articleTreeStructure public function getSplitCategoryArray(int $indexOfArray = -1, bool $bShallTakeStd = false) :string { if ($bShallTakeStd){ - $splitCatArray = + $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 45bc6b4..dd9b7fd 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 */ @@ -234,12 +242,23 @@ class ViewConfig extends ViewConfig_parent } return $dataLayerGlobals; } - + + /** + * @return bool + */ public function isDebugModeOn() :bool { return $this->d3GetModuleConfigParam("_blEnableDebug")?: false; } + /** + * @return bool + */ + public function useRealCategoryTitles(): bool + { + return $this->d3GetModuleConfigParam("_blUseRealCategoyTitles") ?: false; + } + /** * @return string * @throws ContainerExceptionInterface