(function(o){typeof define=="function"&&define.amd?define(o):o()})(function(){"use strict";var j=Object.defineProperty;var O=(o,n,c)=>n in o?j(o,n,{enumerable:!0,configurable:!0,writable:!0,value:c}):o[n]=c;var b=(o,n,c)=>(O(o,typeof n!="symbol"?n+"":n,c),c);class o{constructor(){this._debugFlag=!1}static getInstance(){return o._instance||(o._instance=new o),o._instance}setDebug(t){this._debugFlag=t}log(...t){this._debugFlag&&console.log("[LogSnag]",...t)}}const n=o.getInstance(),c="https://api.logsnag.com",g="/v1",l={LOG:c+g+"/log",IDENTIFY:c+g+"/identify",INSIGHT:c+g+"/insight",GROUP:c+"/v1/group",PAGE:c+g+"/page"};class u extends Error{constructor(t,e,s){super(`HTTP Error Response: ${t} ${e}`),this.message=this.createReadableString(s)}createReadableString(t){let e="[LogSnag] Failed to publish: ";return t&&t.validation&&Array.isArray(t.validation.body)?e+=t.validation.body.map(s=>s.message).join(", "):e+=": Please check our docs at https://docs.logsnag.com",e}toString(){return this.message}toJSON(){return{message:this.message}}}function p(r){return Math.abs(Date.now()-r)n.log("track","success")).catch(s=>n.log("track",s))}identify(t){var e;t.user_id||(t.user_id=this.getUserId()),t.user_id!==void 0&&((e=this.client)==null||e.identify(t).then(()=>n.log("identify","success")).catch(s=>n.log("identify",s)))}filterTags(t){return Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0))}getUTMSource(){return new URLSearchParams(window.location.search).get("utm_source")||void 0}trackPageView(){setTimeout(()=>{var s;const t=this.getUserId();if(!t)return;const e={user_id:t,payload:{path:window.location.pathname,title:document.title,user_agent:navigator.userAgent,referrer:document.referrer,utm_source:this.getUTMSource()}};n.log("trackPageView",e),(s=this.client)==null||s.page(e).then(()=>n.log("trackPageView","success")).catch(a=>n.log("trackPageView",a))},500)}trackClickEvent(t){var i;const e=t.dataset.event;if(!e)return;const s={};for(const[d,f]of Object.entries(t.dataset))if(d.startsWith("tag")){const h=k(d).replace("tag-","");s[h]=f}const a={channel:t.dataset.channel||m,event:e,description:t.dataset.description,icon:t.dataset.icon||"👆",user_id:this.getUserId(),tags:this.filterTags(s)};n.log("trackClickEvent",a),(i=this.client)==null||i.track(a).then(()=>n.log("trackClickEvent","success")).catch(d=>n.log("trackClickEvent",d))}trackFormEvent(t){var f;const e=t.dataset.event;if(!e)return;const s={};for(const[h,w]of Object.entries(t.dataset))if(h.startsWith("tag")){const I=k(h).replace("tag-","");s[I]=w}const a=new FormData(t),i={};for(const[h,w]of a.entries())!w||h.toLowerCase().includes("password")||(i[k(h)]=w.toString());const d={channel:t.dataset.channel||m,event:e,description:t.dataset.description,icon:t.dataset.icon||"👆",user_id:this.getUserId(),tags:{...this.filterTags(s),...this.filterTags(i)}};n.log("trackFormEvent",d),(f=this.client)==null||f.track(d).then(()=>n.log("trackFormEvent","success")).catch(h=>n.log("trackFormEvent",h))}listenToPageViews(){window.addEventListener("load",()=>{this.trackPageView()}),window.addEventListener("hashchange",()=>{this.trackPageView()});const t=window.history;if(t.pushState){const e=t.pushState;t.pushState=(...s)=>{e.apply(t,s),this.trackPageView()},window.addEventListener("popstate",()=>{this.trackPageView()})}}listenToClickEvents(){document.addEventListener("click",t=>{let e=t.target;for(;e&&e!==document.body&&!e.matches("[data-event]");)e=e.parentElement;e&&e.matches("[data-event]")&&this.trackClickEvent(e)})}listenToFormEvents(){document.addEventListener("submit",t=>{const e=t.target;e.matches("form")&&e.getAttribute("data-event")&&this.trackFormEvent(e)})}listen(){n.log("listening for events"),this.listenToPageViews(),this.listenToClickEvents(),this.listenToFormEvents()}}function P(){if(window.lsi)return;window.lsi=!0;const r=new E;for(window.ls=(t,...e)=>{typeof r[t]=="function"&&r[t](...e)},window.lsq||(window.lsq=[]);window.lsq.length>0;){const[t,...e]=window.lsq.shift()||[];t&&typeof r[t]=="function"&&r[t](...e)}r.listen()}P()});