parent
841f458e86
commit
e854446fb9
@ -0,0 +1,135 @@ |
|||||||
|
{# header_scripts_pixel.twig #} |
||||||
|
|
||||||
|
{# Проверка переменных перед рендерингом #} |
||||||
|
{% if pixel_event_type == 'ViewContent' and product %} |
||||||
|
<script> |
||||||
|
document.addEventListener('DOMContentLoaded', function() { |
||||||
|
fbq('track', 'ViewContent', { |
||||||
|
content_ids: ['{{ product.id }}'], |
||||||
|
content_type: 'product', |
||||||
|
value: {{ product.price|number_format(2, '.', '') }}, |
||||||
|
currency: '{{ currency }}' |
||||||
|
}); |
||||||
|
}); |
||||||
|
</script> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
{% if pixel_event_type == 'InitiateCheckout' %} |
||||||
|
<script> |
||||||
|
document.addEventListener('DOMContentLoaded', function() { |
||||||
|
fbq('track', 'InitiateCheckout'); |
||||||
|
}); |
||||||
|
</script> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
{% if pixel_event_type == 'AddToCart' %} |
||||||
|
<script> |
||||||
|
document.addEventListener('DOMContentLoaded', function() { |
||||||
|
jQuery(function($) { |
||||||
|
$(document.body).on('added_to_cart', function(event, fragments, cart_hash, $button) { |
||||||
|
var productId = $button.data('product_id') || ''; |
||||||
|
var quantity = $button.data('quantity') || 1; |
||||||
|
var productName = $button.data('product_sku') || |
||||||
|
$button.closest('.product').find('.woocommerce-loop-product__title').text().trim() || 'Unknown'; |
||||||
|
var priceElement = $button.closest('.product').find('.price .amount').text().replace(/[^0-9.]/g, '') || '0.00'; |
||||||
|
var currency = '{{ currency }}'; |
||||||
|
|
||||||
|
fbq('track', 'AddToCart', { |
||||||
|
content_ids: [productId], |
||||||
|
content_type: 'product', |
||||||
|
value: parseFloat(priceElement) * quantity, |
||||||
|
currency: currency |
||||||
|
}); |
||||||
|
|
||||||
|
window.dataLayer = window.dataLayer || []; |
||||||
|
window.dataLayer.push({ |
||||||
|
'event': 'add_to_cart', |
||||||
|
'ecommerce': { |
||||||
|
'currency': currency, |
||||||
|
'value': parseFloat(priceElement) * quantity, |
||||||
|
'items': [{ |
||||||
|
'item_id': productId, |
||||||
|
'item_name': productName, |
||||||
|
'price': parseFloat(priceElement), |
||||||
|
'quantity': quantity |
||||||
|
}] |
||||||
|
} |
||||||
|
}); |
||||||
|
}); |
||||||
|
}); |
||||||
|
}); |
||||||
|
</script> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
{% if pixel_event_type == 'AddPaymentInfo' %} |
||||||
|
<script> |
||||||
|
document.addEventListener('DOMContentLoaded', function() { |
||||||
|
fbq('track', 'AddPaymentInfo', { |
||||||
|
value: {{ cart_total|number_format(2, '.', '') }}, |
||||||
|
currency: '{{ currency }}' |
||||||
|
}); |
||||||
|
|
||||||
|
window.dataLayer = window.dataLayer || []; |
||||||
|
window.dataLayer.push({ |
||||||
|
'event': 'add_payment_info', |
||||||
|
'ecommerce': { |
||||||
|
'currency': '{{ currency }}', |
||||||
|
'value': {{ cart_total|number_format(2, '.', '') }} |
||||||
|
} |
||||||
|
}); |
||||||
|
}); |
||||||
|
</script> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
{% if pixel_event_type == 'Purchase' and order %} |
||||||
|
<script> |
||||||
|
document.addEventListener('DOMContentLoaded', function() { |
||||||
|
fbq('track', 'Purchase', { |
||||||
|
value: {{ order.total|number_format(2, '.', '') }}, |
||||||
|
currency: '{{ order.currency }}', |
||||||
|
content_ids: [{{ order.content_ids|join(',') }}], |
||||||
|
content_type: 'product' |
||||||
|
}); |
||||||
|
|
||||||
|
window.dataLayer = window.dataLayer || []; |
||||||
|
window.dataLayer.push({ |
||||||
|
'event': 'purchase', |
||||||
|
'ecommerce': { |
||||||
|
'currency': '{{ order.currency }}', |
||||||
|
'value': {{ order.total|number_format(2, '.', '') }}, |
||||||
|
'items': {{ order.items|json_encode()|raw }} |
||||||
|
} |
||||||
|
}); |
||||||
|
}); |
||||||
|
</script> |
||||||
|
|
||||||
|
<script> |
||||||
|
window.dataLayer = window.dataLayer || []; |
||||||
|
dataLayer.push({ |
||||||
|
'ecommerce': { |
||||||
|
'purchase': { |
||||||
|
'actionField': { |
||||||
|
'id': '{{ order.id }}', |
||||||
|
'revenue': '{{ order.total|number_format(2, '.', '') }}', |
||||||
|
'currency': '{{ order.currency }}' |
||||||
|
}, |
||||||
|
'products': {{ order.items|json_encode()|raw }} |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
yaCounter96481053.reachGoal('purchase', { |
||||||
|
'order_id': '{{ order.id }}', |
||||||
|
'order_price': '{{ order.total|number_format(2, '.', '') }}', |
||||||
|
'currency': '{{ order.currency }}', |
||||||
|
'items': {{ order.items|json_encode()|raw }} |
||||||
|
}); |
||||||
|
|
||||||
|
fbq('track', 'Purchase', { |
||||||
|
value: {{ order.total|number_format(2, '.', '') }}, |
||||||
|
currency: '{{ order.currency }}', |
||||||
|
content_ids: [{{ order.content_ids|join(',') }}], |
||||||
|
content_type: 'product' |
||||||
|
}); |
||||||
|
</script> |
||||||
|
{% endif %} |
Loading…
Reference in new issue