1/* Crol â analytics helpers (Google Analytics 4) 2 * Sends events to GA4 via gtag(). Safe to call before gtag is ready 3 * (it queues into dataLayer, which gtag.js drains on load). 4 */ 5(function () { 6 function track(eventName, params) { 7 try { 8 if (typeof window.gtag === 'function') { 9 window.gtag('event', eventName, params || {}); 10 } else { 11 window.dataLayer = window.dataLayer || []; 12 window.dataLayer.push(['event', eventName, params || {}]); 13 } 14 } catch (err) { 15 // never throw from analytics 16 console.warn('[analytics] track failed:', err); 17 } 18 } 19 window.trackEvent = track; 20 21 // Auto-tracking via event delegation â runs once per page. 22 function pathFor(el) { 23 return el.closest('[data-page]')?.getAttribute('data-page') || document.body.getAttribute('data-page') || 'home'; 24 } 25 function locationLabel(el) { 26 // Try to give context: nearest section id, or footer/hero 27 const section = el.closest('section[id], header, footer'); 28 if (!section) return 'unknown'; 29 if (section.tagName === 'HEADER') return 'header'; 30 if (section.tagName === 'FOOTER') return 'footer'; 31 return section.id || section.tagName.toLowerCase(); 32 } 33 34 document.addEventListener('click', function (e) { 35 const a = e.target.closest('a'); 36 if (!a) return; 37 const href = a.getAttribute('href') || ''; 38 39 // ââ WhatsApp clicks ââââââââââââââââââââââââââââââââââââââââââââââââ 40 if (/(?:^https?:)?\/\/(?:api\.)?wa\.me\//i.test(href) || /(?:^https?:)?\/\/(?:web\.)?whatsapp\.com\//i.test(href)) { 41 const phoneMatch = href.match(/wa\.me\/\+?([\d]+)/i); 42 const phone = phoneMatch ? phoneMatch[1] : 'unknown'; 43 const role = phone.endsWith('39209800') ? 'ventas' 44 : phone.endsWith('39207010') ? 'soporte' 45 : 'otro'; 46 track('whatsapp_click', { 47 whatsapp_number: phone, 48 whatsapp_role: role, 49 location: locationLabel(a), 50 page: pathFor(a), 51 link_url: href, 52 link_text: (a.textContent || '').trim().slice(0, 80) || a.getAttribute('aria-label') || '', 53 }); 54 return; 55 } 56 57 // ââ "Agendar demostración" (any link to #form) ââââââââââââââââââââââ 58 if (href === '#form' || href.endsWith('#form')) { 59 track('cta_demo_click', { 60 location: locationLabel(a), 61 page: pathFor(a), 62 link_text: (a.textContent || '').trim().slice(0, 80) || a.getAttribute('aria-label') || 'Agenda', 63 }); 64 return; 65 } 66 }, true); 67})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.