!function(){"use strict";if(!document.querySelector(".mf-form-wrapper"))return;const e={};function t(e){const t="mf_session_"+e,n=sessionStorage.getItem(t);if(!n)return 0;try{const e=JSON.parse(n);return Math.floor((Date.now()-e.startTime)/1e3)}catch(o){return 0}}let n=null,o=!1;async function r(e){if("undefined"==typeof metformAnalyticsTracking||!metformAnalyticsTracking.nonce)return;const r=t(e),i=function(){const e=navigator.userAgent.toLowerCase();return/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(e)?"tablet":/Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/i.test(e)?"mobile":"desktop"}(),c=function(){const e=navigator.userAgent.toLowerCase();return e.indexOf("opera")>-1||e.indexOf("opr")>-1?"opera":e.indexOf("edg")>-1?"edge":e.indexOf("firefox")>-1?"firefox":e.indexOf("trident")>-1||e.indexOf("msie")>-1?"ie":e.indexOf("chrome")>-1?"chrome":e.indexOf("safari")>-1?"safari":"other"}(),s=function(){const e=document.referrer;if(!e)return"direct";const t=window.location.hostname,n=new URL(e).hostname;if(n===t)return"direct";const o=["google","bing","yahoo","duckduckgo","baidu","yandex"];for(const e of o)if(n.includes(e))return"organic";return"referral"}(),a=function(){const e=document.referrer;if(!e)return"";try{const t=window.location.hostname;if(new URL(e).hostname===t)return""}catch(t){}return e}(),f=await async function(){if(o)return n;if("undefined"==typeof metformAnalyticsTracking||!metformAnalyticsTracking.countryDetection)return n="",o=!0,n;try{const e=await fetch("https://ipinfo.io/json");if(e.ok){const t=await e.json();n=t.country||""}}catch(e){n=""}return o=!0,n}(),d=JSON.stringify({country:f||"",referrer:a||""});!function(e,t,n){const o=new Date;o.setTime(o.getTime()+24*n*60*60*1e3);const r="expires="+o.toUTCString(),i="https:"===window.location.protocol?";Secure":"";document.cookie=e+"="+t+";"+r+";path=/;SameSite=Lax"+i}("mf_analytics_"+e,encodeURIComponent(d),1),fetch(`${metformAnalyticsTracking.restUrl}/track_view/${e}`,{method:"POST",headers:{"X-WP-Nonce":metformAnalyticsTracking.nonce,"Content-Type":"application/json"},body:JSON.stringify({session_duration:r,device:i,browser:c,source:s,referrer:a,country:f||""})})["catch"]((()=>{}))}function i(e){if("undefined"==typeof metformAnalyticsTracking)return;const t="mf_session_"+e,n=sessionStorage.getItem(t);if(!n)return;const o=JSON.parse(n),r=Math.floor((Date.now()-o.startTime)/1e3)-(o.sentDuration||0);if(r<=0)return;o.sentDuration=(o.sentDuration||0)+r,sessionStorage.setItem(t,JSON.stringify(o));const i=JSON.stringify({session_duration:r,is_update:!0}),c=`${metformAnalyticsTracking.restUrl}/track_view/${e}`;if(navigator.sendBeacon){const e=`${c}?_wpnonce=${metformAnalyticsTracking.nonce}`,t=new Blob([i],{type:"application/json"});navigator.sendBeacon(e,t)}else fetch(c,{method:"POST",headers:{"X-WP-Nonce":metformAnalyticsTracking.nonce,"Content-Type":"application/json"},body:i,keepalive:!0})["catch"]((()=>{}))}function c(){!function(){const t=document.querySelectorAll(".mf-form-wrapper");if(!t.length)return;const n=new IntersectionObserver((t=>{t.forEach((t=>{if(t.isIntersecting){const n=function(e){let t=e.getAttribute("data-form-id");if(t)return t;const n=e.id;if(n){const e=n.match(/metform-wrap-(\d+)/);if(e)return e[1]}return null}(t.target);if(n&&!e[n]){const t={startTime:Date.now(),sentDuration:0};sessionStorage.setItem("mf_session_"+n,JSON.stringify(t)),e[n]=!0,r(n)}}}))}),{root:null,rootMargin:"0px",threshold:.5});t.forEach((e=>n.observe(e)))}(),document.addEventListener("visibilitychange",(()=>{document.hidden&&Object.keys(e).forEach((e=>{i(e)}))})),window.addEventListener("pagehide",(()=>{Object.keys(e).forEach((e=>{i(e)}))}))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",c):c(),window.MetFormAnalytics={trackView:r,getSessionDuration:e=>t(e)}}();