//Initialize Snap Pixel
snaptr('init', 'd3b38712-477b-4ac9-b7c3-f54fe9be8b67');
// Track Page View (exclude event-specific pages)
if (
!window.location.href.includes('/product') &&
!window.location.href.includes('/cart') &&
!window.location.href.includes('/checkout') &&
!window.location.href.includes('/order-received')
) {
snaptr('track', 'PAGE_VIEW');
}
// Track View Content for Product Pages
if (window.location.href.includes('product')) {
document.addEventListener('DOMContentLoaded', function() {
var productData = {
'price': document.querySelector('.woocommerce-Price-amount.amount')?.innerText.replace(/[^\d.]/g, '') || '0.00', // Product price
'currency': document.querySelector('meta[property="og:price:currency"]')?.content || 'USD', // Currency
'item_ids': [document.querySelector('[name="add-to-cart"]')?.value || 'unknown'], // Product ID
'item_category': document.querySelector('.posted_in a')?.innerText || 'unknown', // Category
};
// Trigger View Content event
snaptr('track', 'VIEW_CONTENT', productData);
});
}
// Track Add to Cart on Button Click
document.addEventListener('DOMContentLoaded', function() {
document.body.addEventListener('click', function(event) {
var target = event.target;
if (target.classList.contains('add_to_cart_button')) {
var productId = target.getAttribute('data-product_id') || 'unknown';
var quantity = target.closest('.quantity')?.querySelector('input.qty')?.value || 1;
var price = target.getAttribute('data-price') || document.querySelector('.woocommerce-Price-amount.amount')?.innerText.replace(/[^\d.]/g, '') || '0.00';
var currency = document.querySelector('meta[property="og:price:currency"]')?.content || 'USD';
snaptr('track', 'ADD_CART', {
'price': price,
'currency': currency,
'item_ids': [productId],
'number_items': quantity,
});
console.log('ADD_CART event triggered:', {
'price': price,
'currency': currency,
'item_ids': [productId],
'number_items': quantity,
});
}
});
});
// Track Add to Cart on Cart Page
if (window.location.href.includes('/cart')) {
document.addEventListener('DOMContentLoaded', function() {
var total = document.querySelector('.cart-subtotal .woocommerce-Price-amount.amount')?.innerText.replace(/[^\d.]/g, '') || '0.00';
var currency = document.querySelector('meta[property="og:price:currency"]')?.content || 'USD';
var items = Array.from(document.querySelectorAll('.cart_item')).map(function(item) {
return item.querySelector('.product_id')?.value || 'unknown';
});
snaptr('track', 'ADD_CART', {
'price': total,
'currency': currency,
'item_ids': items,
});
console.log('ADD_CART event triggered on Cart Page:', {
'price': total,
'currency': currency,
'item_ids': items,
});
});
}
// Track Start Checkout for Checkout Page
if (window.location.href.includes('/checkout') && !window.location.href.includes('/order-received')) {
document.addEventListener('DOMContentLoaded', function() {
var total = document.querySelector('.cart-subtotal .woocommerce-Price-amount.amount')?.innerText.replace(/[^\d.]/g, '') || '0.00';
var currency = document.querySelector('meta[property="og:price:currency"]')?.content || 'USD';
snaptr('track', 'START_CHECKOUT', {
'price': total,
'currency': currency,
});
});
}
// Track Purchase for Thank You Page
if (window.location.href.includes('/order-received')) {
document.addEventListener('DOMContentLoaded', function() {
var orderTotal = document.querySelector('.woocommerce-order-overview__total .woocommerce-Price-amount.amount')?.innerText.replace(/[^\d.]/g, '') || '0.00';
var currency = document.querySelector('meta[property="og:price:currency"]')?.content || 'USD';
var transactionId = document.querySelector('.woocommerce-order-overview__order .woocommerce-order-overview__order-number')?.innerText || 'unknown';
snaptr('track', 'PURCHASE', {
'price': orderTotal,
'currency': currency,
'transaction_id': transactionId,
});
});
}
عطر شاريول رويال ليذر رجالي او دي برفيوم 100 مل - مقتنياتي