// CÓDIGO PARA RASTREAR WHATSAPP DESDE REDES SOCIALES // Agregar este código al final del código JavaScript que ya tienesfunction modifyWhatsAppLinks() { console.log("=== MODIFICANDO ENLACES WHATSAPP ==="); // Obtener valor de cookie var socialSource = getCookie('social_source'); console.log("Cookie social_source: " + socialSource); // Buscar todos los enlaces de WhatsApp var whatsappLinks = document.querySelectorAll('a[href*="wa.me"], a[href*="whatsapp.com"], a[href*="api.whatsapp.com"]'); console.log("Enlaces WhatsApp encontrados: " + whatsappLinks.length); whatsappLinks.forEach(function(link, index) { console.log("Procesando enlace " + (index + 1) + ": " + link.href); if (socialSource === 'true') { // Usuario viene de redes sociales var originalHref = link.href; // Verificar si ya tiene parámetro text if (originalHref.includes('?text=')) { // Ya tiene texto, agregar al final if (!originalHref.includes('[REDES SOCIALES]')) { link.href = originalHref + '%20[REDES SOCIALES]'; } } else if (originalHref.includes('?')) { // Tiene otros parámetros, agregar text link.href = originalHref + '&text=Hola!%20Vengo%20de%20redes%20sociales%20[REDES SOCIALES]'; } else { // No tiene parámetros, agregar text link.href = originalHref + '?text=Hola!%20Vengo%20de%20redes%20sociales%20[REDES SOCIALES]'; } console.log("✅ Enlace modificado: " + link.href); // Agregar clase CSS para identificar visualmente (opcional) link.classList.add('whatsapp-from-social'); } else { // Usuario NO viene de redes sociales console.log("❌ Usuario normal, enlace sin modificar"); } }); }// Ejecutar la modificación de WhatsApp document.addEventListener('DOMContentLoaded', function() { // Esperar un poco para que cargue todo setTimeout(function() { modifyWhatsAppLinks(); }, 1000); // Ejecutar varias veces para asegurar que funciona setTimeout(function() { modifyWhatsAppLinks(); }, 3000); });// También ejecutar cuando cambie el DOM var whatsappObserver = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type === 'childList') { setTimeout(function() { modifyWhatsAppLinks(); }, 500); } }); });whatsappObserver.observe(document.body, { childList: true, subtree: true });// Ejecutar cuando se haga clic en cualquier enlace WhatsApp document.addEventListener('click', function(e) { if (e.target.tagName === 'A' && (e.target.href.includes('wa.me') || e.target.href.includes('whatsapp.com'))) { // Último intento de modificación justo antes del clic setTimeout(function() { modifyWhatsAppLinks(); }, 100); } });
Skip to content