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