diff --git a/Application/views/blocks/purchase.tpl b/Application/views/blocks/purchase.tpl index 8cb92b8..9109d19 100644 --- a/Application/views/blocks/purchase.tpl +++ b/Application/views/blocks/purchase.tpl @@ -1,51 +1,54 @@ [{$smarty.block.parent}] -[{strip}] - -[{/strip}] + { + '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}] + ] + } + }) + [{/strip}] + [{/capture}] + [{oxscript add=$d3_ga4_purchase}] +[{/block}] \ No newline at end of file diff --git a/Application/views/blocks/view_cart.tpl b/Application/views/blocks/view_cart.tpl index 2671fde..cffdbde 100644 --- a/Application/views/blocks/view_cart.tpl +++ b/Application/views/blocks/view_cart.tpl @@ -5,40 +5,44 @@ [{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}] [{assign var='gtmCartArticles' value=$oView->getBasketArticles()}] -[{strip}][{capture assign=d3_ga4_view_cart}] - 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}] - ] - } - }); -[{/capture}][{/strip}] -[{oxscript add=$d3_ga4_view_cart}] \ No newline at end of file +[{block name="d3_ga4_view_cart_block"}] + [{capture assign=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}] + ] + } + }); + [{/strip}] + [{/capture}] + [{oxscript add=$d3_ga4_view_cart}] +[{/block}] \ No newline at end of file diff --git a/Application/views/blocks/view_item.tpl b/Application/views/blocks/view_item.tpl index 6a4e87f..720a2cc 100644 --- a/Application/views/blocks/view_item.tpl +++ b/Application/views/blocks/view_item.tpl @@ -3,31 +3,36 @@ [{assign var="gtmCategory" value=$gtmProduct->getCategory()}] [{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] - \ No newline at end of file + }); + [{/strip}] + [{/capture}] + [{oxscript add=$d3_ga4_view_item}] +[{/block}] \ No newline at end of file diff --git a/Application/views/ga4/add_to_cart.tpl b/Application/views/ga4/add_to_cart.tpl index 8a63023..2c76b2f 100644 --- a/Application/views/ga4/add_to_cart.tpl +++ b/Application/views/ga4/add_to_cart.tpl @@ -6,43 +6,45 @@ [{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] [{assign var="gtmCategory" value=$gtmProduct->getCategory()}] -[{capture assign=d3_ga4_add_to_cart}] - [{block name="d3_ga4_add_to_basket"}] - $("#toBasket").click(function(event) { - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ +[{block name="d3_ga4_add_to_cart_block"}] + [{capture assign=d3_ga4_add_to_cart}] + [{strip}] + $("#toBasket").click(function(event) { + dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - [{*** Debug cases ***}] - [{*event.preventDefault();*}] + [{*** Debug cases ***}] + [{*event.preventDefault();*}] - let iArtQuantity = $("#amountToBasket").val(); + let iArtQuantity = $("#amountToBasket").val(); - dataLayer.push({ - 'isAddToBasket': true, - 'event':'add_to_cart', - 'eventLabel': 'add_to_cart', - 'ecommerce': { - 'currency': "[{$currency->name}]", - 'value': iArtQuantity*[{$d3PriceObject->getPrice()}], - 'items': [ - { - 'item_id': '[{$gtmProduct->getFieldData('oxartnum')}]', - 'item_name': '[{$gtmProduct->getFieldData('oxtitle')}]', - 'price': [{$d3PriceObject->getPrice()}], - '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}] - 'quantity': iArtQuantity - } - ] - } - }); - }); - [{/block}] + dataLayer.push({ + 'isAddToBasket': true, + 'event':'add_to_cart', + 'eventLabel': 'add_to_cart', + 'ecommerce': { + 'currency': "[{$currency->name}]", + 'value': iArtQuantity*[{$d3PriceObject->getPrice()}], + 'items': [ + { + 'item_id': '[{$gtmProduct->getFieldData('oxartnum')}]', + 'item_name': '[{$gtmProduct->getFieldData('oxtitle')}]', + 'price': [{$d3PriceObject->getPrice()}], + '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}] + 'quantity': iArtQuantity + } + ] + } + }); + }); + [{/strip}] [{/capture}] -[{oxscript add=$d3_ga4_add_to_cart}] \ No newline at end of file + [{oxscript add=$d3_ga4_add_to_cart}] +[{/block}] \ No newline at end of file diff --git a/Application/views/ga4/remove_from_cart.tpl b/Application/views/ga4/remove_from_cart.tpl index 8f3e61e..5386f26 100644 --- a/Application/views/ga4/remove_from_cart.tpl +++ b/Application/views/ga4/remove_from_cart.tpl @@ -1,10 +1,10 @@ [{$smarty.block.parent}] -[{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}] - -[{if $hasBeenReloaded}] - [{strip}] - [{capture assign=d3_ga4_view_cart}] +[{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, @@ -39,7 +39,8 @@ ] } }); - [{/capture}] - [{/strip}] - [{oxscript add=$d3_ga4_view_cart}] -[{/if}] \ No newline at end of file + [{/strip}] + [{/capture}] + [{oxscript add=$d3_ga4_remove_from_cart}] + [{/if}] +[{/block}] \ No newline at end of file diff --git a/Application/views/ga4/view_item_list.tpl b/Application/views/ga4/view_item_list.tpl index 942ad28..47b920e 100644 --- a/Application/views/ga4/view_item_list.tpl +++ b/Application/views/ga4/view_item_list.tpl @@ -4,39 +4,41 @@ [{assign var="breadCrumb" value=''}] -[{if $gtmProducts|@count}] -[{strip}] - -[{/strip}] -[{/if}] \ No newline at end of file +[{block name="d3_ga4_view_item_list_block"}] + [{if $gtmProducts|@count}] + [{capture assign=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}] + ] + } + }); + [{/strip}] + [{/capture}] + [{oxscript add=$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/ga4/view_search_result.tpl index 991d682..8c9a547 100644 --- a/Application/views/ga4/view_search_result.tpl +++ b/Application/views/ga4/view_search_result.tpl @@ -2,38 +2,41 @@ [{assign var="gtmProducts" value=$oView->getArticleList()}] -[{if $gtmProducts|@count}] - [{strip}] - - [{/strip}] -[{/if}] \ No newline at end of file +[{block name="d3_ga4_add_to_cart_block"}] + [{if $gtmProducts|@count}] + [{capture assign=d3_ga4_add_to_cart}] + [{strip}] + dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ + dataLayer.push({ + 'event': 'view_search_result', + 'eventLabel':'view_search_result', + '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")}]', + '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)}]', + 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', + [{/if}] + 'quantity': 1 + }[{if !$smarty.foreach.gtmProducts.last}],[{/if}] + [{/foreach}] + ] + } + }); + [{/strip}] + [{/capture}] + [{oxscript add=$d3_ga4_add_to_cart}] + [{/if}] +[{/block}] \ No newline at end of file