1/** 2 * Loads scripts/features in a deferred manner 3 * 4 * @version 1.7.1 5 */ 6 7// Global variable to prevent delayedScripts from running more than once 8let delayedScriptsInitialized = false; 9 10/** 11 * Constant variables that are referenced within their respective functions 12 * Enter IDs for services you plan to use. 13 */ 14const analyticsIdOld = "" // Format: UA-0000000-0 (Old Google Analytics â analytics.js) 15const analyticsID = "UA-28542995-1"; // Format: UA-0000000-0 (Universal Analytics â gtag.js) 16const analyticsV4ID = "G-45W3M25KVT"; // Format: 'G-0000000000 (Google Analytics 4 â gtag.js) 17const googleTagID = "GTM-MXKM8DQ"; // Format: GTM-0000000 (Google Tag Manager) 18const googleAds = ""; // Format AW-000000000 (Google Ads) 19const googleCallMetricsID = ""; // Format AW-000000000/00000000000000000000 (Google Call Metrics ID, associated with Google Ads) 20const googleCallMetricsPhone1 = ""; // Format 1-000-000-0000 (Google Call Metics Phone Number) 21const googleCallMetricsPhone2 = "";// Format 1-000-000-0000 (Google Call Metics Phone Number) 22const googleLeadConversionID = ""; // Format AW-000000000/00000000000000000000 (Google Lead Conversion ID, associated with Google Ads) 23const googleLeadConversionValue = 1.0; // Decimal value, 1.0 set by default. Update as needed 24const googleLeadConversioncurrency = 'USD'; // Currency, USD set by default. Update as needed 25const chatID = "109-152-65-27-131-114-177-196"; // Format: 0-000-000-000-000-000-000-000 (Ngage live chat) 26const oClarkID = ""; // Format: 0000-000-00-0000 (Olark live chat) 27const chatApexID = ""; // Format: String, as in "companyname" (Apex live chat) 28const pixelId = ""; // Format: 000000000000000 (Facebook pixel tracking) 29const bingConversionId = ""; // Format: 000000000 (Bing pixel tracking) 30const intakerID = ""; // Format: sitename 31 32 33// JavaScript code to execute after the DOM is ready 34document.addEventListener("DOMContentLoaded", function(event) { 35 36 // Load script(s) after the user scrolls, moves the mouse, or touches the screen 37 document.addEventListener('scroll', delayedScripts); 38 document.addEventListener('mousemove', delayedScripts); 39 document.addEventListener('touchstart', delayedScripts); 40 41 setTimeout(function() { 42 delayedScripts(); 43 }, 4000); 44}); 45 46// Run scripts when user interacts with the page 47function delayedScripts(event) { 48 // Trigger this function only once 49 if(delayedScriptsInitialized) return; 50 51 // Setup Scripts, uncomment needed ones 52 setupGoogleAnalytics(); 53 setupGoogleTagManager(window, document, 'script', 'dataLayer', googleTagID); 54 // setupGoogleAnalyticsOld(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); 55 // setupPixel(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js'); 56 // setupBingConversion(window, document, "script", "//bat.bing.com/bat.js", "uetq"); 57 setupNgage("https://messenger.ngageics.com/ilnksrvr.aspx?websiteid=", document, "script", chatID); 58 // setupOlark(window, document, "static.olark.com/jsclient/loader.js"); 59 // setupApexChat(); 60 // setupIntaker(window, document, 'script','Intaker', intakerID); 61// setupGoogleTranslate(); 62 63 // Set variable to true to prevent delayedScripts from rerunning 64 delayedScriptsInitialized = true; 65 66} 67 68// Initializes Google Analytics 69function setupGoogleAnalytics() {
70 console.log('Setup analytics with ID ' + analyticsID); 71 72 // Create the script 73 const script = document.createElement('script'); 74 script.type = 'text/javascript'; 75 script.onload = () => { 76 window.dataLayer = window.dataLayer || []; 77 function gtag(){ dataLayer.push(arguments); } 78 gtag('js', new Date()); 79 gtag('config', analyticsID); 80 if(analyticsV4ID) 81 gtag('config', analyticsV4ID); 82 if(googleAds) 83 gtag('config', googleAds); 84 if(googleCallMetricsID && googleCallMetricsPhone1) 85 gtag( 'config', googleCallMetricsID, { 86 'phone_conversion_number': googleCallMetricsPhone1 87 }); 88 if(googleCallMetricsID && googleCallMetricsPhone2) 89 gtag( 'config', googleCallMetricsID, { 90 'phone_conversion_number': googleCallMetricsPhone2 91 }); 92 if(googleLeadConversionID) 93 gtag('event', 'conversion', { 94 'send_to': googleLeadConversionID, 95 'value': googleLeadConversionValue, 96 'currency': googleLeadConversioncurrency 97 }); 98 } 99 script.src = 'https://www.googletagmanager.com/gtag/js?id=' + analyticsID; 100 script.defer = true; //Set attribute 101 102 //Append the script to the body of the document 103 document.getElementsByTagName('body')[0].appendChild(script); 104} 105 106/** 107 * This is for older versions of Google Analytics ONLY 108 * Consult David if unsure of version to use. 109 */ 110function setupGoogleAnalyticsOld(i, s, o, g, r, a, m) {
111 console.log('Setup analytics with ID ' + analyticsIdOld); 112 113 // Create the script 114 i['GoogleAnalyticsObject'] = r; 115 i[r] = i[r] || function() { 116 (i[r].q = i[r].q || []).push(arguments) 117 }, 118 i[r].l = 1*new Date(); 119 a = s.createElement(o), 120 m = s.getElementsByTagName(o)[0]; 121 a.async = 1; 122 a.src = g; 123 m.parentNode.insertBefore(a,m) 124 125 ga('create', analyticsIdOld, 'auto'); 126 ga('send', 'pageview'); 127 128} 129 130// Load chat feature late 131function setupNgage(ng, a, g, e) { 132 console.log('Setup Ngage with ID ' + chatID); 133 134 var l = document.createElement(g); 135 l.async = 1; 136 l.src = (ng + e); 137 var c = a.getElementsByTagName(g)[0]; 138 c.parentNode.insertBefore(l, c); 139} 140 141// Load Olark chat late 142function setupOlark(o, l, a, r, k, y) { 143 console.log('Setup Olark with ID ' + oClarkID); 144 145 r = "script"; 146 y = l.createElement(r); 147 r = l.getElementsByTagName(r)[0]; 148 y.async = 1; 149 y.src="//" + a; 150 r.parentNode.insertBefore(y,r); 151 y = o.olark = function(){k.s.push(arguments);k.t.push(+new Date)}; 152 y.extend = function(i,j){y("extend",i,j)}; 153 y.identify = function(i){y("identify",k.i=i)}; 154 y.configure = function(i,j){y("configure",i,j);k.c[i]=j}; 155 k = y._={s:[],t:[+new Date],c:{},l:a}; 156 157 olark.identify(oClarkID); 158} 159 160// Load Google Tag Manager late 161function setupGoogleTagManager(w, d, s, l, i) { 162 console.log('Setup Google Tag Manager ' + i); 163 164 // Head script 165 w[l] = w[l] || []; 166 w[l].push({ 167 'gtm.start': new Date().getTime(),event:'gtm.js' 168 }); 169 var f = d.getElementsByTagName(s)[0], 170 j = d.createElement(s), 171 dl = l != 'dataLayer' ? '&l=' + l : '' ; 172 j.async = true; 173 j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; 174 f.parentNode.insertBefore(j,f); 175 176 // Body script 177 const script = document.createElement('noscript'); 178 const iframe = document.createElement('iframe'); 179 180 iframe.src= "https://www.googletagmanager.com/ns.html?id=" + i; 181 iframe.height = 0; 182 iframe.width = 0; 183 iframe.style.display = "none"; 184 iframe.style.visibility = "hidden"; 185 186 // Move elements to correct locations 187 script.appendChild(iframe); 188 document.getElementsByTagName('body')[0].prepend(script); 189} 190 191// Load Pixel script late 192function setupPixel(f, b, e, v, n, t, s) { 193 console.log('Setup Pixel ' + pixelId); 194 195 if(f.fbq) return; 196 n = f.fbq = function(){ 197 n.callMethod? 198 n.callMethod.apply(n,arguments):n.queue.push(arguments) 199 }; 200 if(!f._fbq) f._fbq = n; 201 n.push = n; 202 n.loaded = !0; 203 n.version = '2.0'; 204 n.queue = []; 205 t = b.createElement(e); 206 t.async = !0; 207 t.src = v; 208 s = b.getElementsByTagName(e)[0]; 209 s.parentNode.insertBefore(t,s) 210 211 fbq('init', pixelId, {}, { 212 "agent": "wordpress-5.7.1-3.0.5" 213 }); 214 215 fbq('track', 'PageView', []); 216 217 const noScript = document.createElement('noscript'); 218 noScript.innerHTML += "<img height=\"1\" width=\"1\" style=\"display:none\" alt=\"fbpx\"src=\"https://www.facebook.com/tr?id=" + pixelId + "&ev=PageView&noscript=1\" />"; 219 220 // Move elements to correct locations 221 document.getElementsByTagName('head')[0].append(noScript); 222} 223 224// Load Bing Conversion script late 225function setupBingConversion(w, d, t, r, u) { 226 console.log('Setup Bing Conversion ' + bingConversionId); 227 228 var f, n, i; 229 w[u] = w[u] || [], 230 f=function() { 231 var o = {ti: bingConversionId}; 232 o.q = w[u], 233 w[u] = new UET(o), 234 w[u].push("pageLoad") 235 }, 236 n = d.createElement(t), 237 n.src = r, 238 n.async = 1, 239 n.onload = n.onreadystatechange = function() { 240 var s = this.readyState; 241 s && s !== "loaded" && s !== "complete" || (f(), n.onload = n.onreadystatechange = null) 242 }, 243 i = d.getElementsByTagName(t)[0], 244 i.parentNode.insertBefore(n,i) 245} 246 247// Load Apex Chat 248function setupApexChat() { 249 console.log('Setup Apex Chat with ID ' + chatApexID); 250 251 const script = document.createElement('script'); 252 script.src = '//www.apex.live/scripts/invitation.ashx?company=' + chatApexID; 253 script.async = true; 254 255 //Add script to body 256 document.getElementsByTagName('body')[0].appendChild(script); 257} 258 259// Load Intake chat service late 260function setupIntaker(w, d, s, v, odl) { 261 console.log('Intaker Loaded'); 262 263 ( w[v] = w[v] || {} )['odl'] = odl; 264 var f = d.getElementsByTagName(s)[0],
265 j = d.createElement(s); 266 j.async=true; 267 j.src = 'https://intaker.azureedge.net/widget/chat.min.js'; 268 f.parentNode.insertBefore(j,f); 269} 270 271/** 272 * Load Google Translate script late 273 * 274 * This function does not work with wordpress google translate plugin 275 * This should only be used for custom google translate install. Example on https://www.thorntaxlaw.com/ 276 * 277 * If there is google tracking, the analyticsID should be filled in, or updated accordingly 278 */ 279function setupGoogleTranslate() { 280 console.log('Setup Google Translate'); 281 282 // Create script to add to the footer 283 const script = document.createElement('script'); 284 script.src = 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'; 285 script.async = true; 286 287 // Create script for google translate init function to add to the footer 288 const script2 = document.createElement('script'); 289 script2.innerHTML = function googleTranslateElementInit(){ 290 new google.translate.TranslateElement({ 291 pageLanguage: "en", 292 includedLanguages: "cy,de,es,fr,hi,it,nl,no,ru,tr,zh-CN", 293 layout: google.translate.TranslateElement.InlineLayout.SIMPLE, 294 gaTrack: !0, 295 gaId: analyticsID || '', 296 },"google_translate_element") 297 }; 298 script2.async = true; 299 300 // Add google translate script to the footer, followed by the init function 301 document.getElementsByTagName('footer')[0].appendChild(script); 302 document.getElementsByTagName('footer')[0].appendChild(script2); 303}
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.