1/* ========================================================================== 2 ORMSY Analytics â Frontend WhatsApp Click Tracker v1.0.0 3 ========================================================================== */ 4 5(function() { 6 'use strict'; 7 8 if (typeof ormsy_analytics === 'undefined') { 9 return; 10 } 11 12 /** 13 * Extract product ID from the page body class (e.g. postid-123) 14 */ 15 function getProductId() { 16 var body = document.body.className; 17 var match = body.match(/postid-(\d+)/); 18 return match ? parseInt(match[1], 10) : 0; 19 } 20 21 /** 22 * Send tracking event via AJAX (fire-and-forget) 23 */ 24 function trackWhatsApp(productId) { 25 var data = new FormData(); 26 data.append('action', 'ormsy_track_whatsapp'); 27 data.append('nonce', ormsy_analytics.nonce); 28 data.append('product_id', productId); 29 data.append('page_url', window.location.href); 30 31 // Use sendBeacon if available (survives navigation), fall back to fetch 32 var url = ormsy_analytics.ajax_url; 33 if (navigator.sendBeacon) { 34 navigator.sendBeacon(url, data); 35 } else { 36 fetch(url, { method: 'POST', body: data, keepalive: true }); 37 } 38 } 39 40 /** 41 * Attach click listeners to all known WhatsApp button selectors 42 */ 43 document.addEventListener('DOMContentLoaded', function() { 44 // All known WhatsApp button selectors across ORMSY sites 45 var selectors = [ 46 '.resto-wa-btn', // resto-whatsapp plugin 47 '.resto-wa-widget-btn', // resto-whatsapp floating widget 48 '.rf-whatsapp-order-btn', // rf-whatsapp-order plugin 49 'a[href*="wa.me"]' // catch-all for any wa.me links 50 ]; 51 52 var combined = selectors.join(', '); 53 54 document.addEventListener('click', function(e) { 55 var link = e.target.closest(combined); 56 if (!link) return; 57 58 var productId = getProductId(); 59 trackWhatsApp(productId); 60 }, true); 61 }); 62})();
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.