1// (function(history){ 2// var replaceState = history.replaceState; 3// history.replaceState = function(state) { 4// if (typeof history.onreplacestate == "function") { 5// history.onreplacestate({state: state}); 6// } 7// return replaceState.apply(history, arguments); 8// }; 9// })(window.history); 10// 11// window.onpopstate = history.onreplacestate = function(e) { 12// var domain = getDomainName() 13// console.log(e.state.path) 14// Cookies.set('handl_url', e.state.path, { 15// expires: parseInt(handl_utm_cookie_duration[0]), 16// domain: domain, 17// sameSite:'None', 18// secure: true } 19// ); 20// } 21 22var qvars = getUrlVars() 23var domain = getDomainName() 24 25jQuery(function($) { 26 if (handl_utm_cookie_duration[1] === '1' && 27 typeof(TVE) === "undefined" //thrive editor fix 28 ){ 29 console.log('Running HandL'); 30 RunHandL() 31 32 const borlabsCookie = Cookies.get('borlabs-cookie'); // Get the cookie as a JSON string 33 if (borlabsCookie) { 34 try { 35 // Parse the JSON string into an object 36 const cookieData = JSON.parse(borlabsCookie); 37 38 // Check if the 'marketing' key has 'handl-utm-grabber' 39 if (cookieData.consents.marketing.includes('handl-utm-grabber')) { 40 console.log("handl-utm-grabber checked by Borlabs.. RunHandL..."); 41 RunHandL() 42 } else { 43 console.log("handl-utm-grabber not checked by Borlabs"); // or return false; 44 } 45 } catch (e) { 46 console.error('Error parsing JSON:', e); 47 } 48 } 49 } 50}); 51 52 53function RunHandL(){ 54 window.utms_js = {} 55 window.gaNames = [] 56 57 //simulate referrer locally 58 // Object.defineProperty(document, "referrer", {get : function(){ return "https://google.com"; }}); 59 60 SetRefLink('handlID', Math.floor(Math.random() * Date.now()), false, 0) 61 62 GAClientID() 63 setHandLParams() 64 65 // console.log("after handl params") 66 67 RunFieldFiller() 68 // Occasionally, the page takes longer to render, so it makes sense to introduce a delay. However, we have not yet investigated the potential negative effects of doing this when it is not necessary. 69 // setTimeout(RunFieldFiller, 1000) 70 71 jQuery.each(handl_utm_predefined, function( i,v ) { 72 let cookie_name = v.name; 73 let value = v.value 74 75 if ( value.startsWith('[') && value.endsWith(']') ){ //it's a shortcode! 76 value = v.value.replace(/^\[|\]$/g,''); 77 }else{ //it is a hardcoded default value 78 value = cookie_name 79 } 80 81 if ( ['_ga','gaclientid'].indexOf(value) > -1 ){ 82 gaNames.push(cookie_name) 83 } 84 85 if (cookie_name != ''){ 86 var cookie_field = GetQVars(value,qvars) 87 88 if (cookie_field == ''){ 89 cookie_field = Cookies.get(value) 90 } 91 92 if ( cookie_field != '' && cookie_field != 'PANTHEON_STRIPPED' ){ 93 utms_js[cookie_name] = cookie_field 94 SetRefLink(cookie_name, cookie_field, true, 0) 95 } 96 } 97 }) 98 99 populateLinks() 100 101 jQuery(document).on( 'nfFormReady', function() { 102 // Loop through each form in nfForms array 103 nfForms.forEach(form => { 104 form.fields.map(item => { 105 if (item.default) { 106 var matches = String(item.default).match(/^{(\w+):(\w+)/) 107 if (matches && matches.length == 3) { 108 let key = matches[1] 109 let value = matches[2] 110 111 if (key === 'handl') { 112 console.log(key, value) 113 jQuery('#nf-field-' + item.id).val(Cookies.get(value)) 114 } 115 } 116 } 117 }) 118 }) 119 120 //hide hidden fields 121 // jQuery('.nf-field-container.hidden-container').map( (i, item) => jQuery(item).parents().eq(4).hide()) 122 }) 123 124 document.dispatchEvent(new Event('HandL-After-Main-Function')); 125} 126 127function RunFieldFiller(){ 128
129 let cookieOptions = { 130 domain: domain, 131 secure: true, 132 sameSite: 'None' 133 }; 134 135 if (!parseInt(handl_utm_session_cookies?.enabled)) { 136 cookieOptions.expires = parseInt(handl_utm_cookie_duration[0]); 137 } 138 139 Cookies.set('user_agent', navigator.userAgent, cookieOptions) 140 141 jQuery.each(handl_utm_all_params, function( i,vi ) { 142 var cookie_field = GetQVars(vi,qvars) 143 144 var cookie_params = [vi] 145 if ( handl_utm_first_touch_params.includes(vi) ) 146 cookie_params.push('first_'+vi) 147 148 cookie_params.forEach( (v, ind) => { 149 150 if ( cookie_field != '' && cookie_field != 'PANTHEON_STRIPPED' ){ 151 if ( v.startsWith('first_') && Cookies.get(v) != undefined ){ 152 //do not update the first attributes... 153 }else{ 154 if (cookie_field.includes('#')) { 155 cookie_field = cookie_field.split('#')[0]; 156 } 157 158 let cookieOptions = { 159 domain: domain, 160 sameSite: 'None', 161 secure: true 162 }; 163 164 if (!parseInt(handl_utm_session_cookies?.enabled)) { 165 cookieOptions.expires = parseInt(handl_utm_cookie_duration[0]); 166 } 167 168 Cookies.set(v, cookie_field, cookieOptions); 169 } 170 } 171 172 var curval = decodeURI(Cookies.get(v)) 173 curval = curval != 'undefined' ? curval : '' 174 if (curval != 'undefined') { 175 curval = sanitizeInput(curval); 176 utms_js[v] = curval 177 curval = decodeURIComponent(curval) 178 // curval = curval.replace(/[%]/g,' ') 179 if (v == 'username') { 180 //Maybe this should apply to all... We'll see... 181 curval = curval.replace(/\+/g, ' ') 182 } 183 184 jQuery('input[name=\"'+v+'\"]').val(curval) 185 jQuery('input#'+v).val(curval) 186 jQuery('input.'+v).val(curval) 187 jQuery('input#form-field-'+v).val(curval) 188 189 //for nested input fix 190 jQuery('#'+v).find('input').val(curval) 191 jQuery('.'+v).find('input').val(curval) 192 193 jQuery("[data-original_id='"+v+"']").val(curval) 194 jQuery("[data-name='"+v+"']").val(curval) 195 jQuery("[data-name='"+v.replace(/_/g,'')+"']").val(curval) //Active Campaign 196 197 198 199 if (v.length > 4){ // this is for making sure wildcards are not hyper sensitive. 200 //wildcard selector 201 jQuery("[name*="+v+"]").val(curval) 202 jQuery("[id*="+v+"]").val(curval) 203 jQuery("[class*="+v+"]").val(curval) 204 205 jQuery("[class*="+v+"_out]").html(curval) 206 jQuery("[id*="+v+"_out]").html(curval) 207 } 208 209 } 210 }) 211 }); 212} 213 214function populateLinks(){ 215 jQuery('.utm-out-js, .utm-out-js a').each(function(){ 216 var merged_raw = jQuery.extend( {}, utms_js ) 217 var merged = Object.keys(merged_raw) 218 .filter(key => handl_utm_append_params.includes(key)) 219 .reduce((obj, key) => { 220 if (merged_raw[key]) { 221 obj[key] = decodeURIComponent(merged_raw[key]); 222 } 223 return obj; 224 }, {}); 225 merged = jQuery.extend(merged, getSearchParams(this.href)) 226 var current_page = window.location.href.split('?')[0] 227 if ( 228 this.href !== undefined && 229 this.href !== "" && 230 !this.href.match("#") && 231 !this.href.startsWith("tel:") && 232 !this.href.startsWith("mailto:") && 233 !this.href.startsWith("sms:") && 234 !jQuery(this).attr('onclick') && 235 !jQuery(this).closest('.no-utm').length // Check if the link or any of its parents have the no-utm class 236 // this.href.match(new RegExp("^"+current_page+"$")) == null 237 ){ 238 var href = this.href.split("?")[0]; 239 if ( !jQuery.isEmptyObject(merged) ) 240 this.href = href+"?"+decodeURIComponent(jQuery.param(merged)) 241 } 242 }) ; 243 244 // console.log(handl_utm) 245 // console.log(utms_js) 246 247 jQuery('.utm-out, .utm-out a').each(function(){ 248 var merged_raw = jQuery.extend( {}, handl_utm, utms_js ) 249 var merged = Object.keys(merged_raw) 250 .filter(key => handl_utm_append_params.includes(key)) 251 .reduce((obj, key) => { 252 if (merged_raw[key]) { 253 obj[key] = decodeURIComponent(merged_raw[key]); 254 } 255 return obj 256 }, {}); 257 merged = jQuery.extend(merged, getSearchParams(this.href)) 258 var current_page = window.location.href.split('?')[0] 259 if ( 260 this.href !== undefined && 261 this.href !== "" && 262 !this.href.match("#") && 263 !this.href.startsWith("tel:") && 264 !this.href.startsWith("mailto:") && 265 !this.href.startsWith("sms:") && 266 !jQuery(this).closest('.no-utm').length // Check if the link or any of its parents have the no-utm class 267 // !jQuery(this).attr('onclick') && 268 // this.href.match(new RegExp("^"+current_page+"$")) == null 269 ){ 270 var href = this.href.split("?")[0]; 271 var parts = [] 272 if (this.href.match("#")){ 273 parts = this.href.split("#") 274 if (parts[1] != ""){ 275 href = parts[0] 276 } 277 } 278 279 // console.log(parts, href) 280 if ( !jQuery.isEmptyObject(merged) ){ 281 if (this.href.match("#") && parts.length == 2){ 282 this.href = href+"?"+decodeURIComponent(jQuery.param(merged))+"#"+parts[1].split("?")[0] 283 }else{ 284 this.href = href+"?"+decodeURIComponent(jQuery.param(merged)) 285 } 286 } 287 } 288 }); 289
290 jQuery('.utm-src').each(function(){ 291 var target_url 292 if (this.src){ 293 target_url = this.src 294 }else if (jQuery(this).data('url')){ 295 target_url = jQuery(this).data('url') 296 }else if (jQuery(this).data('src')){ 297 target_url = jQuery(this).data('src') 298 } 299 300 var merged_raw = jQuery.extend( {}, handl_utm, utms_js ) 301 var merged = Object.keys(merged_raw) 302 .filter(key => handl_utm_append_params.includes(key)) 303 .reduce((obj, key) => { 304 if (merged_raw[key]) { 305 obj[key] = decodeURIComponent(merged_raw[key]); 306 } 307 return obj; 308 }, {}); 309 merged = jQuery.extend( merged, getSearchParams(target_url) ) 310 311 var src = target_url.split("?")[0]; 312 if ( !jQuery.isEmptyObject(merged) ){ 313 var final_target = src + "?" + decodeURIComponent(jQuery.param(merged)) 314 if (this.src) { 315 this.src = final_target 316 }else if (jQuery(this).data('url')){ 317 jQuery(this).data('url', final_target) 318 } 319 } 320 }); 321 322 jQuery("[data-fillout-id]").each(function(){ 323 handl_utm_append_params.map(t=>{ 324 jQuery(this).attr(`data-${t}`, utms_js[t]) 325 }) 326 327 var script = document.createElement('script'); 328 script.src ='https://server.fillout.com/embed/v1/'; 329 document.head.appendChild(script); 330 331 }) 332} 333 334function getSearchParams(url,k){ 335 var p={}; 336 var a = document.createElement('a'); 337 a.href = url; 338 a.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){p[k]=v}) 339 return k?p[k]:p; 340} 341 342function GetQVars(v,qvars){ 343 if (qvars[v] != undefined) { 344 return qvars[v] 345 } 346 return '' 347} 348 349function getUrlVars() { 350 var vars = {}; 351 window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { 352 vars[key] = decodeURIComponent(value); 353 }); 354 return vars; 355} 356 357function GAClientID(){ 358 if ( typeof(ga) == 'function' && typeof(ga.getAll) == 'function'){ 359 var trackers = ga.getAll(); 360 if (trackers.length > 0 ){ 361 //maybe we'll update this later, so we can loop all the tracking ids... 362 var entries = Object.entries({"clientId":"gaclientid","referrer":"organic_source"}) 363 var domain = getDomainName() 364 for (const [gaName, handlName] of entries) { 365 var gaValue = trackers[0].get(gaName) 366 if (gaValue !== undefined) { 367 if (gaName != 'clientId'){ // we should reset the array for anythng other than clientId 368 gaNames = [] 369 } 370 371 gaNames.push(handlName) 372 373 for (const curName of gaNames){ 374 // console.log(curName, gaValue) 375 utms_js[curName] = gaValue 376 let cookieOptions = { 377 domain: domain, 378 sameSite: 'None', 379 secure: true 380 }; 381 382 if (!parseInt(handl_utm_session_cookies?.enabled)) { 383 cookieOptions.expires = parseInt(handl_utm_cookie_duration[0]); 384 } 385 386 Cookies.set(curName, gaValue, cookieOptions); 387 // console.log(`Setting ${handlName} as ${gaValue}`) 388 jQuery('input[name=\"' + curName + '\"]').val(gaValue) 389 jQuery('input#' + curName).val(gaValue) 390 jQuery('input.' + curName).val(gaValue) 391 } 392 393 // so we can include gaclientid to the links incase needed 394 populateLinks() 395 } 396 } 397 } 398 }else{ 399 setTimeout(GAClientID,500); 400 } 401} 402 403function getDomainName(){ 404 var name="HandLtestDomainName" 405 var value="HandLtestDomainValue" 406 var host=location.host 407 var domain; 408 409 if (host.split('.').length === 1){ 410 domain = ''; 411 }else{ 412 var domainParts = host.split('.'); 413 domainParts.shift(); 414 domain = '.'+domainParts.join('.'); 415 Cookies.set(name, value, { 416 domain: domain, 417 secure: true, 418 sameSite: 'None' 419 }) 420 if (Cookies.get(name) == null || Cookies.get(name) != value) 421 { 422 domain = '.'+host; 423 } 424 } 425 426 return domain; 427} 428 429function setHandLParams(){ 430 // console.log("set handl params") 431 432 SetRefLink('handl_url_base', document.location.origin + document.location.pathname, true, 0) 433 SetRefLink('handl_url', document.location.href, true, 0) 434 SetRefLink('handl_ref', document.referrer, true, 0) 435 SetRefLink('handl_ref_domain', document.referrer == '' ? '' : this.get_url_domain(document.referrer), true, 0) 436 SetRefLink('handl_landing_page', document.location.href, false, 0) 437 SetRefLink('handl_landing_page_base', new URL(document.location.href).origin + new URL(document.location.href).pathname, false, 0) 438 SetRefLink('handl_original_ref', document.referrer, false, 0) 439 440 let original_ref = Cookies.get('handl_ref_domain') 441 let this_domain = document.location.host 442 let source = "Other"; 443 if (original_ref == '') { 444 source = "Direct"; 445 }else if ( original_ref.match(/google\.co.*/i) !== null ){ 446 source = "Google"; 447 }else if ( original_ref.match(/bing\.co.*/i) !== null ){ 448 source = "Bing"; 449 }else if ( original_ref.match(/instagram\.co.*/i) !== null ){ 450 source = "Instagram"; 451 }else if ( original_ref.match(/facebook\.co.*/i) !== null || original_ref.match(/fb\.co.*/i) !== null ){ 452 source = "Facebook"; 453 }else if ( original_ref.match(/reddit\.com/i) !== null ){ 454 source = "Reddit"; 455 }else if ( original_ref.match(/twitter\.com/i) !== null || original_ref.match(/t\.co$/i) !== null || original_ref.match(/x\.com$/i) !== null ){ 456 source = "Twitter"; 457 }else if ( original_ref.match(/snapchat\.co.*/i) !== null ){ 458 source = "Snapchat"; 459 }else if ( original_ref.match(/youtube\.co.*/i) !== null ){ 460 source = "YouTube"; 461 }else if ( original_ref.match(/pinterest\.co.*/i) !== null ){ 462 source = "Pinterest"; 463 }else if ( original_ref.match(/linkedin\.co.*/i) !== null ){ 464 source = "LinkedIn"; 465 }else if ( original_ref.match(/tumblr\.com/i) !== null ){ 466 source = "Tumblr"; 467 }else if ( original_ref.match(/duckduckgo\.co.*/i) !== null ){ 468 source = "Duckduckgo"; 469 }else if ( original_ref.match(/openai\.com/i) !== null || original_ref.match(/chatgpt\.com/i) !== null ){ 470 source = "OpenAI"; 471 }else if ( original_ref.match(/perplexity\.ai/i) !== null ){ 472 source = "Perplexity"; 473 }else if ( original_ref.match(/claude\.ai/i) !== null ){ 474 source = "Claude"; 475 }else if ( original_ref.match(/gemini\.google\.com/i) !== null ){ 476 source = "Gemini"; 477 }else if ( original_ref.match(/copilot\.microsoft\.com/i) !== null ){ 478 source = "Copilot"; 479 }else if ( original_ref.match(/yelp\.com/i) !== null ){ 480 source = "Yelp"; 481 }else if (this_domain == original_ref){ 482 source = "Internal"; 483 } 484 485 if(
486 ( !Cookies.get('organic_source_str') || Cookies.get('organic_source_str') == '' ) || 487 ( Cookies.get('organic_source_str') && Cookies.get('organic_source_str') != '' && ['Internal','Direct'].indexOf(source) == -1 ) 488 ){ 489 SetRefLink('organic_source', document.referrer, true, 0) 490 SetRefLink('organic_source_str', source, true, 0) 491 } 492 493 494 var qvars = getUrlVars() 495 let traffic_source = 'Other' 496 if ( 497 Cookies.get('gclid') != undefined || 498 Cookies.get('msclkid') != undefined || 499 Cookies.get('wbraid') != undefined || 500 Cookies.get('gbraid') != undefined || 501 Object.keys(qvars).indexOf('gclid') != -1 || 502 Object.keys(qvars).indexOf('msclkid') != -1 || 503 Object.keys(qvars).indexOf('wbraid') != -1 || 504 Object.keys(qvars).indexOf('gbraid') != -1 || 505 (Cookies.get('fbclid') != undefined && Cookies.get('_fbc') != undefined) || 506 (Object.keys(qvars).indexOf('fbclid') != -1 && Cookies.get('_fbc') != undefined) || 507 Object.keys(qvars).indexOf('gad_source') != -1 || 508 Object.keys(qvars).indexOf('gad_campaignid') != -1 509 ){ 510 traffic_source = 'Paid' 511 }
511else if ( ['Google','Bing','Yahoo','Duckduckgo'].indexOf(Cookies.get('organic_source_str')) > -1 ){ 512 traffic_source = 'Organic' 513 }else if ( ['Facebook','Twitter','Instagram','Snapchat','YouTube','Pinterest','LinkedIn','Tumblr','Reddit'].indexOf(Cookies.get('organic_source_str')) > -1 ){ 514 traffic_source = 'Social' 515 }else if ( ['Internal','Direct'].indexOf(Cookies.get('organic_source_str')) > -1 ){ 516 traffic_source = 'Direct' 517 }else if ( Cookies.get('organic_source_str') && ['Internal'].indexOf(Cookies.get('organic_source_str')) == -1 ){ 518 traffic_source = 'Referral' 519 } 520 521 SetRefLink('traffic_source', traffic_source, true, 0) 522 SetRefLink('first_traffic_source', traffic_source, false, 0) 523 524 document.dispatchEvent(new CustomEvent('handl_cookies_set')); 525 526} 527 528function SetRefLink(field, value, overwrite, count){ 529 // console.log(`Trying ${count} for ${field} ---> ${value}`) 530 var domain = getDomainName() 531 532 if (Cookies.get(field) != value) { 533 if (Cookies.get(field) !== undefined && Cookies.get(field) != "" && !overwrite ){ 534 //bail... 535 // console.log(`No need to update... ${field}`) 536 }else if (Cookies.get(field) === undefined || Cookies.get(field) == '' || overwrite) { 537 if (count == undefined) { 538 count = 0 539 } 540 541 // utms_js[field] = value //not sure if we really need it here 542 // console.log(`Setting cookies for ${field} as ${value}`) 543 let cookieOptions = { 544 domain: domain, 545 sameSite: 'None', 546 secure: true 547 }; 548 549 if (!parseInt(handl_utm_session_cookies?.enabled)) { 550 cookieOptions.expires = parseInt(handl_utm_cookie_duration[0]); 551 } 552 553 Cookies.set(field, value, cookieOptions); 554 555 } else { 556 count = count + 1 557 if (count < 3) { 558 setTimeout(function () { 559 SetRefLink(field, value, overwrite, count) 560 }, 500) 561 } 562 } 563 } 564} 565 566function get_url_domain(url) { 567 let a = document.createElement('a'); 568 a.href = url; 569 return a.hostname; 570} 571 572//This is for OptinMonster events: https://optinmonster.com/docs/optinmonster-javascript-events-api/ 573document.addEventListener('om.Campaign.afterShow',function(){ 574 RunFieldFiller() 575}) 576 577window.addEventListener('CookiebotOnAccept', function (e) { 578 if (Cookiebot.consent.marketing) 579 { 580 RunHandL() 581 } 582}, false); 583 584document.addEventListener("cmplz_enable_category", function(consentData) { 585 var category = consentData.detail.category; 586 if (category==='marketing'){ 587 RunHandL() 588 } 589}); 590 591// WP Consent API integration 592document.addEventListener('wp_listen_for_consent_change', function (e) { 593 var changedConsentCategory = e.detail; 594 for (var key in changedConsentCategory) { 595 if (changedConsentCategory.hasOwnProperty(key)) { 596 if (key === 'marketing' && changedConsentCategory[key] === 'allow') { 597 console.log('WP Consent API: Marketing consent granted, running HandL'); 598 RunHandL(); 599 } 600 } 601 } 602}); 603 604// Check if consent already exists on page load 605if (typeof wp_has_consent === 'function' && wp_has_consent('marketing')) { 606 console.log('WP Consent API: Marketing consent already granted'); 607} 608 609 610function afterBookingSelectDateAndTime(a){ 611 Object.keys(a.bookings[0].customFields).forEach(function(key) { 612 let label = a.bookings[0].customFields[key].label 613 if (Cookies.get(label)){ 614 a.bookings[0].customFields[key].value = Cookies.get(label) 615 } 616 }); 617} 618 619window.ameliaActions = { 620 beforeBooking: function(x,y,a){ 621 afterBookingSelectDateAndTime(a) 622 x() 623 } 624} 625 626/* 627FormStack solution... 628 */ 629function FF_AutoFiller(v){ 630 let it = jQuery(v) 631 632 for ( vv of ['placeholder', 'title'] ) { 633 var ph = it.attr(vv) 634 var params = Object.values(handl_utm_all_params) 635 var n = params.findIndex( (p) => new RegExp(p,'i').test(ph) ) 636 if (n > -1){ 637 var cval = Cookies.get(params[n]) 638 it.val(cval).attr('value',cval) 639 } 640 } 641} 642setTimeout(function () { 643 jQuery('.fsCell.fsHidden>input').map( (i, v) => { FF_AutoFiller(v) }) 644}, 3000) 645 646jQuery(document).on('wsf-rendered', function(event, form_object, form_id, instance_id) { 647 RunFieldFiller() 648}); 649 650// function FF_OnAfterRender(){ 651// console.log("Form rendered successfully!"); 652// // var vars = ["Lead.UTM_Campaign__c","Lead.UTM_Medium__c","Lead.UTM_Source__c","Lead.UTM_Term__c","Lead.UTM_Content__c","Lead.GCLID__c","Lead.FBclid__c"] 653// // for (v of vars){ 654// // escape_v = v.replace(/\./g, '\\.')
655// // jQuery("#"+escape_v).val(Cookies.get(v)); 656// // } 657// return true; 658// } 659 660// wp.hooks.addFilter('jet.fb.inputs','jet-plugins',function(x,y,z,t,i){console.log(x,y,z,t,i)}) 661// wp.hooks.addFilter('jet.fb.macro.field.value','jet-plugins',function(x,y,z,t,i){console.log(x,y,z,t,i)}) 662// wp.hooks.addAction('jet.fb.observe.after','jet-plugins',function(x,y,z,t,i){console.log(x,y,z,t,i)}) 663 664//This is to support Jet Form Builder 665jQuery(document).on('jet-form-builder/after-init',function(e){ 666 RunFieldFiller() 667}) 668 669setTimeout(() => { //jotform iframe embed support 670 if (typeof(window.utms_js) == 'object' && typeof(iframeParams) == 'object'){ 671 var iframeParams = []; 672 iframeParams.push( jQuery.param(window.utms_js) ) 673 var src = ifr.src; 674 ifr.src = src + "?" + iframeParams.join('&'); 675 } 676}, "500"); 677 678 679jQuery( document ).on( 'elementor/popup/show' , function () { 680 setTimeout(RunFieldFiller, 1000) 681} ); 682 683//Borlabs cookie client-side 684window.addEventListener('borlabs-cookie-consent-saved', () => { 685 if (window.BorlabsCookie.Consents.hasConsent('handl-utm-grabber')){ 686 RunHandL() 687 } 688}); 689 690getAllHandLUTMParams = function() { 691 var values = {}; 692 693 Object.values(handl_utm_all_params).forEach(function(param) { 694 var value = Cookies.get(param); 695 if (value) { 696 values[param] = decodeURIComponent(value); 697 } 698 }); 699 700 return values; 701}; 702 703function getUserData() { 704 return { 705 fbc: Cookies.get('_fbc') || '', 706 fbp: Cookies.get('_fbp') || '', 707 client_ip_address: Cookies.get('handl_ip') || '', 708 client_user_agent: navigator.userAgent 709 }; 710} 711 712jQuery(document).ready(function($) { 713 setTimeout(() => { 714 var emailField = $('#email'); 715 var hasInitiatedCheckout = false; 716 717 // Check if we're on the WooCommerce checkout page 718 if ($('body').hasClass('woocommerce-checkout')) { 719 emailField.on('blur', function() { 720 if (!hasInitiatedCheckout && emailField.val().trim() !== '') { 721 hasInitiatedCheckout = true; 722 var userData = getUserData(); 723 userData.em = [emailField.val()]; 724 $.ajax({ 725 url: handl_ajax.ajax_url, 726 type: 'POST', 727 data: { 728 action: 'handl_initiate_checkout', 729 user_data: userData 730 }, 731 success: function(response) { 732 console.log('InitiateCheckout event sent:', response); 733 } 734 }); 735 } 736 }); 737 } 738 }, 500); 739}); 740 741function isFBCAPIEnabled() { 742 return handl_ajax.fb_capi_enabled === '1'; 743} 744 745jQuery(document).on('added_to_cart', function(event, fragments, cart_hash, button) { 746 if (!isFBCAPIEnabled()) return; 747 748 var productId = button.data('product_id'); 749 var quantity = button.data('quantity'); 750 751 if (typeof productId !== 'undefined' && typeof quantity !== 'undefined') { 752 var userData = getUserData(); 753 754 jQuery.ajax({ 755 url: handl_ajax.ajax_url, 756 type: 'POST', 757 data: { 758 action: 'handl_ajax_add_to_cart', 759 product_id: productId, 760 quantity: quantity, 761 user_data: userData 762 }, 763 success: function(response) { 764 console.log('AddToCart event sent:', response); 765 } 766 }); 767 } 768}); 769 770 771jQuery(function($) { 772 $('form.checkout').on('checkout_place_order', function() { 773 if (!isFBCAPIEnabled()) return; 774 775 var userData = getUserData(); 776 777 $.ajax({ 778 url: handl_ajax.ajax_url, 779 type: 'POST', 780 data: { 781 action: 'handl_add_payment_info', 782 user_data: userData 783 }, 784 success: function(response) { 785 console.log('AddPaymentInfo event sent:', response); 786 } 787 }); 788 }); 789}); 790 791function sanitizeInput(input) { 792 var element = document.createElement('div'); 793 element.innerText = input; 794 return element.innerHTML; 795} 796 797function getConsentStatus() { 798 if (!window.dataLayer) { 799 console.warn('dataLayer is not defined.'); 800 return null; 801 }
802 let consent = null; 803 // Iterate through dataLayer in reverse to find the latest consent event 804 for (let i = window.dataLayer.length - 1; i >= 0; i--) { 805 if (window.dataLayer[i][0] === 'consent' && window.dataLayer[i][1] === 'update') { 806 consent = window.dataLayer[i][2]; 807 break; 808 }else if (typeof window.dataLayer[i] === 'object' && window.dataLayer[i].value && window.dataLayer[i].value.event && window.dataLayer[i].value.event.includes('consent')) { 809 consent = window.dataLayer[i].value; 810 break; 811 } 812 } 813 return consent; 814} 815 816function isConsentDenied() { 817 const consentStatus = getConsentStatus(); 818 return consentStatus && (consentStatus.ad_user_data === 'denied' && (consentStatus.analytics_storage === 'denied' || !consentStatus.analytics_storage)); 819} 820 821function handleConsentStatus() { 822 if (isConsentDenied()) { 823 RemoveHandLCookies(); 824 } else { 825 RunHandL(); 826 } 827} 828 829function RemoveHandLCookies() { 830 console.log('Removing HandL cookies'); 831 Object.values(handl_utm_all_params).forEach(param => { 832 Cookies.remove(param, { path: '/', domain: getDomainName() }); 833 }); 834} 835 836(function() { 837 if (typeof handl_ajax.require_third_party_consent !== 'undefined' && handl_ajax.require_third_party_consent) { 838 if (!window.dataLayer) { 839 window.dataLayer = []; 840 } 841 842 const originalPush = window.dataLayer.push; 843 844 window.dataLayer.push = function(...args) { 845 args.forEach(entry => { 846 if ( 847 (Array.isArray(entry) && entry[0] === 'consent' && entry[1] === 'update') 848 || (entry.event && entry.event.includes('consent')) 849 || (entry.value && entry.value.event && entry.value.event.includes('consent')) 850 ) { 851 // Handle the consent update 852 // console.log(`entry3: ${JSON.stringify(entry)}`); 853 handleConsentStatus(); 854 } 855 856 // if (entry.event && entry.event.includes('marketing')) { 857 // // Handle the consent update 858 // console.log(`entry4: ${JSON.stringify(entry)}`); 859 // console.log(getConsentStatus()); 860 // } 861 // 862 // if (typeof entry === 'object' && Object.keys(entry).some(key => key.includes('marketing'))) { 863 // // Handle the consent update 864 // console.log(`entry5: ${JSON.stringify(entry)}`); 865 // console.log(getConsentStatus()); 866 // } 867 }); 868 869 return originalPush.apply(this, args); 870 }; 871 } 872})();
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.