diff --git a/Application/views/blocks/purchase.tpl b/Application/views/blocks/purchase.tpl index b97219e..3419a43 100644 --- a/Application/views/blocks/purchase.tpl +++ b/Application/views/blocks/purchase.tpl @@ -1,49 +1,56 @@ [{$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}] + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }) + [{/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 79279c0..765bfe8 100644 --- a/Application/views/blocks/view_cart.tpl +++ b/Application/views/blocks/view_cart.tpl @@ -5,38 +5,46 @@ [{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')}]', - '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()}]', - '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}] + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + [{/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 3e4b60a..e79852e 100644 --- a/Application/views/blocks/view_item.tpl +++ b/Application/views/blocks/view_item.tpl @@ -3,29 +3,38 @@ [{assign var="gtmCategory" value=$gtmProduct->getCategory()}] [{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] - \ No newline at end of file + 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=$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 adc990f..8a2b68e 100644 --- a/Application/views/ga4/add_to_cart.tpl +++ b/Application/views/ga4/add_to_cart.tpl @@ -6,41 +6,47 @@ [{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}]', - '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()}]', - '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 + } + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + }); + [{/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/view_item_list.tpl b/Application/views/ga4/view_item_list.tpl index 2be0f46..12fb5e8 100644 --- a/Application/views/ga4/view_item_list.tpl +++ b/Application/views/ga4/view_item_list.tpl @@ -4,37 +4,43 @@ [{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}] + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + [{/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 92487ed..42e4c7b 100644 --- a/Application/views/ga4/view_search_result.tpl +++ b/Application/views/ga4/view_search_result.tpl @@ -2,36 +2,43 @@ [{assign var="gtmProducts" value=$oView->getArticleList()}] -[{if $gtmProducts|@count}] - [{strip}] - - [{/strip}] -[{/if}] \ No newline at end of file +[{block name="d3_ga4_view_search_result_block"}] + [{if $gtmProducts|@count}] + [{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")}]', + '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}] + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + [{/strip}] + [{/capture}] + [{oxscript add=$d3_ga4_view_search_result}] + [{/if}] +[{/block}] \ No newline at end of file