(function(){"use strict";const c="data-",Ne="false",g="true",ne="lm_ssid",oe="lm_vid",ie="lm_cst",re="{{LM_SESS}}",_="__LM_SESS__",se=document.currentScript,l=e=>se.getAttribute(e),Be=l(c+"auto-track")!==Ne,s=l(c+"jrny")??l(c+"id")??void 0,xe=l(c+"host-url")??void 0,qe=l(c+"exclude-search")===g,M=l(c+"domains")||"",Fe=M?M.split(",").map(e=>e.trim()):[];l(c+"tag");const ae=l(c+"frm-dtct")??void 0,He=l(c+"multi-dmn")===g,Ke=l(c+"consent")!==g,D=l(c+"isolated")===g,je=l(c+"consent-mode")===g,u=D?ne+"_"+s:ne,f=D?oe+"_"+s:oe,S=D?ie+"_"+s:ie,We=new URL(se.src),V=xe||We.origin,k=V.replace(/\/$/,"");let w,b,y={},N="",d=!0;try{const e="lm__str__test__";localStorage.setItem(e,"1"),localStorage.removeItem(e)}catch{d=!1}const ce=e=>{w=e.ssid,b=e.vid,L(e.cst),e.cst&&(B(e.ssid,90),d&&localStorage.setItem(u,e.ssid),x(e.vid,30),d&&sessionStorage.setItem(f,e.vid))};function Xe(e){w=e,T()&&(B(e,90),d&&localStorage.setItem(u,e))}function Je(e){b=e,T()&&(x(e,30),d&&localStorage.setItem(f,e))}function L(e){ue(e,90),d&&localStorage.setItem(S,e?"true":"false")}function le(){document.cookie=`${u}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`,d&&localStorage.removeItem(u),E()}function ze(){document.cookie=`${u}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`,document.cookie=`${f}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`,d&&(localStorage.removeItem(u),localStorage.removeItem(f)),w=void 0,b=void 0,E()}function B(e,n=90){const t=new Date;t.setTime(t.getTime()+n*24*60*60*1e3),document.cookie=`${u}=${e}; expires=${t.toUTCString()}; path=/`,E()}function x(e,n=30){const t=new Date;t.setTime(t.getTime()+n*60*1e3),document.cookie=`${f}=${e}; expires=${t.toUTCString()}; path=/`,E()}function ue(e,n=90){const t=new Date;t.setTime(t.getTime()+n*24*60*60*1e3),document.cookie=`${S}=${e}; expires=${t.toUTCString()}; path=/`,E()}function E(){N="",y={}}const Ge=[u,f,S];function q(){const e=document.cookie;if(e===N)return y;if(N=e,y={},e){const n=e.split("; ");for(const t of n){const[o,i]=t.split("=");o&&Ge.includes(o)&&(y[o]=i)}}return y}function a(){const e=new URLSearchParams(window.location.search).get(u);e&&Xe(e);const t=q()[u];if(t&&t!=="undefined")return t;if(d){const o=localStorage.getItem(u);if(o&&o!=="undefined")return B(o),o}if(w)return w}function Ze(){const e=new URLSearchParams(window.location.search).get(f);e&&Je(e);const t=q()[f];if(t&&t!=="undefined")return t;if(d){const o=localStorage.getItem(f);if(o&&o!=="undefined")return x(o),o}if(b)return b}function T(){const n=q()[S];if(n&&n!=="undefined")return n==="true";if(d){const t=localStorage.getItem(S);if(t&&t!=="undefined")return ue(t==="true"),t==="true"}return je?!1:Ke}const C=()=>{const e=a();if(e===void 0)return;const n=document.querySelectorAll("input");document.querySelectorAll(`input[value="${re}"]`).forEach(t=>{t.value=e,t.dispatchEvent(new Event("input",{bubbles:!0}))});for(let t=0;t<n.length;t++)n[t].value.trim()===re&&(n[t].value=e)};function Dt(e){}const F=e=>{try{const{pathname:n,search:t}=new URL(e);e=n+t}catch{}return qe?e.split("?")[0]:e},de=e=>{if(e){try{const n=decodeURI(e);if(n!==e)return n}catch{return e}return encodeURI(e)}};function Qe(){document.addEventListener("click",e=>{const t=e.target.closest("a");if(!t||!t.href||!He)return;const o=new URL(t.href);o.hostname!==location.hostname&&(a()&&o.searchParams.set(u,a()),t.target==="_blank"||e.ctrlKey||e.metaKey||e.button===1?(e.preventDefault(),window.open(o.toString(),"_blank")):(e.preventDefault(),window.location.href=o.toString()))})}function Ye(e){let n=0;for(let t=0;t<e.length;t++)n=(n+e.charCodeAt(t))%256;return n}function fe(e,n){const t=Ye(n);let o="";for(let i=0;i<e.length;i++){const r=e.charCodeAt(i);o+=String.fromCharCode((r+t)%256)}return btoa(o)}function H(){const e=document.cookie.match(/(^|;)\s*_fbp=([^;]+)/);return e?e[2]:void 0}function et(){return/iP(hone|od|ad)/i.test(navigator.userAgent)}function me(){if(!et())return!1;const e=navigator.userAgent||"";if(/WKWebView/i.test(e)||/(Musical\.ly|TikTok|Instagram|FBAN|FBAV|FB_IAB|Line\/|Snapchat|GSA|YaBrowser|OPiOS)/i.test(e))return!0;const n=/\bSafari\//.test(e),t=/\bVersion\//.test(e);return!!(n&&!t||typeof window.webkit<"u"&&!t)}function he(){const e=navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1;return/Mobi|iPhone|Android/i.test(navigator.userAgent)||e}const{navigator:{language:pe},screen:{width:tt,height:nt}}=window,{referrer:ge}=document,K=`${k}/api/v3/events/harvest`,{hostname:j,href:ot}=location;let it=ge!==j?ge:"",rt=F(ot);const ve=`${tt}x${nt}`,Se=Intl.DateTimeFormat().resolvedOptions().timeZone,we=new Date().getTimezoneOffset(),I=[];let A=a()!==void 0;function be(){if(!A||I.length===0)return;const e=a();if(e)for(;I.length>0;){const n=I.shift();n&&Date.now()-n.timestamp<3e4&&W(n,e)}}function ye(e,n){A?W({endpoint:e,payload:n,timestamp:Math.floor(new Date().getTime()/1e3)},a()||""):I.push({payload:n,timestamp:Date.now(),endpoint:e})}function Ee(e,n){const t=a();W({endpoint:e,payload:n,timestamp:Math.floor(new Date().getTime()/1e3)},t)}function W(e,n){if(s===void 0)return;let t=`${e.endpoint}?jrny=${encodeURIComponent(s)}`,o=typeof e.payload=="function"?e.payload(n):e.payload;n!==void 0&&n!==""?t+=`&ss=${encodeURIComponent(n)}`:o={...o,timeZone:Se,timeZoneOffset:we,screen:ve,language:pe};const i=new URLSearchParams(o).toString();typeof navigator<"u"&&"sendBeacon"in navigator&&typeof navigator.sendBeacon=="function"&&!he()&&!me()&&st(t,i)||(typeof fetch=="function"?fetch(t,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"},keepalive:!0}).then(()=>{}).catch(()=>{Te(t,i)}):Te(t,i))}function Te(e,n){try{const t=new XMLHttpRequest;t.open("POST",e,!0),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.onreadystatechange=function(){t.readyState,XMLHttpRequest.DONE},t.onerror=function(){},t.send(n)}catch{}}function st(e,n){try{const t=new Blob([n],{type:"application/x-www-form-urlencoded"});return navigator.sendBeacon(e,t)}catch{return!1}}async function X(e){const n=a(),t=Ze(),o={...e,vid:t,ts:Math.floor(new Date().getTime()/1e3)},i=Object.fromEntries(Object.entries(o).filter(([m,v])=>v!=null));if(!(typeof navigator<"u"&&"sendBeacon"in navigator&&typeof navigator.sendBeacon=="function"&&!he()&&!me()&&n&&t&&at(K,i,n))){if(typeof fetch=="function"){const m=await ct(K,i,n);if(m!==void 0)return m}return lt(K,i,n)}}function at(e,n,t){if(!("sendBeacon"in navigator)||s===void 0)return!1;try{const o=new Blob([new URLSearchParams(n).toString()],{type:"application/x-www-form-urlencoded"}),i=`${e}?jrny=${encodeURIComponent(s)}${t?`&ss=${encodeURIComponent(t)}`:""}`;return navigator.sendBeacon(i,o)}catch{return!1}}async function ct(e,n,t){if(s!==void 0)try{const o=new URLSearchParams(n).toString(),i=await fetch(`${e}?jrny=${encodeURIComponent(s)}${t?`&ss=${encodeURIComponent(t)}`:""}`,{method:"POST",body:o,headers:{"Content-Type":"application/x-www-form-urlencoded"},keepalive:!0});if(i.status===200){const r=await i.json();return ce(r),A=!0,be(),r}else i.status===403&&(await i.json()).title==="invalid_ssid"&&le()}catch{return}}function lt(e,n,t){if(s!==void 0)return new Promise(o=>{try{const i=new URLSearchParams(n).toString(),r=new XMLHttpRequest,m=`${e}?jrny=${encodeURIComponent(s)}${t?`&ss=${encodeURIComponent(t)}`:""}`;r.open("POST",m,!0),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.onreadystatechange=function(){if(r.readyState===XMLHttpRequest.DONE)if(r.status===200)try{const v=JSON.parse(r.responseText);ce(v),A=!0,be(),o(v)}catch{o(void 0)}else if(r.status===403){try{JSON.parse(r.responseText).title==="invalid_ssid"&&le()}catch{}o(void 0)}else o(void 0)},r.onerror=function(){o(void 0)},r.send(i)}catch{o(void 0)}})}const ut=async()=>{},P=e=>X(typeof e=="object"?e:typeof e=="function"?e(_e()):_e()),_e=()=>({hostname:j,screen:ve,language:pe,timeZone:Se,timeZoneOffset:we,url:de(rt),referrer:de(it),fbp:H(),cst:T()}),dt=()=>!s||localStorage&&localStorage.getItem("lmetrics.disabled")||M&&!Fe.includes(j),J=new Set,$={},ke=["EMAIL","email_address","emailAddress","email-address","e-mail","Email","email","invitee_email","hemail","he","cemail","payer_email","checkoutemail","customer_email","email-address-lead","email-lead","buyer_email","cf-email","Personal Email Address","Email Address","field-:r3:","Enter your email","maincontent_emailTextBox","donor_email","cus_email","billing_email","user_email","contact_email","login_email","email adresse","wj_lead_email"],Le=["Phone Number","Phone","phone","phone-lead","phone_lead","phone_number","phonenumber","phoneNumber","phone-number","phone_number_lead","phone_number-lead","phone_number_lead","ph","cellPhoneNumber","invitee_phone","phone-1","+44","tel","Applicant.HomePhone","Applicant.MobilePhone","maincontent_primaryPhone","donor_phone","billing_phone","telefon"];function Ce(e,n){let t;return function(...o){t!==void 0&&clearTimeout(t),t=window.setTimeout(()=>{e.apply(this,o)},n)}}const Ie=`${V.replace(/\/$/,"")}/api/v4/events/amend`;function h(e){const n=e.trim().substring(0,255),t=a()||"nosession",o=`${n}_${t}`;n.length<3||$.email===o||!s||($.email=o,Ee(Ie,{eml:fe(n,s)}))}function Ae(e){const n=e.target;n&&n.value&&h(n.value)}function O(e){if(e.type&&e.type.toLowerCase()==="email")return!0;const n=["name","id","placeholder"];for(const t of n){const o=e.getAttribute(t);if(o){for(const i of ke)if(o.toLowerCase()===i.toLowerCase())return!0}}for(const t of n){const o=e.getAttribute(t);if(o&&o.toLowerCase().includes("email"))return!0}return!1}function p(e){const n=e.trim().substring(0,20),t=a()||"nosession",o=`${n}_${t}`;n.length<5||$.phone===o||!s||($.phone=o,Ee(Ie,{phn:fe(n,s)}))}function Pe(e){const n=e.target;n&&n.value&&p(n.value)}function U(e){if(e.type&&e.type.toLowerCase()==="tel")return!0;const n=["name","id","placeholder"];for(const t of n){const o=e.getAttribute(t);if(o){for(const i of Le)if(o.toLowerCase()===i.toLowerCase())return!0}}for(const t of n){const o=e.getAttribute(t);if(o&&o.toLowerCase().includes("phone"))return!0}return!1}function ft(e,n){n.querySelectorAll('input[data-lm-listener="true"]').forEach(o=>{O(o)&&o.value&&h(o.value),U(o)&&o.value&&p(o.value)})}function mt(e){e.querySelectorAll('input[data-lm-listener="true"]').forEach(t=>{O(t)&&t.value&&h(t.value),U(t)&&t.value&&p(t.value)})}function $e(){const e=new URLSearchParams(window.location.search);let n=e.get("email"),t=e.get("phone");!n&&!t&&e.forEach((o,i)=>{const r=i.toLowerCase();ke.includes(r)&&(n=o),Le.includes(r)&&(t=o)}),n&&h(n),t&&p(t)}function z(){if(!ae)return;$e(),document.querySelectorAll("input").forEach(t=>{t.dataset.lmListener!=="true"&&(O(t)?(t.dataset.lmListener="true",J.add(t),t.addEventListener("change",Ae),t.addEventListener("input",Ce(Ae,400)),new MutationObserver(()=>{const i=t.getAttribute("value");i&&h(i)}).observe(t,{attributes:!0,attributeFilter:["value"]}),t.value&&setTimeout(()=>{h(t.value)},500)):U(t)&&(t.dataset.lmListener="true",J.add(t),t.addEventListener("change",Pe),t.addEventListener("input",Ce(Pe,400)),new MutationObserver(()=>{const i=t.getAttribute("value");i&&p(i)}).observe(t,{attributes:!0,attributeFilter:["value"]}),t.value&&setTimeout(()=>{p(t.value)},500)))}),document.querySelectorAll("form").forEach(t=>{if(t.dataset.lmListener==="true")return;t.dataset.lmListener="true",t.addEventListener("submit",i=>{ft(i,t)}),t.querySelectorAll('button[type="submit"], input[type="submit"]').forEach(i=>{i.addEventListener("click",()=>{mt(t)})})})}function ht(){ae&&setInterval(()=>{document.visibilityState!=="hidden"&&document.querySelectorAll("input").forEach(e=>{e.dataset.lmListener==="true"&&(O(e)&&e.value&&h(e.value),U(e)&&e.value&&p(e.value))})},2e3)}const pt=({email:e,phone:n})=>{e&&h(e),n&&p(n)},gt=1500,vt=100;let G=!1;const St=()=>{G=!0};function R(){const e=a();if(e===void 0)return;document.querySelectorAll(`a[href*="${_}"]`).forEach(t=>{t.dataset.lmLnk!=="true"&&(Z(t,e),t.dataset.lmLnk="true")})}function Z(e,n){e.href.includes(_)&&(e.href=e.href.replace(new RegExp(_,"g"),n)),e.dataset.lmLnk="true"}const Oe=e=>{var t,o;const n=(o=(t=e.target)==null?void 0:t.closest)==null?void 0:o.call(t,"a");if(!(!(n instanceof HTMLAnchorElement)||!n.href.includes(_)))return n},wt=(e,n)=>e.target!==""&&e.target!=="_self"||document.querySelector("base[target]")!==null||e.hasAttribute("download")||n.ctrlKey||n.metaKey||n.shiftKey||n.altKey||n.button!==0,bt=()=>new Promise(e=>{const n=Date.now(),t=()=>{const o=a();if(o!==void 0||G||Date.now()-n>=gt){e(o);return}setTimeout(t,vt)};t()});function yt(){document.addEventListener("click",e=>{const n=Oe(e),t=a();n&&t!==void 0&&Z(n,t)},!0),window.addEventListener("click",e=>{const n=Oe(e);!n||G||e.defaultPrevented||wt(n,e)||(e.preventDefault(),bt().then(t=>{t!==void 0&&Z(n,t),window.location.href=n.href}))})}let Q=!1,Ue=!1,Y=F(window.location.href),Re=document.referrer!==window.location.hostname?document.referrer:"",ee=null;const te=300,Et=()=>new URLSearchParams(window.location.search).get("lm_test")===g,Tt=()=>{setTimeout(()=>{alert("LeadMetrics Script is successfully installed!"),window.opener&&(window.opener.postMessage({test:!0},"*"),window.close())},500)},_t=()=>{let e=0;const n=6,t=500,o=()=>{e++;const r=H();if(r&&r.startsWith("fb.")){ye(`${k}/api/v4/events/adcid`,{fbp:r});return}e<n&&setTimeout(o,t)};H()===void 0&&setTimeout(o,t)},kt=()=>{const e=(n,t,o)=>{const i=n[t];return(...r)=>(o.apply(null,r),i.apply(n,r))};history.pushState=e(history,"pushState",Me),history.replaceState=e(history,"replaceState",Me)},Lt=()=>{const e=new MutationObserver(([o])=>{(o==null?void 0:o.target)instanceof HTMLTitleElement&&(o.target.text,void 0)}),n=document.querySelector("head > title");n&&e.observe(n,{subtree:!0,characterData:!0,childList:!0}),new MutationObserver(()=>{ee||(ee=setTimeout(()=>{ee=null,z(),C(),R(),J.forEach(o=>o.value&&o.dispatchEvent(new Event("input",{bubbles:!0})))},te))}).observe(document.body,{subtree:!0,characterData:!0,childList:!0})},Me=(e,n,t)=>{t&&(Re=Y,Y=F(t.toString()),Y!==Re&&(setTimeout(P,te),setTimeout(()=>{z(),C(),R()},te)))},Ct=async()=>{if(!Q){if(Et()){Tt(),Q=!0;return}await P(),_t(),$e(),Q=!0}},It=()=>{const e=()=>{C(),R()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()},De=async()=>{Ue||(C(),z(),ht(),R(),kt(),Lt(),Qe(),await ut(),Ue=!0)},At=`${k}/api/v4/events/conversion`,Pt=50,$t=255,Ot=20,Ve=new Set,Ut=({externalId:e,fields:n}={})=>{if(e!=null&&typeof e!="string")return;const t=(e??"").trim().substring(0,Pt).trim();if(!T()||Ve.has(t))return;Ve.add(t);const o=t?{eid:t}:{};Object.entries(n??{}).forEach(([i,r])=>{Object.keys(o).filter(m=>m.startsWith("f.")).length<Ot&&r!==void 0&&r!==null&&String(r).trim()!==""&&(o[`f.${i}`]=String(r).substring(0,$t))}),ye(At,o)},Rt=e=>{L(e),e&&P()},Mt=()=>{const e=a();if(L(!1),ze(),e&&s){const n=`${k}/api/v4/events/revoke?jrny=${encodeURIComponent(s)}&ss=${encodeURIComponent(e)}`;typeof navigator<"u"&&"sendBeacon"in navigator?navigator.sendBeacon(n):typeof fetch=="function"&&fetch(n,{method:"POST",keepalive:!0}).catch(()=>{})}};(async()=>{if(window.lmetrics||(window.lmetrics={track:P,attribute:pt,conversion:Ut,host:V,website:s,setConsent:L,getConsent:T,apply_consent:Rt,reject_consent:Mt}),Be&&!dt()){yt();try{await Ct()}finally{St()}It(),document.readyState==="complete"?await De():document.addEventListener("readystatechange",async()=>{document.readyState==="complete"&&await De()},!0)}})()})();
