1(function() { 2 "use strict"; 3 4 // Configuration 5 var API_ENDPOINT = getApiEndpoint(); 6 7 function getApiEndpoint() { 8 // Use the endpoint provided by WordPress if available 9 if (window.airefsApiSettings && window.airefsApiSettings.apiEndpoint) { 10 return window.airefsApiSettings.apiEndpoint; 11 } 12 13 // Fallback: Try to detect permalink structure 14 // Check if wp-json exists in a typical WordPress installation 15 if (window.airefsApiSettings && window.airefsApiSettings.root) { 16 return window.airefsApiSettings.root + "airefs/v1/events"; 17 } 18 19 // Final fallback: Default to pretty permalinks format 20 // The sendTrackingEvent function will handle failures and try the alternative format 21 return "/wp-json/airefs/v1/events"; 22 } 23 24 function getBrowserInfo() { 25 var ua = navigator.userAgent; 26 var browser = "Unknown"; 27 var version = "Unknown"; 28 29 if (ua.indexOf("Firefox") > -1) { 30 browser = "Firefox"; 31 version = ua.split("Firefox/")[1].split(" ")[0]; 32 } else if (ua.indexOf("Edg") > -1) { 33 browser = "Edge"; 34 version = ua.split("Edg/")[1].split(" ")[0]; 35 } else if (ua.indexOf("Chrome") > -1 && ua.indexOf("Edg") === -1) { 36 browser = "Chrome"; 37 version = ua.split("Chrome/")[1].split(" ")[0]; 38 } else if (ua.indexOf("Safari") > -1 && ua.indexOf("Chrome") === -1) { 39 browser = "Safari"; 40 version = ua.split("Version/")[1].split(" ")[0]; 41 } else if (ua.indexOf("Trident") > -1 || ua.indexOf("MSIE") > -1) { 42 browser = "Internet Explorer"; 43 if (ua.indexOf("MSIE") > -1) { 44 version = ua.split("MSIE ")[1].split(";")[0]; 45 } else if (ua.indexOf("rv:") > -1) { 46 version = ua.split("rv:")[1].split(")")[0]; 47 } 48 } 49 50 return { browser: browser, browser_version: version }; 51 } 52 53 function parseUserAgent(ua) { 54 var device_type = "desktop"; 55 if (/Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua)) { 56 device_type = "mobile"; 57 } else if (/Tablet|iPad/i.test(ua)) { 58 device_type = "tablet"; 59 } 60 61 var os; 62 if (/Windows NT/i.test(ua)) os = "Windows"; 63 else if (/Mac OS X/i.test(ua)) os = "Mac OS X"; 64 else if (/Android/i.test(ua)) os = "Android"; 65 else if (/iPhone|iPad|iPod/i.test(ua)) os = "iOS"; 66 else if (/Linux/i.test(ua)) os = "Linux"; 67 else os = "Unknown"; 68 69 var browserInfo = getBrowserInfo(); 70 var browser = browserInfo.browser; 71 var browser_version = browserInfo.browser_version; 72 73 return { device_type: device_type, os: os, browser: browser, browser_version: browser_version }; 74 } 75 76 function sendTrackingEvent(payload, endpoint) { 77 var currentEndpoint = endpoint || API_ENDPOINT; 78 79 function tryAlternativeEndpoint() { 80 // If the current endpoint failed, try the alternative format 81 var alternativeEndpoint; 82 if (currentEndpoint.indexOf("wp-json") > -1) { 83 // Try ugly permalinks format 84 alternativeEndpoint = "/?rest_route=/airefs/v1/events"; 85 } else { 86 // Try pretty permalinks format 87 alternativeEndpoint = "/wp-json/airefs/v1/events"; 88 } 89 90 if (alternativeEndpoint !== currentEndpoint) { 91 sendTrackingEvent(payload, alternativeEndpoint); 92 } 93 } 94 95 try { 96 // Use fetch if available, otherwise fallback to XMLHttpRequest 97 if (typeof fetch === "function") { 98 var headers = { "Content-Type": "application/json" }; 99 100 fetch(currentEndpoint, { method: "POST", headers: headers, body: JSON.stringify(payload) }) 101 .catch(function(e) { 102 console.debug("Airefs tracking error with endpoint " + currentEndpoint + ":", e); 103 // Try alternative endpoint format if this is the first attempt 104 if (!endpoint) { 105 tryAlternativeEndpoint(); 106 } 107 }); 108 } else { 109 // Fallback to XMLHttpRequest 110 var xhr = new XMLHttpRequest(); 111 xhr.open("POST", currentEndpoint, true); 112 xhr.setRequestHeader("Content-Type", "application/json"); 113 xhr.onreadystatechange = function() { 114 if (xhr.readyState === 4) { 115 if (xhr.status !== 200) { 116 console.debug( 117 "Airefs tracking error with endpoint " + currentEndpoint + ":", 118 xhr.statusText, 119 ); 120 // Try alternative endpoint format if this is the first attempt 121 if (!endpoint) { 122 tryAlternativeEndpoint(); 123 } 124 } 125 } 126 }; 127 xhr.send(JSON.stringify(payload)); 128 } 129 } catch (e) { 130 console.debug("Airefs tracking error with endpoint " + currentEndpoint + ":", e); 131 // Try alternative endpoint format if this is the first attempt 132 if (!endpoint) { 133 tryAlternativeEndpoint(); 134 } 135 } 136 } 137 138 function trackPageView() { 139 // Skip if we're in admin area or other non-public contexts 140 if (typeof window === "undefined" || typeof document === "undefined") { 141 return; 142 } 143 144 var ua = navigator.userAgent; 145 var parsed = parseUserAgent(ua); 146 var referrer = typeof document !== "undefined" ? document.referrer : ""; 147 var currentUrl = window.location.href; 148 149 var payload = { 150 name: "pageview", 151 source: "client", 152 url: currentUrl, 153 page_title: document.title, 154 referrer: referrer || null, 155 screen_width: window.screen.width, 156 screen_height: window.screen.height, 157 user_agent: ua, 158 language: navigator.language, 159 timezone_offset: new Date().getTimezoneOffset(), 160 timestamp: new Date().toISOString(), 161 device_type: parsed.device_type, 162 os: parsed.os, 163 browser: parsed.browser, 164 browser_version: parsed.browser_version, 165 }; 166 167 sendTrackingEvent(payload); 168 } 169 170 // Initialize tracking with delay to avoid blocking page load 171 void trackPageView(); 172 173 // Expose global tracking function for custom events 174 window.AirefsTracking = { 175 trackEvent: function(eventName, customData) { 176 if (!eventName) return; 177 178 var ua = navigator.userAgent; 179 var parsed = parseUserAgent(ua); 180 181 var referrer = typeof document !== "undefined" ? document.referrer : ""; 182 var currentUrl = window.location.href; 183 184 var payload = { 185 name: eventName, 186 source: "client", 187 url: currentUrl, 188 page_title: document.title, 189 referrer: referrer || null, 190 screen_width: window.screen.width, 191 screen_height: window.screen.height, 192 user_agent: ua, 193 language: navigator.language, 194 timezone_offset: new Date().getTimezoneOffset(), 195 timestamp: new Date().toISOString(), 196 device_type: parsed.device_type, 197 os: parsed.os, 198 browser: parsed.browser, 199 browser_version: parsed.browser_version, 200 }; 201 202 // Merge custom data if provided 203 if (customData && typeof customData === "object") {
204 Object.keys(customData).forEach(function(key) { 205 payload[key] = customData[key]; 206 }); 207 } 208 209 sendTrackingEvent(payload); 210 }, 211 212 trackPageView: trackPageView, 213 }; 214})();
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.