Files
2025-03-12 17:06:23 +01:00

98 lines
3.2 KiB
HTML

<script async src="https://www.googletagmanager.com/gtag/js?id={$code}"></script>
<script type="text/javascript">
{literal}
const cookies = document.cookie.split("; ");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].split("=");
if (cookie[0] === "cookies_google_analytics") {
var cookies_google_analytics = cookie[1];
if(cookies_google_analytics === 'true'){
var analytics_storage = "granted";
}else{
var analytics_storage = "denied";
}
}
if (cookie[0] === "cookies_google_targeting") {
var cookies_google_targeting = cookie[1];
if(cookies_google_targeting === 'true'){
var ad_storage = "granted";
}else{
var ad_storage = "denied";
}
}
}
{/literal}
window.dataLayer = window.dataLayer || [];
function gtag(){literal}{dataLayer.push(arguments)};{/literal}
gtag('consent', 'default', {literal}{{/literal}
'functionality_storage': 'granted',
'personalization_storage': 'granted',
'security_storage': 'granted',
'analytics_storage': analytics_storage,
'ad_storage': ad_storage
{literal}}{/literal});
gtag('js', new Date());
gtag('config', '{$code}');
{slot name="analytics" hidden="true"}{/slot}
{if $ecommerce_check == 1}
{if $old_version == 1}
gtag('event', 'purchase', {literal}{{/literal}
"transaction_id": "{$order_id}",
"affiliation": "{$host}",
"value": {$order_amount},
"currency": "{$currency}",
"tax": 0,
"shipping": {$delivery_cost},
"items": [
{foreach item=order_product from=$results name=product}
{literal}{{/literal}
"id": "{$order_product.product_code}",
"name": "{$order_product.product_name}",
"brand": "{$order_product.brand}",
"category": "{$order_product.product_category}",
"variant": "{$order_product.product.options}",
"quantity": {$order_product.product_quantity},
"google_business_vertical": 'retail',
"price": '{$order_product.product_price}'
{literal}}{/literal}{if not $smarty.foreach.product.last},{/if}
{/foreach}
]
{literal}});{/literal}
{else}
gtag('event', 'purchase', {literal}{{/literal}
"transaction_id": "{$order_id}",
"value": {$order_amount},
"currency": "{$currency}",
"tax": 0,
"shipping": {$delivery_cost},
"items": [
{foreach item=order_product from=$results name=product}
{literal}{{/literal}
"id": "{$order_product.product_code}",
"item_id": "{$order_product.product_code}",
"item_name": "{$order_product.product_name}",
"item_brand": "{$order_product.brand}",
"item_category": "{$order_product.product_category}",
"item_variant": "{$order_product.product.options}",
"quantity": {$order_product.product_quantity},
"google_business_vertical": 'retail',
"price": '{$order_product.product_price}'
{literal}}{/literal}{if not $smarty.foreach.product.last},{/if}
{/foreach}
]
{literal}});{/literal}
{/if}
{/if}
</script>