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 RunHandL() 30 } 31}); 32 33 34function RunHandL(){ 35 window.utms_js = {} 36 window.gaNames = [] 37 38 //simulate referrer locally 39 // Object.defineProperty(document, "referrer", {get : function(){ return "https://google.com"; }}); 40 41 SetRefLink('handlID', Math.floor(Math.random() * Date.now()), false, 0) 42 43 GAClientID() 44 setHandLParams() 45 46 // console.log("after handl params") 47 48 RunFieldFiller() 49 50 jQuery.each(handl_utm_predefined, function( i,v ) { 51 let cookie_name = v.name; 52 let value = v.value 53 54 if ( value.startsWith('[') && value.endsWith(']') ){ //it's a shortcode! 55 value = v.value.replace(/^\[|\]$/g,''); 56 }else{ //it is a hardcoded default value 57 value = cookie_name 58 } 59 60 if ( ['_ga','gaclientid'].indexOf(value) > -1 ){ 61 gaNames.push(cookie_name) 62 } 63 64 if (cookie_name != ''){ 65 var cookie_field = GetQVars(value,qvars) 66 67 if (cookie_field == ''){ 68 cookie_field = Cookies.get(value) 69 } 70 71 if ( cookie_field != '' && cookie_field != 'PANTHEON_STRIPPED' ){ 72 utms_js[cookie_name] = cookie_field 73 SetRefLink(cookie_name, cookie_field, true, 0) 74 } 75 } 76 }) 77 78 populateLinks() 79 80 jQuery(document).on( 'nfFormReady', function() { 81 form.fields.map(item => { 82 if (item.default) { 83 var matches = item.default.match(/^{(\w+):(\w+)/) 84 if (matches && matches.length == 3) { 85 let key = matches[1] 86 let value = matches[2] 87 88 if (key === 'handl') { 89 jQuery('#nf-field-' + item.id).val(Cookies.get(value)) 90 } 91 } 92 } 93 }) 94 95 //hide hidden fields 96 jQuery('.nf-field-container.hidden-container').map( (i, item) => jQuery(item).parents().eq(4).hide()) 97 }) 98} 99 100function RunFieldFiller(){ 101 102 Cookies.set('user_agent', navigator.userAgent, {domain: domain}) 103 104 jQuery.each(handl_utm_all_params, function( i,vi ) { 105 var cookie_field = GetQVars(vi,qvars) 106 107 var cookie_params = [vi] 108 if ( handl_utm_first_touch_params.includes(vi) ) 109 cookie_params.push('first_'+vi) 110 111 cookie_params.forEach( (v, ind) => { 112 113 if ( cookie_field != '' && cookie_field != 'PANTHEON_STRIPPED' ){ 114 if ( v.startsWith('first_') && Cookies.get(v) != undefined ){ 115 //do not update the first attributes... 116 }else{ 117 Cookies.set(v, cookie_field, { 118 expires: parseInt(handl_utm_cookie_duration[0]), 119 domain: domain, 120 sameSite:'None', 121 secure: true }); 122 } 123 } 124 125 var curval = decodeURI(Cookies.get(v)) 126 127 if (curval != 'undefined') { 128 utms_js[v] = curval 129 curval = decodeURIComponent(curval) 130 // curval = curval.replace(/[%]/g,' ') 131 if (v == 'username') { 132 //Maybe this should apply to all... We'll see... 133 curval = curval.replace(/\+/g, ' ') 134 } 135 136 jQuery('input[name=\"'+v+'\"]').val(curval) 137 jQuery('input#'+v).val(curval) 138 jQuery('input.'+v).val(curval) 139 jQuery('input#form-field-'+v).val(curval) 140 141 //for nested input fix 142 jQuery('#'+v).find('input').val(curval) 143 jQuery('.'+v).find('input').val(curval) 144 145 jQuery("[data-original_id='"+v+"']").val(curval) 146 147 //wildcard selector 148 jQuery("[name*="+v+"]").val(curval) 149 jQuery("[id*="+v+"]").val(curval) 150 jQuery("[class*="+v+"]").val(curval) 151 152 jQuery("[class*="+v+"_out]").html(curval) 153 jQuery("[id*="+v+"_out]").html(curval) 154 155 } 156 }) 157 }); 158} 159 160function populateLinks(){ 161 jQuery('.utm-out-js, .utm-out-js a').each(function(){ 162 var merged_raw = jQuery.extend( {}, utms_js ) 163 var merged = Object.keys(merged_raw) 164 .filter(key => handl_utm_append_params.includes(key)) 165 .reduce((obj, key) => { 166 obj[key] = merged_raw[key]; 167 return obj; 168 }, {}); 169 merged = jQuery.extend(merged, getSearchParams(this.href)) 170 if ( 171 this.href !== undefined && 172 this.href !== "" && 173 !this.href.match("#") && 174 !this.href.startsWith("tel:") && 175 !this.href.startsWith("mailto:") && 176 !this.href.startsWith("sms:") && 177 !jQuery(this).attr('onclick') && 178 this.href.match(new RegExp("^"+current_page+"$")) == null 179 ){ 180 var href = this.href.split("?")[0]; 181 if ( !jQuery.isEmptyObject(merged) ) 182 this.href = href+"?"+decodeURIComponent(jQuery.param(merged)) 183 } 184 }) ; 185 186 // console.log(handl_utm) 187 // console.log(utms_js) 188 189 jQuery('.utm-out, .utm-out a').each(function(){ 190 var merged_raw = jQuery.extend( {}, handl_utm, utms_js ) 191 var merged = Object.keys(merged_raw) 192 .filter(key => handl_utm_append_params.includes(key)) 193 .reduce((obj, key) => { 194 obj[key] = decodeURIComponent(merged_raw[key]); 195 return obj; 196 }, {}); 197 merged = jQuery.extend(merged, getSearchParams(this.href)) 198 var current_page = window.location.href.split('?')[0] 199 200 if ( 201 this.href !== undefined && 202 this.href !== "" && 203 !this.href.match("#") && 204 !this.href.startsWith("tel:") && 205 !this.href.startsWith("mailto:") && 206 !this.href.startsWith("sms:") && 207 !jQuery(this).attr('onclick') && 208 this.href.match(new RegExp("^"+current_page+"$")) == null 209 ){ 210 var href = this.href.split("?")[0]; 211 if ( !jQuery.isEmptyObject(merged) ) 212 this.href = href+"?"+decodeURIComponent(jQuery.param(merged)) 213 } 214 }); 215
216 jQuery('.utm-src').each(function(){ 217 var target_url 218 if (this.src){ 219 target_url = this.src 220 }else if (jQuery(this).data('url')){ 221 target_url = jQuery(this).data('url') 222 } 223 224 var merged = jQuery.extend( {}, handl_utm, getSearchParams(target_url) ) 225 226 var src = target_url.split("?")[0]; 227 if ( !jQuery.isEmptyObject(merged) ){ 228 var final_target = src + "?" + decodeURIComponent(jQuery.param(merged)) 229 if (this.src) { 230 this.src = final_target 231 }else if (jQuery(this).data('url')){ 232 jQuery(this).data('url', final_target) 233 } 234 } 235 }); 236} 237 238function getSearchParams(url,k){ 239 var p={}; 240 var a = document.createElement('a'); 241 a.href = url; 242 a.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){p[k]=v}) 243 return k?p[k]:p; 244} 245 246function GetQVars(v,qvars){ 247 if (qvars[v] != undefined) { 248 return qvars[v] 249 } 250 return '' 251} 252 253function getUrlVars() { 254 var vars = {}; 255 window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { 256 vars[key] = value; 257 }); 258 return vars; 259} 260 261function GAClientID(){ 262 if ( typeof(ga) == 'function' && typeof(ga.getAll) == 'function'){ 263 var trackers = ga.getAll(); 264 if (trackers.length > 0 ){ 265 //maybe we'll update this later, so we can loop all the tracking ids... 266 var entries = Object.entries({"clientId":"gaclientid","referrer":"organic_source"}) 267 var domain = getDomainName() 268 for (const [gaName, handlName] of entries) { 269 var gaValue = trackers[0].get(gaName) 270 if (gaValue !== undefined) { 271 if (gaName != 'clientId'){ // we should reset the array for anythng other than clientId 272 gaNames = [] 273 } 274 275 gaNames.push(handlName) 276 277 for (const curName of gaNames){ 278 // console.log(curName, gaValue) 279 utms_js[curName] = gaValue 280 Cookies.set(curName, gaValue, { 281 expires: parseInt(handl_utm_cookie_duration[0]), 282 domain: domain, 283 sameSite:'None', 284 secure: true } 285 ); 286 // console.log(`Setting ${handlName} as ${gaValue}`) 287 jQuery('input[name=\"' + curName + '\"]').val(gaValue) 288 jQuery('input#' + curName).val(gaValue) 289 jQuery('input.' + curName).val(gaValue) 290 } 291 292 // so we can include gaclientid to the links incase needed 293 populateLinks() 294 } 295 } 296 } 297 }else{ 298 setTimeout(GAClientID,500); 299 } 300} 301 302function getDomainName(){ 303 var name="HandLtestDomainName" 304 var value="HandLtestDomainValue" 305 var host=location.host 306 var domain; 307 308 if (host.split('.').length === 1){ 309 domain = ''; 310 }else{ 311 var domainParts = host.split('.'); 312 domainParts.shift(); 313 domain = '.'+domainParts.join('.'); 314 Cookies.set(name, value, {domain: domain}) 315 if (Cookies.get(name) == null || Cookies.get(name) != value) 316 { 317 domain = '.'+host; 318 } 319 } 320 321 return domain; 322} 323 324function setHandLParams(){ 325 // console.log("set handl params") 326 327 SetRefLink('handl_url_base', document.location.origin + document.location.pathname, true, 0) 328 SetRefLink('handl_url', document.location.href, true, 0) 329 SetRefLink('handl_ref', document.referrer, true, 0) 330 SetRefLink('handl_ref_domain', document.referrer == '' ? '' : this.get_url_domain(document.referrer), true, 0) 331 SetRefLink('handl_landing_page', document.location.href, false, 0) 332 SetRefLink('handl_original_ref', document.referrer, false, 0) 333 334 let original_ref = Cookies.get('handl_ref_domain') 335 let this_domain = document.location.host 336 let source = "Other"; 337 if (original_ref == '') { 338 source = "Direct"; 339 }else if ( original_ref.match(/google/i) !== null ){ 340 source = "Google"; 341 }else if ( original_ref.match(/yahoo/i) !== null ){
342 source = "Yahoo"; 343 }else if ( original_ref.match(/bing/i) !== null ){ 344 source = "Bing"; 345 }else if ( original_ref.match(/instagram/i) !== null ){ 346 source = "Instagram"; 347 }else if ( original_ref.match(/facebook/i) !== null || original_ref.match(/fb\.com$/i) !== null ){ 348 source = "Facebook"; 349 }else if ( original_ref.match(/twitter/i) !== null || original_ref.match(/t\.co$/i) !== null ){ 350 source = "Twitter"; 351 }else if ( original_ref.match(/snapchat/i) !== null ){ 352 source = "Snapchat"; 353 }else if ( original_ref.match(/youtube/i) !== null ){ 354 source = "YouTube"; 355 }else if ( original_ref.match(/pinterest/i) !== null ){ 356 source = "Pinterest"; 357 }else if ( original_ref.match(/linkedin/i) !== null ){ 358 source = "LinkedIn"; 359 }else if ( original_ref.match(/tumblr/i) !== null ){ 360 source = "Tumblr"; 361 }else if ( original_ref.match(/duckduckgo/i) !== null ){ 362 source = "Duckduckgo"; 363 }else if (this_domain == original_ref){ 364 source = "Internal"; 365 } 366 367 if( 368 ( !Cookies.get('organic_source_str') || Cookies.get('organic_source_str') == '' ) || 369 ( Cookies.get('organic_source_str') && Cookies.get('organic_source_str') != '' && ['Internal','Direct'].indexOf(source) == -1 ) 370 ){ 371 SetRefLink('organic_source', document.referrer, true, 0) 372 SetRefLink('organic_source_str', source, true, 0) 373 } 374 375 376 var qvars = getUrlVars() 377 let traffic_source = 'Other' 378 if ( 379 Cookies.get('fbclid') != undefined || 380 Cookies.get('gclid') != undefined || 381 Cookies.get('msclkid') != undefined || 382 Object.keys(qvars).indexOf('fbclid') != -1 || 383 Object.keys(qvars).indexOf('gclid') != -1 || 384 Object.keys(qvars).indexOf('msclkid') != -1 385 ){ 386 traffic_source = 'Paid' 387 }
387else if ( ['Google','Bing','Yahoo','Duckduckgo'].indexOf(Cookies.get('organic_source_str')) > -1 ){ 388 traffic_source = 'Organic' 389 }else if ( ['Facebook','Twitter','Instagram','Snapchat','YouTube','Pinterest','LinkedIn','Tumblr'].indexOf(Cookies.get('organic_source_str')) > -1 ){ 390 traffic_source = 'Social' 391 }else if ( ['Internal','Direct'].indexOf(Cookies.get('organic_source_str')) > -1 ){ 392 traffic_source = 'Direct' 393 }else if ( Cookies.get('organic_source_str') && ['Internal'].indexOf(Cookies.get('organic_source_str')) == -1 ){ 394 traffic_source = 'Referral' 395 } 396 397 SetRefLink('traffic_source', traffic_source, true, 0) 398 399} 400 401function SetRefLink(field, value, overwrite, count){ 402 // console.log(`Trying ${count} for ${field} ---> ${value}`) 403 var domain = getDomainName() 404 405 if (Cookies.get(field) != value) { 406 if (Cookies.get(field) !== undefined && Cookies.get(field) != "" && !overwrite ){ 407 //bail... 408 // console.log(`No need to update... ${field}`) 409 }else if (Cookies.get(field) === undefined || Cookies.get(field) == '' || overwrite) { 410 if (count == undefined) { 411 count = 0 412 } 413 414 // utms_js[field] = value //not sure if we really need it here 415 // console.log(`Setting cookies for ${field} as ${value}`) 416 Cookies.set(field, value, { 417 expires: parseInt(handl_utm_cookie_duration[0]), 418 domain: domain, 419 sameSite: 'None', 420 secure: true 421 } 422 ); 423 424 } else { 425 count = count + 1 426 if (count < 3) { 427 setTimeout(function () { 428 SetRefLink(field, value, overwrite, count) 429 }, 500) 430 } 431 } 432 } 433} 434 435function get_url_domain(url) { 436 let a = document.createElement('a'); 437 a.href = url; 438 return a.hostname; 439} 440 441//This is for OptinMonster events: https://optinmonster.com/docs/optinmonster-javascript-events-api/ 442document.addEventListener('om.Campaign.afterShow',function(){ 443 RunFieldFiller() 444}) 445 446window.addEventListener('CookiebotOnAccept', function (e) { 447 if (Cookiebot.consent.marketing) 448 { 449 RunHandL() 450 } 451}, false); 452 453function afterBookingSelectDateAndTime(a){ 454 Object.keys(a.bookings[0].customFields).forEach(function(key) { 455 let label = a.bookings[0].customFields[key].label 456 if (handl_utm[label]){ 457 a.bookings[0].customFields[key].value = handl_utm[label] 458 } 459 }); 460} 461 462window.ameliaActions = { 463 beforeBooking: function(x,y,a){ 464 afterBookingSelectDateAndTime(a) 465 x() 466 } 467}
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.