L3Page'; const EIBASEURL = 'https://www.exportersindia.com'; const endpoint_1 = 'send-ga4'; const endpoint = EIBASEURL+'/'+endpoint_1+'.php'; const payload = { page_location: pageLocation, page_title: pageTitle, page_group: pageGroup }; function sendWithFetch() { fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }) .then(res => res.text()) .then(data => console.log('GA4 Fallback via fetch:', data)) .catch(err => console.error('Fetch fallback failed:', err)); } function sendData() { try { const blob = new Blob([JSON.stringify(payload)], { type: 'application/json' }); if (navigator.sendBeacon) { const sent = navigator.sendBeacon(endpoint, blob); if (!sent) { console.warn('sendBeacon failed, switching to fetch.'); sendWithFetch(); } else { console.log('GA4 data sent using sendBeacon.'); } } else { console.warn('sendBeacon not supported, using fetch.'); sendWithFetch(); } } catch (e) { console.error('Error using sendBeacon:', e); sendWithFetch(); } } if ('requestIdleCallback' in window) { requestIdleCallback(sendData); } else { setTimeout(sendData, 300); } })();