From 229cf3695f58deb67b2070f642c3d5479359988f Mon Sep 17 00:00:00 2001 From: MaxBUhe Date: Tue, 2 Jan 2024 16:07:53 +0100 Subject: [PATCH] [Changed] template structure, template-structure information all block extensions now only include the template instead of having the extension included immediately (dedicated event-templates within views/event); information about the structure changed to the correct paths --- .../blocks/details_productmain_tobasket.tpl | 2 +- .../views/blocks/page_list_listbody.tpl | 2 +- Application/views/blocks/purchase.tpl | 55 +------- Application/views/blocks/remove_from_cart.tpl | 3 + .../views/blocks/start_welcome_text.tpl | 2 +- Application/views/blocks/view_cart.tpl | 49 +------ Application/views/blocks/view_item.tpl | 39 +----- Application/views/blocks/view_item_list.tpl | 3 + .../views/blocks/view_search_result.tpl | 3 + .../views/{ga4 => event}/add_to_cart.tpl | 120 +++++++++--------- Application/views/event/purchase.tpl | 56 ++++++++ .../views/{ga4 => event}/remove_from_cart.tpl | 2 - Application/views/event/view_cart.tpl | 50 ++++++++ Application/views/event/view_item.tpl | 41 ++++++ .../views/{ga4 => event}/view_item_list.tpl | 89 +++++++------ .../{ga4 => event}/view_search_result.tpl | 2 - .../tpl/page/account/d3gtmnoticelist.tpl | 2 +- .../page/account/d3gtmrecommendationlist.tpl | 2 +- .../views/tpl/page/account/d3gtmwishlist.tpl | 2 +- CHANGELOG.md | 7 + Docs/README.md | 2 +- metadata.php | 16 ++- 22 files changed, 288 insertions(+), 261 deletions(-) create mode 100644 Application/views/blocks/remove_from_cart.tpl create mode 100644 Application/views/blocks/view_item_list.tpl create mode 100644 Application/views/blocks/view_search_result.tpl rename Application/views/{ga4 => event}/add_to_cart.tpl (97%) create mode 100644 Application/views/event/purchase.tpl rename Application/views/{ga4 => event}/remove_from_cart.tpl (98%) create mode 100644 Application/views/event/view_cart.tpl create mode 100644 Application/views/event/view_item.tpl rename Application/views/{ga4 => event}/view_item_list.tpl (96%) rename Application/views/{ga4 => event}/view_search_result.tpl (98%) diff --git a/Application/views/blocks/details_productmain_tobasket.tpl b/Application/views/blocks/details_productmain_tobasket.tpl index 6f3c741..6ccb0de 100644 --- a/Application/views/blocks/details_productmain_tobasket.tpl +++ b/Application/views/blocks/details_productmain_tobasket.tpl @@ -1,3 +1,3 @@ [{$smarty.block.parent}] -[{include file="addtocart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] \ No newline at end of file +[{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] \ No newline at end of file diff --git a/Application/views/blocks/page_list_listbody.tpl b/Application/views/blocks/page_list_listbody.tpl index 6f3c741..6ccb0de 100644 --- a/Application/views/blocks/page_list_listbody.tpl +++ b/Application/views/blocks/page_list_listbody.tpl @@ -1,3 +1,3 @@ [{$smarty.block.parent}] -[{include file="addtocart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] \ No newline at end of file +[{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] \ No newline at end of file diff --git a/Application/views/blocks/purchase.tpl b/Application/views/blocks/purchase.tpl index 9878983..dd15b60 100644 --- a/Application/views/blocks/purchase.tpl +++ b/Application/views/blocks/purchase.tpl @@ -1,56 +1,3 @@ [{$smarty.block.parent}] -[{block name="d3_ga4_purchase_block"}] - [{capture name="d3_ga4_purchase"}] - [{strip}] - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - [{assign var="gtmOrder" value=$oView->getOrder()}] - [{assign var="gtmBasket" value=$oView->getBasket()}] - [{assign var="gtmArticles" value=$gtmOrder->getOrderArticles()}] - [{assign var="gtmOrderVouchers" value=$gtmOrder->getVoucherNrList()}] - - dataLayer.push({ - 'event': 'purchase', - 'eventLabel':'Checkout Step 5', - 'ecommerce': { - 'transaction_id': '[{$gtmOrder->getFieldData("oxordernr")}]', - 'affiliation': '[{$oxcmp_shop->getFieldData("oxname")}]', - 'value': [{$gtmOrder->getTotalOrderSum()}], - 'tax': [{math equation="x+y" x=$gtmOrder->getFieldData("oxartvatprice1") y=$gtmOrder->getFieldData("oxartvatprice2") }], - 'shipping': [{$gtmOrder->getFieldData("oxdelcost")}], - 'currency': '[{$gtmOrder->getFieldData('oxcurrency')}]', - 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]', - 'paymentType': '[{$gtmBasket->getPaymentOnPaymentId()}]', - 'items': [ - [{foreach from=$gtmArticles item="gtmBasketItem" name="gtmArticles"}] - [{assign var="gtmPurchaseItemPriceObject" value=$gtmBasketItem->getPrice()}] - [{assign var="gtmPurchaseItem" value=$gtmBasketItem->getArticle()}] - [{assign var="gtmPurchaseItemCategory" value=$gtmPurchaseItem->getCategory()}] - - { - 'item_id': '[{$gtmBasketItem->getFieldData("oxartnum")}]', - 'item_name': '[{$gtmBasketItem->getFieldData("oxtitle")}]', - 'affiliation': '[{$gtmBasketItem->getFieldData("oxtitle")}]', - 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]', - 'item_variant': '[{$gtmBasketItem->getFieldData("oxselvariant")}]', - [{if $gtmPurchaseItemCategory}] - 'item_category': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(0)}]', - 'item_category_2': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(1)}]', - 'item_category_3': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(2)}]', - 'item_category_4': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(3)}]', - 'item_list_name': '[{$gtmPurchaseItemCategory->getSplitCategoryArray()}]', - [{/if}] - 'price': [{$gtmPurchaseItemPriceObject->getPrice()}], - 'quantity': [{$gtmBasketItem->getFieldData("oxamount")}], - 'position': [{$smarty.foreach.gtmArticles.iteration}] - }[{if !$smarty.foreach.gtmArticles.last}],[{/if}] - [{/foreach}] - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }) - [{/strip}] - [{/capture}] - [{oxscript add=$smarty.capture.d3_ga4_purchase}] -[{/block}] \ No newline at end of file +[{include file="event/purchase.tpl"}] \ No newline at end of file diff --git a/Application/views/blocks/remove_from_cart.tpl b/Application/views/blocks/remove_from_cart.tpl new file mode 100644 index 0000000..3fd874a --- /dev/null +++ b/Application/views/blocks/remove_from_cart.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="event/remove_from_cart.tpl"}] \ No newline at end of file diff --git a/Application/views/blocks/start_welcome_text.tpl b/Application/views/blocks/start_welcome_text.tpl index 6f3c741..6ccb0de 100644 --- a/Application/views/blocks/start_welcome_text.tpl +++ b/Application/views/blocks/start_welcome_text.tpl @@ -1,3 +1,3 @@ [{$smarty.block.parent}] -[{include file="addtocart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] \ No newline at end of file +[{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] \ No newline at end of file diff --git a/Application/views/blocks/view_cart.tpl b/Application/views/blocks/view_cart.tpl index 0ac03f3..7f795e7 100644 --- a/Application/views/blocks/view_cart.tpl +++ b/Application/views/blocks/view_cart.tpl @@ -1,50 +1,3 @@ [{$smarty.block.parent}] -[{*$oxcmp_basket|get_class_methods|dumpvar*}] - -[{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}] -[{assign var='gtmCartArticles' value=$oView->getBasketArticles()}] - -[{block name="d3_ga4_view_cart_block"}] - [{capture name="d3_ga4_view_cart"}] - [{strip}] - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - dataLayer.push({ - 'event': 'view_cart', - 'eventLabel':'Checkout Step 1', - '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=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}] - [{assign var="d3oItemPrice" value=$basketitem->getPrice()}] - [{assign var="gtmBasketItem" value=$basketitem->getArticle()}] - [{assign var="gtmBasketItemCategory" value=$gtmBasketItem->getCategory()}] - { - 'item_id': '[{$gtmCartArticles[$basketindex]->getFieldData('oxartnum')}]', - 'item_name': '[{$gtmCartArticles[$basketindex]->getFieldData('oxtitle')}]', - 'item_variant': '[{$gtmCartArticles[$basketindex]->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}] - 'price': [{$d3oItemPrice->getPrice()}], - 'coupon': '[{foreach from=$oxcmp_basket->getVouchers() item=sVoucher key=key name=Voucher}][{$sVoucher->sVoucherNr}][{if !$smarty.foreach.Voucher.last}], [{/if}][{/foreach}]', - 'quantity': [{$basketitem->getAmount()}], - 'position': [{$smarty.foreach.gtmCartContents.index}] - }[{if !$smarty.foreach.gtmCartContents.last}],[{/if}] - [{/foreach}] - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }); - [{/strip}] - [{/capture}] - [{oxscript add=$smarty.capture.d3_ga4_view_cart}] -[{/block}] \ No newline at end of file +[{include file="event/view_cart.tpl"}] \ No newline at end of file diff --git a/Application/views/blocks/view_item.tpl b/Application/views/blocks/view_item.tpl index c274d42..b4dbab0 100644 --- a/Application/views/blocks/view_item.tpl +++ b/Application/views/blocks/view_item.tpl @@ -1,40 +1,3 @@ [{$smarty.block.parent}] -[{assign var="gtmProduct" value=$oView->getProduct()}] -[{assign var="gtmCategory" value=$gtmProduct->getCategory()}] -[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] -[{block name="d3_ga4_view_item_block"}] - [{capture name="d3_ga4_view_item"}] - [{strip}] - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - - dataLayer.push({ - 'event': 'view_item', - 'eventLabel':'Product View', - 'ecommerce': { - 'currency': '[{$currency->name}]', - 'items': [ - { - 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', - 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', - '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)}]', - 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1)}]', - 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2)}]', - 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3)}]', - 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', - [{/if}] - [{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] - 'price': [{$d3PriceObject->getPrice()}] - } - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }); - [{/strip}] - [{/capture}] - [{oxscript add=$smarty.capture.d3_ga4_view_item}] -[{/block}] \ No newline at end of file +[{include file="event/view_item.tpl"}] \ No newline at end of file diff --git a/Application/views/blocks/view_item_list.tpl b/Application/views/blocks/view_item_list.tpl new file mode 100644 index 0000000..beba87d --- /dev/null +++ b/Application/views/blocks/view_item_list.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="event/view_item_list.tpl"}] \ No newline at end of file diff --git a/Application/views/blocks/view_search_result.tpl b/Application/views/blocks/view_search_result.tpl new file mode 100644 index 0000000..1684871 --- /dev/null +++ b/Application/views/blocks/view_search_result.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="event/view_search_result.tpl"}] \ No newline at end of file diff --git a/Application/views/ga4/add_to_cart.tpl b/Application/views/event/add_to_cart.tpl similarity index 97% rename from Application/views/ga4/add_to_cart.tpl rename to Application/views/event/add_to_cart.tpl index 8dfc2e5..5ec242d 100644 --- a/Application/views/ga4/add_to_cart.tpl +++ b/Application/views/event/add_to_cart.tpl @@ -1,61 +1,61 @@ - -[{if $d3CmpBasket->getAddToBasketDecision() && $d3CmpBasket->d3GtmRequestedArticleLoadedByAnid() !== null}] - [{assign var="oGtmProduct" value=$d3CmpBasket->d3GtmRequestedArticleLoadedByAnid()}] - [{assign var="oGtmAmountArticlesAdded" value=$d3CmpBasket->getD3GtmAddToCartAmountArticles()}] - [{*$smarty.block.parent*}] - [{* variable $oGtmProduct is passed from parent tempalte *}] - [{assign var="d3PriceObject" value=$oGtmProduct->getPrice()}] - [{assign var="gtmCurrency" value=$oView->getActCurrency()}] - [{assign var="gtmManufacturer" value=$oGtmProduct->getManufacturer()}] - [{assign var="gtmCategory" value=$oGtmProduct->getCategory()}] - - [{block name="d3_ga4_add_to_cart_list_block"}] - [{capture name="d3_ga4_add_to_cart_listtpl"}] - [{strip}] - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - - [{*** Debug cases ***}] - [{*event.preventDefault();*}] - - let iArtQuantity = $("[{$htmlIdAmountOfArticles}]").val(); - let iArtQuantityAdded = [{$oGtmAmountArticlesAdded}]; - - if(!iArtQuantity && (iArtQuantityAdded === 1)){ - iArtQuantity = 1; - }else{ - iArtQuantity = iArtQuantityAdded; - } - - dataLayer.push({ - 'isAddToBasket': true, - 'event':'add_to_cart', - 'eventLabel': 'add_to_cart', - 'ecommerce': { - 'currency': "[{$currency->name}]", - 'value': iArtQuantity*[{$d3PriceObject->getPrice()}], - 'items': [ - { - 'item_id': '[{$oGtmProduct->getFieldData('oxartnum')}]', - 'item_name': '[{$oGtmProduct->getFieldData('oxtitle')}]', - 'price': [{$d3PriceObject->getPrice()}], - '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)}]', - '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': iArtQuantity - } - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }); - [{/strip}] - [{/capture}] - [{oxscript add=$smarty.capture.d3_ga4_add_to_cart_listtpl}] - [{/block}] + +[{if $d3CmpBasket->getAddToBasketDecision() && $d3CmpBasket->d3GtmRequestedArticleLoadedByAnid() !== null}] + [{assign var="oGtmProduct" value=$d3CmpBasket->d3GtmRequestedArticleLoadedByAnid()}] + [{assign var="oGtmAmountArticlesAdded" value=$d3CmpBasket->getD3GtmAddToCartAmountArticles()}] + [{*$smarty.block.parent*}] + [{* variable $oGtmProduct is passed from parent tempalte *}] + [{assign var="d3PriceObject" value=$oGtmProduct->getPrice()}] + [{assign var="gtmCurrency" value=$oView->getActCurrency()}] + [{assign var="gtmManufacturer" value=$oGtmProduct->getManufacturer()}] + [{assign var="gtmCategory" value=$oGtmProduct->getCategory()}] + + [{block name="d3_ga4_add_to_cart_list_block"}] + [{capture name="d3_ga4_add_to_cart_listtpl"}] + [{strip}] + dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ + + [{*** Debug cases ***}] + [{*event.preventDefault();*}] + + let iArtQuantity = $("[{$htmlIdAmountOfArticles}]").val(); + let iArtQuantityAdded = [{$oGtmAmountArticlesAdded}]; + + if(!iArtQuantity && (iArtQuantityAdded === 1)){ + iArtQuantity = 1; + }else{ + iArtQuantity = iArtQuantityAdded; + } + + dataLayer.push({ + 'isAddToBasket': true, + 'event':'add_to_cart', + 'eventLabel': 'add_to_cart', + 'ecommerce': { + 'currency': "[{$currency->name}]", + 'value': iArtQuantity*[{$d3PriceObject->getPrice()}], + 'items': [ + { + 'item_id': '[{$oGtmProduct->getFieldData('oxartnum')}]', + 'item_name': '[{$oGtmProduct->getFieldData('oxtitle')}]', + 'price': [{$d3PriceObject->getPrice()}], + '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)}]', + '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': iArtQuantity + } + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + [{/strip}] + [{/capture}] + [{oxscript add=$smarty.capture.d3_ga4_add_to_cart_listtpl}] + [{/block}] [{/if}] \ No newline at end of file diff --git a/Application/views/event/purchase.tpl b/Application/views/event/purchase.tpl new file mode 100644 index 0000000..4ea1909 --- /dev/null +++ b/Application/views/event/purchase.tpl @@ -0,0 +1,56 @@ +[{block name="d3_ga4_purchase_block"}] + [{capture name="d3_ga4_purchase"}] + [{strip}] + dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ + [{assign var="gtmOrder" value=$oView->getOrder()}] + [{assign var="gtmBasket" value=$oView->getBasket()}] + [{assign var="gtmArticles" value=$gtmOrder->getOrderArticles()}] + [{assign var="gtmOrderVouchers" value=$gtmOrder->getVoucherNrList()}] + + dataLayer.push({ + 'event': 'purchase', + 'eventLabel':'Checkout Step 5', + 'ecommerce': + { + 'transaction_id': '[{$gtmOrder->getFieldData("oxordernr")}]', + 'affiliation': '[{$oxcmp_shop->getFieldData("oxname")}]', + 'value': [{$gtmOrder->getTotalOrderSum()}], + 'tax': [{math equation="x+y" x=$gtmOrder->getFieldData("oxartvatprice1") y=$gtmOrder->getFieldData("oxartvatprice2") }], + 'shipping': [{$gtmOrder->getFieldData("oxdelcost")}], + 'currency': '[{$gtmOrder->getFieldData('oxcurrency')}]', + 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]', + 'paymentType': '[{$gtmBasket->getPaymentOnPaymentId()}]', + 'items': + [ + [{foreach from=$gtmArticles item="gtmBasketItem" name="gtmArticles"}] + [{assign var="gtmPurchaseItemPriceObject" value=$gtmBasketItem->getPrice()}] + [{assign var="gtmPurchaseItem" value=$gtmBasketItem->getArticle()}] + [{assign var="gtmPurchaseItemCategory" value=$gtmPurchaseItem->getCategory()}] + + { + 'item_id': '[{$gtmBasketItem->getFieldData("oxartnum")}]', + 'item_name': '[{$gtmBasketItem->getFieldData("oxtitle")}]', + 'affiliation': '[{$gtmBasketItem->getFieldData("oxtitle")}]', + 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]', + 'item_variant': '[{$gtmBasketItem->getFieldData("oxselvariant")}]', + [{if $gtmPurchaseItemCategory}] + 'item_category': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(0)}]', + 'item_category_2': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(1)}]', + 'item_category_3': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(2)}]', + 'item_category_4': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(3)}]', + 'item_list_name': '[{$gtmPurchaseItemCategory->getSplitCategoryArray()}]', + [{/if}] + 'price': [{$gtmPurchaseItemPriceObject->getPrice()}], + 'quantity': [{$gtmBasketItem->getFieldData("oxamount")}], + 'position': [{$smarty.foreach.gtmArticles.iteration}] + }[{if !$smarty.foreach.gtmArticles.last}],[{/if}] + [{/foreach}] + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }) + [{/strip}] + [{/capture}] + [{oxscript add=$smarty.capture.d3_ga4_purchase}] +[{/block}] \ No newline at end of file diff --git a/Application/views/ga4/remove_from_cart.tpl b/Application/views/event/remove_from_cart.tpl similarity index 98% rename from Application/views/ga4/remove_from_cart.tpl rename to Application/views/event/remove_from_cart.tpl index 72e7c6b..8de971f 100644 --- a/Application/views/ga4/remove_from_cart.tpl +++ b/Application/views/event/remove_from_cart.tpl @@ -1,5 +1,3 @@ -[{$smarty.block.parent}] - [{block name="d3_ga4_remove_from_cart_block"}] [{if $hasBeenReloaded}] [{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}] diff --git a/Application/views/event/view_cart.tpl b/Application/views/event/view_cart.tpl new file mode 100644 index 0000000..879ab99 --- /dev/null +++ b/Application/views/event/view_cart.tpl @@ -0,0 +1,50 @@ +[{*$oxcmp_basket|get_class_methods|dumpvar*}] + +[{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}] +[{assign var='gtmCartArticles' value=$oView->getBasketArticles()}] + +[{block name="d3_ga4_view_cart_block"}] + [{capture name="d3_ga4_view_cart"}] + [{strip}] + dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ + dataLayer.push({ + 'event': 'view_cart', + 'eventLabel':'Checkout Step 1', + '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=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}] + [{assign var="d3oItemPrice" value=$basketitem->getPrice()}] + [{assign var="gtmBasketItem" value=$basketitem->getArticle()}] + [{assign var="gtmBasketItemCategory" value=$gtmBasketItem->getCategory()}] + { + 'item_id': '[{$gtmCartArticles[$basketindex]->getFieldData('oxartnum')}]', + 'item_name': '[{$gtmCartArticles[$basketindex]->getFieldData('oxtitle')}]', + 'item_variant': '[{$gtmCartArticles[$basketindex]->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}] + 'price': [{$d3oItemPrice->getPrice()}], + 'coupon': '[{foreach from=$oxcmp_basket->getVouchers() item=sVoucher key=key name=Voucher}][{$sVoucher->sVoucherNr}][{if !$smarty.foreach.Voucher.last}], [{/if}][{/foreach}]', + 'quantity': [{$basketitem->getAmount()}], + 'position': [{$smarty.foreach.gtmCartContents.index}] + }[{if !$smarty.foreach.gtmCartContents.last}],[{/if}] + [{/foreach}] + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + [{/strip}] + [{/capture}] + [{oxscript add=$smarty.capture.d3_ga4_view_cart}] +[{/block}] \ No newline at end of file diff --git a/Application/views/event/view_item.tpl b/Application/views/event/view_item.tpl new file mode 100644 index 0000000..6f82d6b --- /dev/null +++ b/Application/views/event/view_item.tpl @@ -0,0 +1,41 @@ +[{assign var="gtmProduct" value=$oView->getProduct()}] +[{assign var="gtmCategory" value=$gtmProduct->getCategory()}] +[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] + +[{block name="d3_ga4_view_item_block"}] + [{capture name="d3_ga4_view_item"}] + [{strip}] + dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ + + dataLayer.push({ + 'event': 'view_item', + 'eventLabel':'Product View', + 'ecommerce': + { + 'currency': '[{$currency->name}]', + 'items': + [ + { + 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', + 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', + '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)}]', + 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1)}]', + 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2)}]', + 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3)}]', + 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', + [{/if}] + [{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] + 'price': [{$d3PriceObject->getPrice()}] + } + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + [{/strip}] + [{/capture}] + [{oxscript add=$smarty.capture.d3_ga4_view_item}] +[{/block}] \ No newline at end of file diff --git a/Application/views/ga4/view_item_list.tpl b/Application/views/event/view_item_list.tpl similarity index 96% rename from Application/views/ga4/view_item_list.tpl rename to Application/views/event/view_item_list.tpl index 927e636..28a273e 100644 --- a/Application/views/ga4/view_item_list.tpl +++ b/Application/views/event/view_item_list.tpl @@ -1,46 +1,45 @@ -[{$smarty.block.parent}] -[{assign var="gtmProducts" value=$oView->getArticleList()}] -[{assign var="gtmCategory" value=$oView->getActiveCategory()}] - -[{assign var="breadCrumb" value=''}] - -[{block name="d3_ga4_view_item_list_block"}] - [{if $gtmProducts|@count}] - [{capture name="d3_ga4_view_item_list"}] - [{strip}] - dataLayer.push({ecommerce: null}); - dataLayer.push({ - 'event':'view_item_list', - 'event_name': 'view_item_list', - 'ecommerce': { - 'item_list_id': '[{$oView->getCategoryId()}]', - 'item_list_name': '[{foreach from=$oView->getBreadCrumb() item=sCrum}][{if $sCrum.title }][{$breadCrumb|cat:$sCrum.title|cat:" > "}][{/if}][{/foreach}]', - 'items': [ - [{foreach from=$gtmProducts name="gtmProducts" item="gtmProduct"}] - [{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] - [{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] - [{if !$gtmCategory}][{assign var="gtmCategory" value=$gtmProduct->getCategory()}][{/if}] - { - 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', - 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', - 'price': [{$d3PriceObject->getPrice()}], - '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)}]', - [{/if}] - 'quantity': 1 - }[{if !$smarty.foreach.gtmProducts.last}],[{/if}] - [{/foreach}] - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }); - [{/strip}] - [{/capture}] - [{oxscript add=$smarty.capture.d3_ga4_view_item_list}] - [{/if}] +[{assign var="gtmProducts" value=$oView->getArticleList()}] +[{assign var="gtmCategory" value=$oView->getActiveCategory()}] + +[{assign var="breadCrumb" value=''}] + +[{block name="d3_ga4_view_item_list_block"}] + [{if $gtmProducts|@count}] + [{capture name="d3_ga4_view_item_list"}] + [{strip}] + dataLayer.push({ecommerce: null}); + dataLayer.push({ + 'event':'view_item_list', + 'event_name': 'view_item_list', + 'ecommerce': { + 'item_list_id': '[{$oView->getCategoryId()}]', + 'item_list_name': '[{foreach from=$oView->getBreadCrumb() item=sCrum}][{if $sCrum.title }][{$breadCrumb|cat:$sCrum.title|cat:" > "}][{/if}][{/foreach}]', + 'items': [ + [{foreach from=$gtmProducts name="gtmProducts" item="gtmProduct"}] + [{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] + [{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] + [{if !$gtmCategory}][{assign var="gtmCategory" value=$gtmProduct->getCategory()}][{/if}] + { + 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', + 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', + 'price': [{$d3PriceObject->getPrice()}], + '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)}]', + [{/if}] + 'quantity': 1 + }[{if !$smarty.foreach.gtmProducts.last}],[{/if}] + [{/foreach}] + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + [{/strip}] + [{/capture}] + [{oxscript add=$smarty.capture.d3_ga4_view_item_list}] + [{/if}] [{/block}] \ No newline at end of file diff --git a/Application/views/ga4/view_search_result.tpl b/Application/views/event/view_search_result.tpl similarity index 98% rename from Application/views/ga4/view_search_result.tpl rename to Application/views/event/view_search_result.tpl index cd1ed6c..8fcb14a 100644 --- a/Application/views/ga4/view_search_result.tpl +++ b/Application/views/event/view_search_result.tpl @@ -1,5 +1,3 @@ -[{$smarty.block.parent}] - [{assign var="gtmProducts" value=$oView->getArticleList()}] [{block name="d3_ga4_view_search_result_block"}] diff --git a/Application/views/tpl/page/account/d3gtmnoticelist.tpl b/Application/views/tpl/page/account/d3gtmnoticelist.tpl index 3b25c57..1f7ee6c 100644 --- a/Application/views/tpl/page/account/d3gtmnoticelist.tpl +++ b/Application/views/tpl/page/account/d3gtmnoticelist.tpl @@ -8,7 +8,7 @@

[{oxmultilang ident="WISH_LIST_EMPTY"}]

[{/if}] - [{include file="addtocart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] + [{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] [{insert name="oxid_tracker" title=$template_title}] [{/capture}] diff --git a/Application/views/tpl/page/account/d3gtmrecommendationlist.tpl b/Application/views/tpl/page/account/d3gtmrecommendationlist.tpl index e3cf2a7..c5828da 100644 --- a/Application/views/tpl/page/account/d3gtmrecommendationlist.tpl +++ b/Application/views/tpl/page/account/d3gtmrecommendationlist.tpl @@ -21,7 +21,7 @@ [{/if}] [{/block}] - [{include file="addtocart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] + [{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] [{insert name="oxid_tracker" title=$template_title}] [{/capture}] diff --git a/Application/views/tpl/page/account/d3gtmwishlist.tpl b/Application/views/tpl/page/account/d3gtmwishlist.tpl index dfda499..d813415 100644 --- a/Application/views/tpl/page/account/d3gtmwishlist.tpl +++ b/Application/views/tpl/page/account/d3gtmwishlist.tpl @@ -34,7 +34,7 @@

[{/if}] - [{include file="addtocart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] + [{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] [{insert name="oxid_tracker" title=$template_title}] [{/capture}] diff --git a/CHANGELOG.md b/CHANGELOG.md index d1a2c51..efa01b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.14.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.13.0...1.14.0) - 2024-01-03 +### Added +- add_to_cart Event to several new shop-pages (landing-page, Account, category article-list) +### Changed +- template structure +- code cleanup + ## [1.13.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.12.0...1.13.0) - 2023-09-13 ### Added - extended Docs diff --git a/Docs/README.md b/Docs/README.md index 8df6e03..8c5afaf 100644 --- a/Docs/README.md +++ b/Docs/README.md @@ -1,6 +1,6 @@ # Technische Doku ## GA4 Events / Customizing -Für alle implementierten GA4 Events existieren Templates unter `source/modules/d3/googleanalytics4/Application/views/ga4/`, dabei entspricht der Dateiname dem Eventnamen in GA4. +Für alle implementierten GA4 Events existieren Templates unter `source/modules/d3/googleanalytics4/Application/views/event/`, dabei entspricht der Dateiname dem Eventnamen in GA4. Die Einbindung dieser Event-Templates erfolgt über TPL-Blöcke unter `source/modules/d3/googleanalytics4/Application/views/blocks/`. *Hinweis: nicht alle templates sind bereits gefüllt. Wünschen Sie die Implementierung eines unausgefüllten templates? Kommen Sie auf uns zu unter https://www.d3data.de/ diff --git a/metadata.php b/metadata.php index 930b2ac..2f706dc 100755 --- a/metadata.php +++ b/metadata.php @@ -62,8 +62,14 @@ $aModule = [ OEStartController::class => d3GtmStartController::class ], 'templates' => [ - // own callable files - 'addtocart.tpl' => 'd3/googleanalytics4/Application/views/ga4/add_to_cart.tpl', + // Event files that store the GA4 Event-Information + 'event/add_to_cart.tpl' => 'd3/googleanalytics4/Application/views/event/add_to_cart.tpl', + 'event/view_item.tpl' => 'd3/googleanalytics4/Application/views/event/view_item.tpl', + 'event/view_cart.tpl' => 'd3/googleanalytics4/Application/views/event/view_cart.tpl', + 'event/purchase.tpl' => 'd3/googleanalytics4/Application/views/event/purchase.tpl', + 'event/view_item_list.tpl' => 'd3/googleanalytics4/Application/views/event/view_item_list.tpl', + 'event/view_search_result.tpl' => 'd3/googleanalytics4/Application/views/event/view_search_result.tpl', + 'event/remove_from_cart.tpl' => 'd3/googleanalytics4/Application/views/event/remove_from_cart.tpl', // complete overwritten file of OXID-Originals // the path of the template-name is the original path to the file in OXID-context from tpl/-> @@ -108,14 +114,14 @@ $aModule = [ [ 'template' => 'page/list/list.tpl', 'block' => 'page_list_productlist', - 'file' => '/Application/views/ga4/view_item_list.tpl', + 'file' => '/Application/views/blocks/view_item_list.tpl', 'position' => 150 ], // view_search_result [ 'template' => 'page/search/search.tpl', 'block' => 'search_results', - 'file' => '/Application/views/ga4/view_search_result.tpl', + 'file' => '/Application/views/blocks/view_search_result.tpl', 'position' => 150 ], // add_to_cart @@ -141,7 +147,7 @@ $aModule = [ [ 'template' => 'page/checkout/basket.tpl', 'block' => 'checkout_basket_main', - 'file' => '/Application/views/ga4/remove_from_cart.tpl', + 'file' => '/Application/views/blocks/remove_from_cart.tpl', 'position' => 150 ] ],