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