"use strict";async function sendEvent(o,t,s){const p=/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*:)*?:?0*1$/.test(location.hostname)||location.protocol==="file:";if(!t.trackLocalhost&&p)return console.warn("[UBT] Ignoring event because website is running locally"),!0;try{if(window.localStorage.ubt_ignore==="true")return console.warn('[UBT] Ignoring event because "ubt_ignore" is set to "true" in localStorage'),!0}catch{return null}const i=s?.props??t.props??{};t.userId&&!i?.userId&&(i.userId=t.userId);const c={u:t.url,n:o,i:t.ubtId,d:t.domain,r:t.referrer,w:t.deviceWidth,h:t.hashMode?1:0,p:JSON.stringify(i)};return fetch(`${t.apiHost}/api/event`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)}).then(a=>(s&&s.callback&&s.callback({status:a.status}),!0)).catch(a=>(console.error(a),!0))}function E(o){let t=0;const s=requestAnimationFrame(()=>{t=window.innerWidth,cancelAnimationFrame(s)}),p=()=>{window.ubt=c},i=()=>({hashMode:!1,trackLocalhost:!1,url:location.href,domain:location.hostname,referrer:document.referrer||null,deviceWidth:t,apiHost:"https://ubt.pf.sungrovetech.vn",ubtId:void 0,userId:void 0,props:void 0,...o}),c=(n,r,u)=>sendEvent(n,{...i(),...u},r);p();const a=(n,r)=>{c("pageview",r,n)};return{trackEvent:c,trackPageview:a,enableAutoPageviews:()=>{const n=()=>a(),r=history.pushState;return r&&(history.pushState=function(u,l,d){r.apply(this,[u,l,d]),n()},addEventListener("popstate",n)),o&&o.hashMode&&addEventListener("hashchange",n),a(),function(){r&&(history.pushState=r,removeEventListener("popstate",n)),o&&o.hashMode&&removeEventListener("hashchange",n)}},enableAutoOutboundTracking:(n=document,r={subtree:!0,childList:!0,attributes:!0,attributeFilter:["href"]})=>{function u(e){return typeof process<"u"&&process&&process.env.NODE_ENV==="test"?!0:(e.stopPropagation(),c("Outbound Link: Click",{props:{url:this.href}}))}const l=new Set;function d(e){e instanceof HTMLAnchorElement?e.host!==location.host&&(e.addEventListener("click",u),l.add(e)):"querySelectorAll"in e&&e.querySelectorAll("a").forEach(d)}function b(e){e instanceof HTMLAnchorElement?(e.removeEventListener("click",u),l.delete(e)):"querySelectorAll"in e&&e.querySelectorAll("a").forEach(b)}const f=new MutationObserver(e=>{e.forEach(h=>{h.type==="attributes"?(b(h.target),d(h.target)):h.type==="childList"&&(h.addedNodes.forEach(d),h.removedNodes.forEach(b))})});return n.querySelectorAll("a").forEach(d),f.observe(n,r),function(){l.forEach(e=>{e.removeEventListener("click",u)}),l.clear(),f.disconnect()}}}}(function(){const o=window.document.currentScript,t={trackLocalhost:!0};if(o){const p=o.dataset??{},{ubtId:i,ubtUserId:c,ubtDebug:a,...n}=p;t.ubtId=i,t.apiHost=new URL(o.src).origin,t.userId=c,t.trackLocalhost=a==="true",Object.keys(n).length>0&&(t.props=n)}if(!t.ubtId){console.warn("[UBT] Missing data-ubt-id in script tag");return}const s=E(t);s.enableAutoPageviews(),s.enableAutoOutboundTracking()})();