(()=>{(function(){"use strict";let h=document.currentScript||document.querySelector('script[src*="/t.js"]'),a={endpoint:h?.getAttribute("data-endpoint")||"/tapi/events",domain:h?.getAttribute("data-domain")||window.location.hostname,sessionTimeout:30,trackClicks:!0,trackForms:!0,trackScroll:!0,debug:h?.hasAttribute("data-debug"),enableOnLocalhost:h?.hasAttribute("data-enable-localhost")},d={VISITOR:"_sid",SESSION:"_sss",ACTIVITY:"_lts"};if(!a.enableOnLocalhost&&(/^localhost$|^127(\\.([0-9])+){0,2}\\.([0-9])+$|^\\[::1?\\]$/.test(window.location.hostname)||window.location.protocol==="file:"||window!==window.parent))return;let l=null,u=null,s=null,p=null,i={generateId:()=>{let t="0123456789ABCDEFGHJKMNPQRSTVWXYZ",n=Date.now(),e="",o=n;for(let r=9;r>=0;r--)e=t.charAt(o%32)+e,o=Math.floor(o/32);for(let r=0;r<16;r++)e+=t.charAt(Math.floor(Math.random()*32));return e},encode:t=>{try{return btoa(String(t))}catch{return t}},decode:t=>{try{return atob(t)}catch{return t}},setCookie:(t,n,e)=>{let o=new Date;o.setTime(o.getTime()+e*24*60*60*1e3);let r=i.encode(n);document.cookie=`${t}=${r};expires=${o.toUTCString()};path=/`},getCookie:t=>{let n=`${t}=`,e=document.cookie.split(";");for(let o=0;o{let t=document.documentElement,n=document.body,e=Math.max(n.scrollHeight,n.offsetHeight,n.clientHeight,t.scrollHeight,t.offsetHeight,t.clientHeight),o=window.innerHeight||t.clientHeight,r=window.scrollY||t.scrollTop||n.scrollTop;return Math.min(100,Math.round((r+o)/e*100))},isBot:()=>/bot|spider|crawl|lighthouse|pagespeed|pingdom/i.test(navigator.userAgent)||window.navigator.webdriver||window.__nightmare||window._phantom||window.callPhantom||window.phantom||window.__polypane||window._bot||window.Cypress||!("ontouchstart"in window)&&!window.localStorage&&!window.sessionStorage||window.screen&&(window.screen.width===0||window.screen.height===0),debug:(...t)=>{a.debug&&console.log("Analytics:",...t)}},w={send:t=>{i.isBot()||(t.visitor_id=l,t.session_id=u,t.domain=a.domain,t.timestamp=new Date().toISOString(),t.user_agent=navigator.userAgent,fetch(a.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),keepalive:!0}).catch(n=>a.debug&&console.error("Tracking error:",n)),i.debug(t.type+" tracked",t))},sendBeacon:t=>{if(i.isBot()||!navigator.sendBeacon)return!1;t.visitor_id=l,t.session_id=u,t.domain=a.domain,t.timestamp=new Date().toISOString(),t.user_agent=navigator.userAgent;let n=new Blob([JSON.stringify(t)],{type:"application/json"}),e=navigator.sendBeacon(a.endpoint,n);return i.debug("Engagement sent via sendBeacon",t),e}},f={init:()=>{l=i.getCookie(d.VISITOR),l||(l=i.generateId(),i.setCookie(d.VISITOR,l,365)),u=i.getCookie(d.SESSION);let t=i.getCookie(d.ACTIVITY),n=Date.now();(!u||!t||n-parseInt(t,10)>a.sessionTimeout*60*1e3)&&(u=i.generateId(),i.setCookie(d.SESSION,u,1/24)),i.setCookie(d.ACTIVITY,n.toString(),1/24)},updateActivity:()=>{i.setCookie(d.ACTIVITY,Date.now().toString(),1/24)}},c={trackPageview:(t=window.location.href,n=document.referrer)=>{s&&(p=s,c.trackEngagement(p));let e=i.generateId();s={id:e,url:t,path:window.location.pathname,startTime:Date.now(),maxScrollDepth:0};let o=null;try{let r=new URL(t),g={};["utm_source","utm_medium","utm_campaign","utm_term","utm_content"].forEach(m=>{r.searchParams.has(m)&&(g[m]=r.searchParams.get(m))}),Object.keys(g).length&&(o=g)}catch{}return w.send({type:"pageview",page_id:e,url:t,path:window.location.pathname,referrer:n||null,title:document.title,viewport:{width:window.innerWidth||document.documentElement.clientWidth,height:window.innerHeight||document.documentElement.clientHeight},screen:{width:window.screen.width,height:window.screen.height},language:navigator.language,campaign_data:o}),e},trackEngagement:(t,n=!1)=>{if(!t)return;let e=Math.round((Date.now()-t.startTime)/1e3);if(e<1)return;let o={type:"engagement",page_id:t.id,url:t.url,path:t.path,time_on_page:e,scroll_depth:t.maxScrollDepth};n&&navigator.sendBeacon?w.sendBeacon(o):w.send(o)},trackEvent:(t,n={})=>{!t||!s||(t=t.replace(/[^a-z0-9_]/gi,"_").toLowerCase(),w.send({type:"event",page_id:s.id,event:t,url:window.location.href,path:window.location.pathname,props:n}))}};function k(){a.trackScroll&&document.addEventListener("scroll",()=>{if(s){let n=i.getScrollDepth();n>s.maxScrollDepth&&(s.maxScrollDepth=n)}},{passive:!0}),a.trackClicks&&document.addEventListener("click",n=>{let e=n.target.closest("a");if(!e?.href||!(e.hostname!==location.hostname))return;let r={url:e.href,text:e.textContent.trim()};!e.target||e.target==="_self"?e.getAttribute("data-tracking-attached")||(e.setAttribute("data-tracking-attached","true"),n.preventDefault(),c.trackEvent("external_link",r),setTimeout(()=>{window.location.href=e.href},100)):c.trackEvent("external_link",r)}),a.trackForms&&document.addEventListener("submit",n=>{let e=n.target;e?.action&&c.trackEvent("form_submit",{action:e.action,form_id:e.id||null,form_name:e.name||null})}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"?s&&c.trackEngagement(s,!0):document.visibilityState==="visible"&&f.updateActivity()});let t=history.pushState;t&&(history.pushState=function(){t.apply(this,arguments),setTimeout(()=>c.trackPageview(),0)},window.addEventListener("popstate",()=>{setTimeout(()=>c.trackPageview(),0)}))}function v(){f.init(),k(),c.trackPageview(),i.debug("Tracker initialized")}window.sonar={trackEvent:c.trackEvent,trackPageview:c.trackPageview,setDebug:t=>{a.debug=!!t}},i.isBot()||v()})();})();