You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
4.7 KiB
135 lines
4.7 KiB
{# 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 %}
|
|
|