[Changed] condition to trigger event-firing

This commit is contained in:
MaxBuhe01 2024-10-25 20:03:53 +02:00
parent 2ec373c95f
commit a18bcd35c4

View File

@ -1,5 +1,5 @@
[{if $d3CmpBasket && $d3CmpBasket->getAddToBasketDecision() && $d3CmpBasket->d3GtmRequestedArticleLoadedByAnid() !== null}]
[{if $d3CmpBasket && $d3CmpBasket->d3GtmRequestedArticleLoadedByAnid() !== null}]
[{assign var="oGtmProduct" value=$d3CmpBasket->d3GtmRequestedArticleLoadedByAnid()}]
[{assign var="oGtmAmountArticlesAdded" value=$d3CmpBasket->getD3GtmAddToCartAmountArticles()}]
[{*$smarty.block.parent*}]
@ -12,19 +12,17 @@
[{block name="d3_ga4_add_to_cart_list_block"}]
[{capture name="d3_ga4_add_to_cart_listtpl"}]
[{strip}]
$(document).ready(function() {
$('#toBasket').on('click', function() {
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;
}
let iPriceValue = [{$d3PriceObject->getPrice()}];
let iSumPrice = iArtQuantity*iPriceValue;
dataLayer.push({
'isAddToBasket': true,
@ -32,7 +30,7 @@
'eventLabel': 'add_to_cart',
'ecommerce': {
'currency': "[{$currency->name}]",
'value': iArtQuantity*[{$d3PriceObject->getPrice()}],
'value': parseInt(iSumPrice.toFixed(2)),
'items': [
{
'item_id': '[{$oGtmProduct->getFieldData('oxartnum')}]',
@ -54,8 +52,10 @@
'debug_mode': 'true'
[{/if}]
});
});
});
[{/strip}]
[{/capture}]
[{oxscript add=$smarty.capture.d3_ga4_add_to_cart_listtpl}]
[{/block}]
[{/if}]
[{/if}]