add coupon to puchase-event

This commit is contained in:
MaxBUhe 2023-06-22 09:57:14 +02:00
parent 5c53d83f32
commit fec30b1109

View File

@ -3,21 +3,24 @@
[{strip}] [{strip}]
<script> <script>
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
[{assign var="gtmOrder" value=$oView->getOrder()}] [{assign var="gtmOrder" value=$oView->getOrder()}]
[{assign var="gtmArticles" value=$gtmOrder->getOrderArticles()}] [{assign var="gtmArticles" value=$gtmOrder->getOrderArticles()}]
[{assign var="gtmOrderPayment" value=$gtmOrder->getPayment()}]
[{assign var="gtmOrderVouchers" value=$gtmOrder->getVoucherNrList()}]
dataLayer.push({ dataLayer.push({
'event': 'purchase', 'event': 'purchase',
'eventLabel':'Checkout Step 5', 'eventLabel':'Checkout Step 5',
'ecommerce': { 'ecommerce': {
'transaction_id': '[{$gtmOrder->getFieldData("oxordernr")}]', 'transaction_id': '[{$gtmOrder->getFieldData("oxordernr")}]',
'affiliation': '[{$oxcmp_shop->getFieldData("oxname")}]', 'affiliation': '[{$oxcmp_shop->getFieldData("oxname")}]',
'value': [{$gtmOrder->getTotalOrderSum()}], 'value': [{$gtmOrder->getTotalOrderSum()}],
'tax': [{math equation="x+y" x=$gtmOrder->getFieldData("oxartvatprice1") y=$gtmOrder->getFieldData("oxartvatprice2") }], 'tax': [{math equation="x+y" x=$gtmOrder->getFieldData("oxartvatprice1") y=$gtmOrder->getFieldData("oxartvatprice2") }],
'shipping': [{$gtmOrder->getFieldData("oxdelcost")}], 'shipping': [{$gtmOrder->getFieldData("oxdelcost")}],
'currency': '[{$gtmOrder->getFieldData('oxcurrency')}]', 'currency': '[{$gtmOrder->getFieldData('oxcurrency')}]',
'items': 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]',
[ 'paymentType': '[{*$gtmOrderPayment->getFieldData('oxdesc')*}]',
'items': [
[{foreach from=$gtmArticles item="gtmBasketItem" name="gtmArticles"}] [{foreach from=$gtmArticles item="gtmBasketItem" name="gtmArticles"}]
[{assign var="gtmPurchaseItemPriceObject" value=$gtmBasketItem->getPrice()}] [{assign var="gtmPurchaseItemPriceObject" value=$gtmBasketItem->getPrice()}]
[{assign var="gtmPurchaseItem" value=$gtmBasketItem->getArticle()}] [{assign var="gtmPurchaseItem" value=$gtmBasketItem->getArticle()}]
@ -27,7 +30,7 @@
'item_id': '[{$gtmBasketItem->getFieldData("oxartnum")}]', 'item_id': '[{$gtmBasketItem->getFieldData("oxartnum")}]',
'item_name': '[{$gtmBasketItem->getFieldData("oxtitle")}]', 'item_name': '[{$gtmBasketItem->getFieldData("oxtitle")}]',
'affiliation': '[{$gtmBasketItem->getFieldData("oxtitle")}]', 'affiliation': '[{$gtmBasketItem->getFieldData("oxtitle")}]',
'coupon': '[{$gtmBasketItem->getFieldData("oxtitle")}]', 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]',
'item_variant': '[{$gtmBasketItem->getFieldData("oxselvariant")}]', 'item_variant': '[{$gtmBasketItem->getFieldData("oxselvariant")}]',
'item_category': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(0)}]', 'item_category': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(0)}]',
'item_category_2': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(1)}]', 'item_category_2': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(1)}]',
@ -39,7 +42,7 @@
'position': [{$smarty.foreach.gtmArticles.iteration}] 'position': [{$smarty.foreach.gtmArticles.iteration}]
}[{if !$smarty.foreach.gtmArticles.last}],[{/if}] }[{if !$smarty.foreach.gtmArticles.last}],[{/if}]
[{/foreach}] [{/foreach}]
] ]
} }
}) })
</script> </script>