fix(ga4): stabilize checkout funnel events

This commit is contained in:
2026-05-11 15:54:42 +02:00
parent 80a3cb3814
commit a9fce98b01
8 changed files with 597 additions and 106 deletions

View File

@@ -78,18 +78,7 @@
value: {$content_value|escape:'htmlall':'UTF-8'}
});
{else if ($tagType === 'order' || $tagType === 'order-opc')}
console.log('Fired up event GA4: begin_checkout');
if (window.location.hostname === "lulandia.pl") {
gtag('event', 'conversion', {
'send_to': 'AW-11243281264/Gs-KCNqSsesYEPC2m_Ep',
'value': {$content_value|escape:'htmlall':'UTF-8'},
'currency': 'PLN'
});
console.log( 'Fired up event GADS begin_checkout conversion lulandia.pl' );
}
gtag('event', 'begin_checkout', {
window.pdGa4BeginCheckoutPayload = {
coupon: '{$content_coupon|escape:'htmlall':'UTF-8'}',
currency: '{$currency|escape:'htmlall':'UTF-8'}',
items: [
@@ -117,7 +106,61 @@
{/foreach}
],
value: {$content_value|escape:'htmlall':'UTF-8'}
});
};
{else if ($tagType === 'order' || $tagType === 'order-opc')}
(function() {
var payload = {
coupon: '{$content_coupon|escape:'htmlall':'UTF-8'}',
currency: '{$currency|escape:'htmlall':'UTF-8'}',
items: [
{foreach from=$content_products item=product name=products}
{
item_id: '{$product.content_ids|escape:'htmlall':'UTF-8'}',
item_name: '{$product.name|escape:'htmlall':'UTF-8'}',
coupon: '{$product.content_coupon|escape:'htmlall':'UTF-8'}',
discount: {$product.discount|escape:'htmlall':'UTF-8'},
index: {$smarty.foreach.products.index},
item_list_name: 'Cart products',
item_list_id: 1,
affiliation: '{$http_referer|escape:'htmlall':'UTF-8'}',
item_brand: '{$product.manufacturer_name|escape:'htmlall':'UTF-8'}',
item_category: '{$product.content_category|escape:'htmlall':'UTF-8'}',
{if !empty($product.content_category2)}item_category2: '{$product.content_category2|escape:'htmlall':'UTF-8'}',{/if}
{if !empty($product.content_category3)}item_category3: '{$product.content_category3|escape:'htmlall':'UTF-8'}',{/if}
{if !empty($product.content_category4)}item_category4: '{$product.content_category4|escape:'htmlall':'UTF-8'}',{/if}
{if !empty($product.content_category5)}item_category5: '{$product.content_category5|escape:'htmlall':'UTF-8'}',{/if}
item_variant: '{if isset($product.variant)}{$product.variant}{/if}',
price: {$product.price|escape:'htmlall':'UTF-8'},
currency: '{$currency|escape:'htmlall':'UTF-8'}',
quantity: '{$product.cart_quantity|escape:'htmlall':'UTF-8'}'
},
{/foreach}
],
value: {$content_value|escape:'htmlall':'UTF-8'}
};
var eventKey = 'pdga4_begin_checkout_v2_' + payload.items.map(function(item) {
return [item.item_id, item.quantity, item.price].join(':');
}).join('|') + ':' + payload.value;
try {
if (sessionStorage.getItem(eventKey) === '1') {
return;
}
sessionStorage.setItem(eventKey, '1');
} catch (e) {}
console.log('Fired up event GA4: begin_checkout');
if (window.location.hostname === "lulandia.pl") {
gtag('event', 'conversion', {
'send_to': 'AW-11243281264/Gs-KCNqSsesYEPC2m_Ep',
'value': payload.value,
'currency': 'PLN'
});
console.log('Fired up event GADS begin_checkout conversion lulandia.pl');
}
gtag('event', 'begin_checkout', payload);
})();
{else if ($tagType === 'category')}
console.log('Fired up event GA4: view_item_list > Category products list page');
@@ -311,4 +354,4 @@
</script>
<!-- PD Google Analytycs 4 Pro - EVENTS CODE FOOTER -->
{/if}
{/if}