(function(){"use strict";const s="data-",Re="false",g="true",ee="lm_ssid",te="lm_vid",ne="lm_cst",oe="{{LM_SESS}}",$="__LM_SESS__",re=document.currentScript,c=e=>re.getAttribute(e),Oe=c(s+"auto-track")!==Re,a=c(s+"jrny")??c(s+"id")??void 0,Me=c(s+"host-url")??void 0,Ve=c(s+"exclude-search")===g,U=c(s+"domains")||"",De=U?U.split(",").map(e=>e.trim()):[];c(s+"tag");const ie=c(s+"frm-dtct")??void 0,xe=c(s+"multi-dmn")===g,Be=c(s+"consent")!==g,R=c(s+"isolated")===g,Ne=c(s+"consent-mode")===g,l=R?ee+"_"+a:ee,f=R?te+"_"+a:te,S=R?ne+"_"+a:ne,qe=new URL(re.src),O=Me||qe.origin,M=O.replace(/\/$/,"");let b,w,y={},V="",d=!0;try{const e="lm__str__test__";localStorage.setItem(e,"1"),localStorage.removeItem(e)}catch{d=!1}const ae=e=>{b=e.ssid,w=e.vid,T(e.cst),e.cst&&(D(e.ssid,90),d&&localStorage.setItem(l,e.ssid),x(e.vid,30),d&&sessionStorage.setItem(f,e.vid))};function Fe(e){b=e,_()&&(D(e,90),d&&localStorage.setItem(l,e))}function He(e){w=e,_()&&(x(e,30),d&&localStorage.setItem(f,e))}function T(e){ce(e,90),d&&localStorage.setItem(S,e?"true":"false")}function se(){document.cookie=`${l}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`,d&&localStorage.removeItem(l),E()}function je(){document.cookie=`${l}=; 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(l),localStorage.removeItem(f)),b=void 0,w=void 0,E()}function D(e,n=90){const t=new Date;t.setTime(t.getTime()+n*24*60*60*1e3),document.cookie=`${l}=${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 ce(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(){V="",y={}}const Ke=[l,f,S];function B(){const e=document.cookie;if(e===V)return y;if(V=e,y={},e){const n=e.split("; ");for(const t of n){const[o,r]=t.split("=");o&&Ke.includes(o)&&(y[o]=r)}}return y}function u(){const e=new URLSearchParams(window.location.search).get(l);e&&Fe(e);const t=B()[l];if(t&&t!=="undefined")return t;if(d){const o=localStorage.getItem(l);if(o&&o!=="undefined")return D(o),o}if(b)return b}function We(){const e=new URLSearchParams(window.location.search).get(f);e&&He(e);const t=B()[f];if(t&&t!=="undefined")return t;if(d){const o=localStorage.getItem(f);if(o&&o!=="undefined")return x(o),o}if(w)return w}function _(){const n=B()[S];if(n&&n!=="undefined")return n==="true";if(d){const t=localStorage.getItem(S);if(t&&t!=="undefined")return ce(t==="true"),t==="true"}return Ne?!1:Be}const N=()=>{const e=u();if(e===void 0)return;const n=document.querySelectorAll("input");document.querySelectorAll(`input[value="${oe}"]`).forEach(t=>{t.value=e,t.dispatchEvent(new Event("input",{bubbles:!0}))});for(let t=0;t<n.length;t++)n[t].value.trim()===oe&&(n[t].value=e)};function wt(e){}const q=e=>{try{const{pathname:n,search:t}=new URL(e);e=n+t}catch{}return Ve?e.split("?")[0]:e},le=e=>{if(e){try{const n=decodeURI(e);if(n!==e)return n}catch{return e}return encodeURI(e)}};function Xe(){document.addEventListener("click",e=>{const t=e.target.closest("a");if(!t||!t.href||!xe)return;const o=new URL(t.href);o.hostname!==location.hostname&&(u()&&o.searchParams.set(l,u()),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 Je(e){let n=0;for(let t=0;t<e.length;t++)n=(n+e.charCodeAt(t))%256;return n}function ue(e,n){const t=Je(n);let o="";for(let r=0;r<e.length;r++){const i=e.charCodeAt(r);o+=String.fromCharCode((i+t)%256)}return btoa(o)}function F(){const e=document.cookie.match(/(^|;)\s*_fbp=([^;]+)/);return e?e[2]:void 0}function ze(){return/iP(hone|od|ad)/i.test(navigator.userAgent)}function de(){if(!ze())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 fe(){const e=navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1;return/Mobi|iPhone|Android/i.test(navigator.userAgent)||e}const{navigator:{language:me},screen:{width:Ze,height:Qe}}=window,{referrer:he}=document,H=`${M}/api/v3/events/harvest`,{hostname:j,href:Ge}=location;let Ye=he!==j?he:"",et=q(Ge);const pe=`${Ze}x${Qe}`,ge=Intl.DateTimeFormat().resolvedOptions().timeZone,ve=new Date().getTimezoneOffset(),k=[];let C=u()!==void 0;function Se(){if(!C||k.length===0)return;const e=u();if(e)for(;k.length>0;){const n=k.shift();n&&Date.now()-n.timestamp<3e4&&K(n,e)}}function tt(e,n){C?K({endpoint:e,payload:n,timestamp:Math.floor(new Date().getTime()/1e3)},u()||""):k.push({payload:n,timestamp:Date.now(),endpoint:e})}function be(e,n){const t=u();K({endpoint:e,payload:n,timestamp:Math.floor(new Date().getTime()/1e3)},t)}function K(e,n){if(a===void 0)return;let t=`${e.endpoint}?jrny=${encodeURIComponent(a)}`,o=typeof e.payload=="function"?e.payload(n):e.payload;n!==void 0&&n!==""?t+=`&ss=${encodeURIComponent(n)}`:o={...o,timeZone:ge,timeZoneOffset:ve,screen:pe,language:me};const r=new URLSearchParams(o).toString();typeof navigator<"u"&&"sendBeacon"in navigator&&typeof navigator.sendBeacon=="function"&&!fe()&&!de()&&nt(t,r)||(typeof fetch=="function"?fetch(t,{method:"POST",body:r,headers:{"Content-Type":"application/x-www-form-urlencoded"},keepalive:!0}).then(()=>{}).catch(()=>{we(t,r)}):we(t,r))}function we(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 nt(e,n){try{const t=new Blob([n],{type:"application/x-www-form-urlencoded"});return navigator.sendBeacon(e,t)}catch{return!1}}async function W(e){const n=u(),t=We(),o={...e,vid:t,ts:Math.floor(new Date().getTime()/1e3)},r=Object.fromEntries(Object.entries(o).filter(([p,v])=>v!=null));if(!(typeof navigator<"u"&&"sendBeacon"in navigator&&typeof navigator.sendBeacon=="function"&&!fe()&&!de()&&n&&t&&ot(H,r,n))){if(typeof fetch=="function"){const p=await rt(H,r,n);if(p!==void 0)return p}return it(H,r,n)}}function ot(e,n,t){if(!("sendBeacon"in navigator)||a===void 0)return!1;try{const o=new Blob([new URLSearchParams(n).toString()],{type:"application/x-www-form-urlencoded"}),r=`${e}?jrny=${encodeURIComponent(a)}${t?`&ss=${encodeURIComponent(t)}`:""}`;return navigator.sendBeacon(r,o)}catch{return!1}}async function rt(e,n,t){if(a!==void 0)try{const o=new URLSearchParams(n).toString(),r=await fetch(`${e}?jrny=${encodeURIComponent(a)}${t?`&ss=${encodeURIComponent(t)}`:""}`,{method:"POST",body:o,headers:{"Content-Type":"application/x-www-form-urlencoded"},keepalive:!0});if(r.status===200){const i=await r.json();return ae(i),C=!0,Se(),i}else r.status===403&&(await r.json()).title==="invalid_ssid"&&se()}catch{return}}function it(e,n,t){if(a!==void 0)return new Promise(o=>{try{const r=new URLSearchParams(n).toString(),i=new XMLHttpRequest,p=`${e}?jrny=${encodeURIComponent(a)}${t?`&ss=${encodeURIComponent(t)}`:""}`;i.open("POST",p,!0),i.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),i.onreadystatechange=function(){if(i.readyState===XMLHttpRequest.DONE)if(i.status===200)try{const v=JSON.parse(i.responseText);ae(v),C=!0,Se(),o(v)}catch{o(void 0)}else if(i.status===403){try{JSON.parse(i.responseText).title==="invalid_ssid"&&se()}catch{}o(void 0)}else o(void 0)},i.onerror=function(){o(void 0)},i.send(r)}catch{o(void 0)}})}const at=async()=>{},I=e=>W(typeof e=="object"?e:typeof e=="function"?e(ye()):ye()),ye=()=>({hostname:j,screen:pe,language:me,timeZone:ge,timeZoneOffset:ve,url:le(et),referrer:le(Ye),fbp:F(),cst:_()}),st=()=>!a||localStorage&&localStorage.getItem("lmetrics.disabled")||U&&!De.includes(j),X=new Set,L={},Ee=["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"],Te=["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 _e(e,n){let t;return function(...o){t!==void 0&&clearTimeout(t),t=window.setTimeout(()=>{e.apply(this,o)},n)}}const ke=`${O.replace(/\/$/,"")}/api/v4/events/amend`;function m(e){const n=e.trim().substring(0,255),t=u()||"nosession",o=`${n}_${t}`;n.length<3||L.email===o||!a||(L.email=o,be(ke,{eml:ue(n,a)}))}function Ce(e){const n=e.target;n&&n.value&&m(n.value)}function A(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 r of Ee)if(o.toLowerCase()===r.toLowerCase())return!0}}for(const t of n){const o=e.getAttribute(t);if(o&&o.toLowerCase().includes("email"))return!0}return!1}function h(e){const n=e.trim().substring(0,20),t=u()||"nosession",o=`${n}_${t}`;n.length<5||L.phone===o||!a||(L.phone=o,be(ke,{phn:ue(n,a)}))}function Ie(e){const n=e.target;n&&n.value&&h(n.value)}function P(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 r of Te)if(o.toLowerCase()===r.toLowerCase())return!0}}for(const t of n){const o=e.getAttribute(t);if(o&&o.toLowerCase().includes("phone"))return!0}return!1}function ct(e,n){n.querySelectorAll('input[data-lm-listener="true"]').forEach(o=>{A(o)&&o.value&&m(o.value),P(o)&&o.value&&h(o.value)})}function lt(e){e.querySelectorAll('input[data-lm-listener="true"]').forEach(t=>{A(t)&&t.value&&m(t.value),P(t)&&t.value&&h(t.value)})}function Le(){const e=new URLSearchParams(window.location.search);let n=e.get("email"),t=e.get("phone");!n&&!t&&e.forEach((o,r)=>{const i=r.toLowerCase();Ee.includes(i)&&(n=o),Te.includes(i)&&(t=o)}),n&&m(n),t&&h(t)}function J(){if(!ie)return;Le(),document.querySelectorAll("input").forEach(t=>{t.dataset.lmListener!=="true"&&(A(t)?(t.dataset.lmListener="true",X.add(t),t.addEventListener("change",Ce),t.addEventListener("input",_e(Ce,400)),new MutationObserver(()=>{const r=t.getAttribute("value");r&&m(r)}).observe(t,{attributes:!0,attributeFilter:["value"]}),t.value&&setTimeout(()=>{m(t.value)},500)):P(t)&&(t.dataset.lmListener="true",X.add(t),t.addEventListener("change",Ie),t.addEventListener("input",_e(Ie,400)),new MutationObserver(()=>{const r=t.getAttribute("value");r&&h(r)}).observe(t,{attributes:!0,attributeFilter:["value"]}),t.value&&setTimeout(()=>{h(t.value)},500)))}),document.querySelectorAll("form").forEach(t=>{if(t.dataset.lmListener==="true")return;t.dataset.lmListener="true",t.addEventListener("submit",r=>{ct(r,t)}),t.querySelectorAll('button[type="submit"], input[type="submit"]').forEach(r=>{r.addEventListener("click",()=>{lt(t)})})})}function ut(){ie&&setInterval(()=>{document.visibilityState!=="hidden"&&document.querySelectorAll("input").forEach(e=>{e.dataset.lmListener==="true"&&(A(e)&&e.value&&m(e.value),P(e)&&e.value&&h(e.value))})},2e3)}const dt=({email:e,phone:n})=>{e&&m(e),n&&h(n)};function z(){const e=u();if(e===void 0)return;document.querySelectorAll(`a[href*="${$}"]`).forEach(t=>{t.dataset.lmLnk!=="true"&&(t.href.includes($)&&(t.href=t.href.replace(new RegExp($,"g"),e)),t.dataset.lmLnk="true")})}let Z=!1,Ae=!1,Q=q(window.location.href),Pe=document.referrer!==window.location.hostname?document.referrer:"",G=null;const Y=300,ft=()=>new URLSearchParams(window.location.search).get("lm_test")===g,mt=()=>{setTimeout(()=>{alert("LeadMetrics Script is successfully installed!"),window.opener&&(window.opener.postMessage({test:!0},"*"),window.close())},500)},ht=()=>{let e=0;const n=6,t=500,o=()=>{e++;const i=F();if(i&&i.startsWith("fb.")){tt(`${M}/api/v4/events/adcid`,{fbp:i});return}e<n&&setTimeout(o,t)};F()===void 0&&setTimeout(o,t)},pt=()=>{const e=(n,t,o)=>{const r=n[t];return(...i)=>(o.apply(null,i),r.apply(n,i))};history.pushState=e(history,"pushState",$e),history.replaceState=e(history,"replaceState",$e)},gt=()=>{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(()=>{G||(G=setTimeout(()=>{G=null,J(),N(),z(),X.forEach(o=>o.value&&o.dispatchEvent(new Event("input",{bubbles:!0})))},Y))}).observe(document.body,{subtree:!0,characterData:!0,childList:!0})},$e=(e,n,t)=>{t&&(Pe=Q,Q=q(t.toString()),Q!==Pe&&(setTimeout(I,Y),setTimeout(()=>{J(),N(),z()},Y)))},vt=async()=>{if(!Z){if(ft()){mt(),Z=!0;return}await I(),ht(),Le(),Z=!0}},Ue=async()=>{Ae||(N(),J(),ut(),z(),pt(),gt(),Xe(),await at(),Ae=!0)},St=e=>{T(e),e&&I()},bt=()=>{const e=u();if(T(!1),je(),e&&a){const n=`${M}/api/v4/events/revoke?jrny=${encodeURIComponent(a)}&ss=${encodeURIComponent(e)}`;typeof navigator<"u"&&"sendBeacon"in navigator?navigator.sendBeacon(n):typeof fetch=="function"&&fetch(n,{method:"POST",keepalive:!0}).catch(()=>{})}};(async()=>(window.lmetrics||(window.lmetrics={track:I,attribute:dt,host:O,website:a,setConsent:T,getConsent:_,apply_consent:St,reject_consent:bt}),Oe&&!st()&&(await vt(),document.readyState==="complete"?await Ue():document.addEventListener("readystatechange",async()=>{document.readyState==="complete"&&await Ue()},!0))))()})();
