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