document.addEventListener('DOMContentLoaded', function() { // Captura email de cualquier formulario del sitio document.addEventListener('submit', function(e) { var emailField = e.target.querySelector('input[type="email"], input[name="email"], input[placeholder*="correo"], input[placeholder*="Email"]'); if (emailField && emailField.value && typeof gtag !== 'undefined') { gtag('set', 'user_data', { 'email': emailField.value }); } }, true); // Captura especifica del checkout de WooCommerce var checkoutEmail = document.getElementById('billing_email'); if (checkoutEmail) { checkoutEmail.addEventListener('blur', function() { if (this.value && typeof gtag !== 'undefined') { gtag('set', 'user_data', { 'email': this.value }); } }); } }); document.addEventListener('DOMContentLoaded', function() { if (typeof dataLayer !== 'undefined') { dataLayer.forEach(function(item) { if (item.event === 'purchase' || item.transactionId) { var email = item.customer_email || (item.ecommerce && item.ecommerce.customer_email); if (email && typeof gtag !== 'undefined') { gtag('set', 'user_data', { 'email': email }); } } }); } });