const SESS_KEY="seeda_sid",STEP_KEY="seeda_step",CLIENT_KEY="seeda_uid",REF_KEY="seeda_ref",QS_KEY="seeda_qs",ACCOUNT_ID="digitaleagles",API_URL="https://api.seeda.io/events/event";function uuid(){let e=new Uint32Array(8);window.crypto.getRandomValues(e);let t="";for(let n=0;n<e.length;n++)t+=(n<2||n>5?"":"-")+e[n].toString(16).slice(-4);return t}function sessProps(){let e=sessionStorage.getItem(SESS_KEY);e||(e=uuid(),sessionStorage.setItem(SESS_KEY,e));const t=parseInt(sessionStorage.getItem(STEP_KEY));let n=t?t+1:1;return sessionStorage.setItem(STEP_KEY,n),{sessionId:e,step:n}}function clientProps(){let e=localStorage.getItem(CLIENT_KEY);return e||(e=uuid(),localStorage.setItem(CLIENT_KEY,e)),{clientId:e}}function locProps(){const e=window.location.toString().split("?"),t=e.length>1?e[1].split("&").reduce((e,t)=>{const[n,o]=t.split("=");return e[n]=o.replace("+"," "),e},{}):{},n=sessionStorage.getItem(QS_KEY),o=n?JSON.parse(n):{};return qs={...o,...t},sessionStorage.setItem(QS_KEY,JSON.stringify(qs)),{qs:qs}}function seedaPageView(){const{qs:e}=locProps(),{sessionId:t,step:n}=sessProps(),{clientId:o}=clientProps(),s={accountId:ACCOUNT_ID,eventType:"pageView",sessionId:t,step:n,clientId:o,hostName:window.location.hostname,pathName:window.location.pathname,location:window.location,utm_source:e.utm_source,utm_medium:e.utm_medium,utm_campaign:e.utm_campaign,utm_term:e.utm_term,utm_content:e.utm_content,referrer:document.referrer,qs:e};fetch(API_URL,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})}function seedaLink(e,t,n={}){const{qs:o}=locProps(),{sessionId:s,step:i}=sessProps(),{clientId:a}=clientProps(),r={accountId:ACCOUNT_ID,eventType:"click",eventName:e,eventTarget:t,sessionId:s,step:i,clientId:a,hostName:window.location.hostname,pathName:window.location.pathname,location:window.location,utm_source:o.utm_source,utm_medium:o.utm_medium,utm_campaign:o.utm_campaign,utm_term:o.utm_term,utm_content:o.utm_content,referrer:document.referrer,params:n,qs:o};return fetch(API_URL,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),!1}function seedaEvent(e,t={}){const{qs:n}=locProps(),{sessionId:o,step:s}=sessProps(),{clientId:i}=clientProps(),a={accountId:ACCOUNT_ID,eventType:"custom",eventName:e,eventTarget:"",sessionId:o,step:s,clientId:i,hostName:window.location.hostname,pathName:window.location.pathname,location:window.location,utm_source:n.utm_source,utm_medium:n.utm_medium,utm_campaign:n.utm_campaign,utm_term:n.utm_term,utm_content:n.utm_content,referrer:document.referrer,params:t,qs:n};return fetch(API_URL,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),!0}function seedaSetupLinks(){function e(){const e=document.getElementsByTagName("a"),t=`${window.location.protocol}//${window.location.hostname}`;for(let n=0;n<e.length;n++)if(e[n].dataset.seedaEvent){let t=()=>seedaLink(e[n].dataset.seedaEvent,e[n].href);e[n].addEventListener("click",t)}else if(!e[n].href.startsWith(t)){let t=()=>seedaLink("automatic",e[n].href);e[n].addEventListener("click",t)}}"loading"==document.readyState?window.addEventListener("load",e):e()}seedaSetupLinks(),seedaPageView();