function trackGoals(){mida.fetch("/test/goal","POST",{k:window._h_key},e=>{try{var t=JSON.parse(e);t&&t.length&&t.forEach(e=>{var t={goal_id:e.id,goal_type:e.type,goal_value:e.value,test_key:e.key};switch(t.goal_type){case"pageview":case"pageviewExact":case"pageviewWildcard":handlePageviewGoal(t);break;case"scrolling":handleScrollingGoal(t);break;case"duration":handleDurationGoal(t);break;case"clickOnElement":handleClickOnElementGoal(t);break;case"clickOnText":handleClickOnTextGoal(t);break;case"externalLink":handleExternalLinkGoal(t);break;case"formSubmit":handleFormSubmitGoal(t);break;case"revenue":handleRevenueGoal(t)}})}catch(e){console.error("Error in trackGoals:",e)}})}function handleRevenueGoal(e){window._revenueGoals||(window._revenueGoals=[]),window._revenueGoals.push({goal_id:e.goal_id,test_key:e.test_key,goal_value:e.goal_value})}function handlePageviewGoal(e){let t=!1,a=!1,o=!1;try{var n=new URL(e.goal_value.startsWith("http")?e.goal_value:"https://"+e.goal_value),l=new URL(window.location.href);t=removeWww(l.hostname+l.pathname)===removeWww(n.hostname+n.pathname),o=removeWww(l.href)===removeWww(n.href)}catch(e){t=!1,o=!1}a=regexMatchURL(removeProtocol(removeWww(window.location.href)),removeProtocol(removeWww(e.goal_value))),"pageviewExact"===e.goal_type&&(t=!1,a=!1),((t="pageviewWildcard"===e.goal_type?!1:t)||o||a)&&(e.goal_id&&mida.track("goal_"+e.goal_id),mida.converted(e.test_key))}function handleScrollingGoal(e){window._scrollGoals||(window._scrollGoals=[]),window._scrollGoals.push({percentage:Number(e.goal_value),goalId:e.goal_id,testKey:e.test_key,converted:!1}),1===window._scrollGoals.length&&(document.onscroll=()=>{var e=scrollPerc(document.body),t=Math.round(e);window._scrollGoals.forEach(e=>{t>=e.percentage&&!e.converted&&(e.converted=!0,e.goalId&&mida.track("goal_"+e.goalId),mida.converted(e.testKey))})})}function handleDurationGoal(e){var t=e.goal_value;setTimeout(()=>{e.goal_id&&mida.track("goal_"+e.goal_id),mida.converted(e.test_key)},1e3*t)}function handleClickOnElementGoal(c){var i=0,d=!1,u=setInterval(function(){var e,t,a;function o(e){e.target.closest(cleanSel(c.goal_value))&&!t&&(console.log("Global listener triggered for:",c.goal_value),c.goal_id&&mida.track("goal_"+c.goal_id),mida.converted(c.test_key).then(function(){t=!0,document.body.removeEventListener("click",r),document.body.removeEventListener("touchstart",n),document.body.removeEventListener("touchend",l)}))}function n(e){a=!0}function l(e){a&&(a=!1,o(e))}function r(e){a||o(e)}d?clearInterval(u):(0<(e=document.querySelectorAll(cleanSel(c.goal_value))).length&&(e.forEach(function(e){if(!e.dataset.midaTracked){var t=!1,a=!1;function o(){t||(c.goal_id&&mida.track("goal_"+c.goal_id),mida.converted(c.test_key).then(function(){t=!0}))}try{e.addEventListener("touchstart",function(){a=!0}),e.addEventListener("touchend",function(){a&&(a=!1,o())}),e.addEventListener("click",function(){a||o()}),e.dataset.midaTracked="true"}catch(e){console.error("Error attaching event listeners to element:",c.goal_value,e)}}}),d=!0,clearInterval(u)),1e4<=(i+=500)&&!d&&(clearInterval(u),t=!(d=!0),a=!1,document.body.addEventListener("click",r,!0),document.body.addEventListener("touchstart",n,!0),document.body.addEventListener("touchend",l,!0)))},500)}function handleClickOnTextGoal(n){var l=n.goal_value.trim().toLowerCase(),t=0,a=setInterval(function(){var e=document.querySelectorAll("*"),e=Array.from(e).filter(function(e){return e.textContent.trim().toLowerCase()===l});0{document.querySelectorAll(`a[href*="${n.goal_value}"]`).forEach(function(e){let t=!1,a=!1;function o(e){t||(n.goal_id&&mida.track("goal_"+n.goal_id),mida.converted(n.test_key).then(function(){t=!0}))}e.addEventListener("touchstart",function(e){a=!0}),e.addEventListener("touchend",function(e){a&&(a=!1,o())}),e.addEventListener("click",function(e){a||o()})})},500)}function handleFormSubmitGoal(t){setTimeout(()=>{var e=document.querySelector(cleanSel(t.goal_value));e?e.addEventListener("submit",function(e){t.goal_id&&mida.track("goal_"+t.goal_id),mida.converted(t.test_key)}):console.log("form not found "+t.goal_value)},500)}function regexMatchURL(e,t){t="^"+t.replace(/\?/g,"\\?").replace(/\//g,"\\/").replace(/(\*|\%)/g,".*")+"$";t=new RegExp(t);return null!==e.match(t)}function removeWww(e){return"string"==typeof e?e.replace(/\/\/www\./g,"//").replace(/\/$/g,""):e}function removeProtocol(e){return e.replace(/(^\w+:|^)\/\//,"")}function cleanSel(e){return e.replace(/\#[0-9]/,function(e){return e.replace("#","#\\3")}).replace(/\.[0-9]/,function(e){return e.replace(".",".\\3")})}function scrollPerc(e){var t=e.parentNode;return(e.scrollTop||t.scrollTop)/(t.scrollHeight-t.clientHeight)*100}trackGoals();