/* Add custom Js code below */ // Check the lang attribute of the tag const htmlLang = document.documentElement.lang; // Set language in localStorage based on the lang attribute if (htmlLang === 'ar') { localStorage.setItem('language', 'ar'); } else { localStorage.setItem('language', 'en'); } /* Klaviyo Integration */ const kalviyoScript = document.createElement('script'); kalviyoScript.type = 'text/javascript'; kalviyoScript.src = 'https://static.klaviyo.com/onsite/js/klaviyo.js?company_id=SZEMz2'; document.body.appendChild(kalviyoScript); // Wait for Klaviyo script to load kalviyoScript.onload = () => { console.log("Klaviyo script loaded"); // Event: Track Add to Cart document.querySelectorAll('.product-card-actions-add-to-cart-label').forEach(button => { button.addEventListener('click', function () { const productElement = this.closest('.product-card'); // تحديد العنصر الأب لزر الإضافة // الحصول على اسم المنتج const productNameElement = productElement.querySelector('.product-card-content-meta-title h4'); const productName = productNameElement ? productNameElement.textContent.trim() : "اسم غير متوفر"; // الحصول على السعر const productPriceElement = productElement.querySelector('.product-card-content-meta-pricing-current-not-discounted'); const productPrice = productPriceElement ? productPriceElement.textContent.trim() : "سعر غير متوفر"; // إرسال البيانات إلى Klaviyo _learnq.push(['track', 'Added to Cart', { ProductName: productName, ProductPrice: productPrice }]); console.log(`Added to cart: ${productName} - ${productPrice}`); }); }); // Event: Track Abandoned Cart (when user visits the cart page) if (window.location.pathname === '/cart') { const cartItems = []; document.querySelectorAll('.cart-item').forEach(item => { cartItems.push({ name: item.querySelector('.cart-item-name').textContent.trim(), price: item.querySelector('.cart-item-price').textContent.trim(), quantity: item.querySelector('.cart-item-quantity').value }); }); // إرسال بيانات السلة إلى Klaviyo _learnq.push(['track', 'Viewed Cart', { items: cartItems }]); console.log("Cart viewed event sent to Klaviyo"); } };