(function(Ve){typeof define=="function"&&define.amd?define(Ve):Ve()})(function(){"use strict";const Ve="ASPixel",Jt="ASPixel",Oe="ASPixelStore",wt="AS_USER_PSEUDO_ID",bt="AS_USER_SESSION_ID",Vt="AS_UTM_SOURCE",Gt="AS_UTM_MEDIUM",Zt="AS_UTM_CONTENT",Kt="AS_UTM_CAMPAGIN",zt="AS_SCP",St="AS_AM_ID";function Pe(r,n){try{const s=JSON.stringify(n);sessionStorage.setItem(r,s)}catch(s){console.error("Error storing data in sessionStorage:",s)}}function yt(r){try{const n=sessionStorage.getItem(r);return n?JSON.parse(n):null}catch(n){return console.error("Error retrieving data from sessionStorage:",n),null}}function Wt(){const r=new URLSearchParams(location.search),n=r.get("utm_source"),s=r.get("utm_medium"),h=r.get("utm_content"),w=r.get("utm_campaign"),C=r.get("_sc_p");n&&Pe(Vt,n),s&&Pe(Gt,s),h&&Pe(Zt,h),w&&Pe(Kt,w),C&&Yt(C)}function Yt(r){Pe(zt,r);const n=r.split("*").reduce((s,h)=>{const w=h.split(":");return s={...s,[w[0]]:w[1]},s},{});n.lid&&Pe(St,n.lid)}class er{constructor(n){this.queue=[],this.queueSize=0,this.isProcessing=!1,this.index=0,this.enqueue=async(s,h)=>{const w=JSON.stringify(h).length;this.queueSize+=w,(this.queue.length>=this.options.maxQueueCount||this.queueSize>this.options.maxQueueSize)&&await this.processQueue(),this.queue.push({id:this.index++,name:s,data:h,size:w,timestamp:Date.now()})},this.options=n,this.processQueue=this.processQueue.bind(this),this.activeQueue(),window.addEventListener("pagehide",this.processQueue),setTimeout(()=>{window.addEventListener("beforeunload",this.processQueue)})}async activeQueue(){this.processQueue(),await this.delay(this.options.processInterval),this.activeQueue()}async processQueue(){if(this.isProcessing||this.queue.length===0)return;this.isProcessing=!0;const{queue:n}=this;this.queue=[],this.queueSize=0,await this.sendEvent(n),this.isProcessing=!1}async sendEvent(n){await this.options.handleQueue(n)}delay(n){return new Promise(s=>setTimeout(s,n))}}function tr(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Et={exports:{}},Ge={exports:{}};(function(){var r=[],n=3988292384;function s(){var x,_,D;for(_=0;_<256;_+=1){for(x=_,D=0;D<8;D+=1)x&1?x=n^x>>>1:x=x>>>1;r[_]=x>>>0}}function h(x){return Array.prototype.map.call(x,function(_){return _.charCodeAt(0)})}function w(x){var _=-1,D,L,oe,K;for(D=0,oe=x.length;D>>1^n:K=K>>>1;_=_>>>8^K}return _^-1}function C(x,_){var D,L,oe;if(!((typeof C.crc>"u"||!_||!x)&&(C.crc=-1,!x))){for(D=C.crc,L=0,oe=x.length;L>>8^r[(D^x[L])&255];return C.crc=D,D^-1}}s(),Ge.exports=function(D,_){var D=typeof D=="string"?h(D):D,L=_?w(D):C(D);return(L>>>0).toString(16)},Ge.exports.direct=w,Ge.exports.table=C})();var rr=Ge.exports,Dt={exports:{}},It={exports:{}};(function(){var r=32768,n=0,s=1,h=2,w=9,C=6,x,_,D=null,L,oe,K,Se,ee,te,le,V,ce,re,ue,p,I,g,U,X=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],G=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],de=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,99,99],Ee=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],ge=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],we=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];function Re(){this.next=null,this.list=null}function Le(){this.e=0,this.b=0,this.n=0,this.t=null}function Ie(E,A,b,i,l,m){this.BMAX=16,this.N_MAX=288,this.status=0,this.root=null,this.m=0;var he,j=[],P,$,v,T,c,u,_e,pe=[],J,ne,ve,N=new Le,ae=[],xe=[],H,k=[],ie,W,Y,Z,O;for(O=this.root=null,c=0;c256?E[256]:this.BMAX,J=E,ne=0,c=A;do j[J[ne]]++,ne++;while(--c>0);if(j[0]===A){this.root=null,this.m=0,this.status=0;return}for(u=1;u<=this.BMAX&&j[u]===0;u++);for(_e=u,mc&&(m=c),W=1<0;)k[ie++]=u+=J[ne++];J=E,ne=0,c=0;do(u=J[ne++])!==0&&(xe[k[u]++]=c);while(++c0;){for(;_e>H+pe[1+T];){if(H+=pe[1+T],T++,Y=(Y=v-H)>m?m:Y,($=1<<(u=_e-H))>he+1)for($-=he+1,ie=_e;++uP&&H0&&(k[T]=c,N.b=pe[T],N.e=16+u,N.t=ve,u=(c&(1<>H-pe[T],ae[T-1][u].e=N.e,ae[T-1][u].b=N.b,ae[T-1][u].n=N.n,ae[T-1][u].t=N.t)}for(N.b=_e-H,ne>=A?N.e=99:J[ne]>H;u>=1)c^=u;for(c^=u;(c&(1<>=E,ee-=E}function be(E,A,b){var i,l,m;if(b===0)return 0;for(m=0;;){for(y(p),l=re.list[Q(p)],i=l.e;i>16;){if(i===99)return-1;q(l.b),i-=16,y(i),l=l.t[Q(i)],i=l.e}if(q(l.b),i===16){if(_&=r-1,E[A+m++]=x[_++]=l.n,m===b)return b;continue}if(i===15)break;for(y(i),V=l.n+Q(i),q(i),y(I),l=ue.list[Q(I)],i=l.e;i>16;){if(i===99)return-1;q(l.b),i-=16,y(i),l=l.t[Q(i)],i=l.e}for(q(l.b),y(i),ce=_-l.n-Q(i),q(i);V>0&&m0&&i1)return D=null,console.error("HufBuild error: "+m.status),-1;L=m.root,K=m.m}return re=D,ue=L,p=oe,I=K,be(E,A,b)}function Ne(E,A,b){var i,l,m,he,j,P,$,v,T=[],c;for(i=0;i<286+30;i++)T[i]=0;if(y(5),$=257+Q(5),q(5),y(5),v=1+Q(5),q(5),y(4),P=4+Q(4),q(4),$>286||v>30)return-1;for(l=0;lhe)return-1;for(;l-- >0;)T[i++]=m}else if(l===17){if(y(3),l=3+Q(3),q(3),i+l>he)return-1;for(;l-- >0;)T[i++]=0;m=0}else{if(y(7),l=11+Q(7),q(7),i+l>he)return-1;for(;l-- >0;)T[i++]=0;m=0}if(p=w,c=new Ie(T,$,257,G,de,p),p===0&&(c.status=1),c.status!==0&&c.status!==1)return-1;for(re=c.root,p=c.m,i=0;i257||c.status!==0?-1:be(E,A,b)}function F(){x||(x=[]),_=0,Se=0,ee=0,te=-1,le=!1,V=ce=0,re=null}function qe(E,A,b){var i,l;for(i=0;i0){if(te!==n)for(;V>0&&i0&&i0);return g=null,A}It.exports=$e})();var nr=It.exports,ft={exports:{}};(function(){var r=32768,n=0,s=1,h=2,w=6,C=1024*8,x=2*r,_=3,D=258,L=8192,oe=15,K=L,Se=1<9&&(e=9):e=w,J=e,q=!1,c=!1,be===null){for(Ae=y=Q=null,be=[],F=[],qe=[],$e=[],E=[],N=[],t=0;t>>8):(nt(e&255),nt(e>>>8))}function ot(){l=(l<>7)])&255}function Nt(e,t,f){return e[t].fcre?v-re:le,M=v+D,S=F[f+d-1],fe=F[f+d],R,Ce;$>=ne&&(t>>=2);do if(o=e,!(F[o+d]!==fe||F[o+d-1]!==S||F[o]!==F[f]||F[++o]!==F[f+1])){for(f+=2,o++;fd){if(T=e,d=a,a>=ve)break;S=F[f+d-1],fe=F[f+d]}}while((e=E[e&te])>B&&--t!==0);return d}function pt(){var e,t,f=x-u-v;if(f===-1)f--;else if(v>=r+re){for(e=0;e=r?t-r:le);for(e=0;e=r?t-r:le;f+=r}c||(e=Ut(F,v+u,f),e<=0?c=!0:u+=e)}function Tr(){for(;u!==0&&y===null;){var e;if(ot(),m!==le&&v-m<=re&&(P=Ft(m),P>u&&(P=u)),P>=_)if(e=Je(v-T,P-_),u-=P,P<=pe){P--;do v++,ot();while(--P!==0);v++}else v+=P,P=0,l=F[v]&255,l=(l<u&&(P=u),P===_&&v-T>V&&P--),$>=_&&P<=$){var e;e=Je(v-1-he,$-_),u-=$-1,$-=2;do v++,ot();while(--$!==0);j=!1,P=_-1,v++,e&&(st(0),i=v)}else j?(Je(0,F[v-1]&255)&&(st(0),i=v),v++,u--):(j=!0,v++,u--);for(;uy.len&&(a=y.len),d=0;dse-z&&(a=se-z),d=0;d>=7;od&&(R=d,at++),t[S].dl=R,!(S>a)&&(Z[R]++,Ce=0,S>=o&&(Ce=f[S-o]),gt=t[S].fc,Fe+=gt*(R+Ce),B!==null&&(et+=gt*(B[S].dl+Ce)));if(at!==0){do{for(R=d-1;Z[R]===0;)R--;Z[R]--,Z[R+1]+=2,Z[d]--,at-=2}while(at>0);for(R=d;R!==0;R--)for(S=Z[R];S!==0;)fe=O[--M],!(fe>a)&&(t[fe].dl!==R&&(Fe+=(R-t[fe].dl)*t[fe].fc,t[fe].fc=R),S--)}}function $t(e,t){var f=[],o=0,a,d;for(a=1;a<=p;a++)o=o+Z[a-1]<<1,f[a]=o;for(d=0;d<=t;d++){var B=e[d].dl;B!==0&&(e[d].fc=Ht(f[B]++,B))}}function xt(e){var t=e.dyn_tree,f=e.static_tree,o=e.elems,a,d,B=-1,M=o;for(Te=0,Ue=Le,a=0;a>1;a>=1;a--)vt(t,a);do a=O[ue],O[ue]=O[Te--],vt(t,ue),d=O[ue],O[--Ue]=a,O[--Ue]=d,t[M].fc=t[a].fc+t[d].fc,ye[a]>ye[d]+1?ye[M]=ye[a]:ye[M]=ye[d]+1,t[a].dl=t[d].dl=M,O[ue]=M++,vt(t,ue);while(Te>=2);O[--Ue]=O[ue],Or(e),$t(t,B)}function kt(e,t){var f,o=-1,a,d=e[0].dl,B=0,M=7,S=4;for(d===0&&(M=138,S=3),e[t+1].dl=65535,f=0;f<=t;f++)a=d,d=e[f+1].dl,!(++B=3&&k[Ct[e]].dl===0;e--);return Fe+=3*(e+1)+5+5+4,e}function Nr(e,t,f){var o;for(me(e-257,5),me(t-1,5),me(f-4,4),o=0;o>3,f=et+3+7>>3,f<=t&&(t=f),a+4<=t&&i>=0)for(me((n<<1)+e,3),jt(),it(a),it(~a),d=0;d2&&!(Be&4095)){var f=Be*8,o=v-i,a;for(a=0;a>=3,We>=1;while(amt-t?(A|=e<>mt-b,b+=t-mt):(A|=e<>=1,f<<=1;while(--t>0);return f>>1}function jt(){b>8?it(A):b>0&&nt(A),A=0,b=0}function Ur(){var e,t;if(se!==0){for(e=Ir(),y===null?y=Q=e:Q=Q.next=e,e.len=se-z,t=0;t"u"&&(t=w),Er(t),o=[];do f=Cr(o,o.length,1024);while(f>0);return tt=null,o}ft.exports=Fr,ft.exports.DEFAULT_LEVEL=w})();var ir=ft.exports;(function(){Dt.exports={inflate:nr,deflate:ir}})();var or=Dt.exports;(function(){var r=rr,n=or,s=31,h=139,w={deflate:8},C={FTEXT:1,FHCRC:2,FEXTRA:4,FNAME:8,FCOMMENT:16},x={fat:0,amiga:1,vmz:2,unix:3,"vm/cms":4,atari:5,hpfs:6,macintosh:7,"z-system":8,cplm:9,"tops-20":10,ntfs:11,qdos:12,acorn:13,vfat:14,vms:15,beos:16,tandem:17,theos:18},_="unix",D=6;function L(p,I){I.push(p&255)}function oe(p,I){I.push(p&255),I.push(p>>>8)}function K(p,I){oe(p&65535,I),oe(p>>>16,I)}function Se(p,I){var g,U=p.length;for(g=0;g32768?(g-=32768,(g<<16|I)+32768*Math.pow(2,16)):g<<16|I}function V(p){for(var I=[];p[0]!==0;)I.push(String.fromCharCode(p.shift()));return p.shift(),I.join("")}function ce(p,I){var g,U=[];for(g=0;g{n.searchParams.set(h,w)}),n.toString()}async report(n){let s;return typeof window.navigator?.sendBeacon=="function"?s=this.reportBySendBeacon:s=this.reportByXHR,await s.call(this,n)}async reportBySendBeacon(n){const s=this.ReqUrl,h=this.compressData(n);let w=!1;try{w=navigator.sendBeacon(s,h)}catch{return await this.reportByXHR(n)}return w?Promise.resolve(!0):Promise.reject(new Error("sendBeacon failed"))}async reportByXHR(n){const s=new window.XMLHttpRequest,h=this.compressData(n);return s.withCredentials=!1,s.open("POST",this.ReqUrl),s.send(h),new Promise((w,C)=>{s.onload=()=>w(!0),s.onerror=x=>C(x)})}compressData(n){const s=JSON.stringify(n),w=new TextEncoder().encode(s),C=ar.zip(w,{level:9});return new Blob([new Uint8Array(C)],{type:"text/plain"})}}function lr(r){return new URL(window.location.href).searchParams.get(r)}const At={success:({title:r,description:n,details:s})=>{const h=["%c%s%c%s","background: #ff6b2b; color: white; border-radius: 5px; padding: 2px 5px; margin-right: 5px; margin-bottom: 5px;",r,"color: unset!important;"," "+n];s?(console.groupCollapsed(...h),s&&console.log(JSON.stringify(s,null,2)),console.groupEnd()):console.log(...h)}};function Tt(){return new Promise((r,n)=>{const s=indexedDB.open(Jt,1);s.onupgradeneeded=h=>{const w=h.target?.result;w.objectStoreNames.contains(Oe)||w.createObjectStore(Oe)},s.onsuccess=h=>{r(h.target.result)},s.onerror=h=>{n(new Error("IndexedDB error: "+h.target?.error))}})}async function cr(r,n){if(typeof indexedDB>"u")return new Promise((h,w)=>{w(new Error("IndexedDB is not supported"))});const s=await Tt();return new Promise((h,w)=>{const _=s.transaction([Oe],"readwrite").objectStore(Oe).put(n,r);_.onsuccess=()=>h(),_.onerror=D=>w(new Error("IndexedDB error: "+D.target?.error))})}async function ur(r){if(typeof indexedDB>"u")return new Promise((s,h)=>{h(new Error("IndexedDB is not supported"))});const n=await Tt();return new Promise((s,h)=>{const x=n.transaction([Oe],"readonly").objectStore(Oe).get(r);x.onsuccess=_=>s(_.target.result),x.onerror=_=>h(new Error("IndexedDB error: "+_.target?.error))})}async function Bt(r,n){const s=JSON.stringify(n);try{localStorage.setItem(r,s)}catch{console.warn("localStorage limit exceeded")}await cr(r,n)}async function dr(r){const n=localStorage.getItem(r);try{if(n!==null)return JSON.parse(n);const s=await ur(r);return s!==void 0?s:null}catch{return null}}function hr(r){const n=localStorage.getItem(r);try{return n!==null?JSON.parse(n):null}catch{return null}}class _r{constructor(){this.enabled=!1,this.success=this.decorator(At.success);const n=lr("aftership_pixel_debug"),s=hr("aftership_pixel_debug"),h=n?n==="1":!!s;this.enabled=h,this.enabled&&this.logDebug()}setStatus(n){this.enabled=n??!this.enabled,Bt("aftership_pixel_debug",this.enabled),this.logDebug()}decorator(n){return(...s)=>{this.enabled&&n.call(this,...s)}}logDebug(){At.success({title:"AfterShip Pixel Debug mode",description:this.enabled?"Current is debug mode":"Current is not debug mode"})}}function pr(){let r=new Date().getTime(),n=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(s){let h=Math.random()*16;return r>0?(h=(r+h)%16|0,r=Math.floor(r/16)):(h=(n+h)%16|0,n=Math.floor(n/16)),(s==="x"?h:h&3|8).toString(16)})}function Mt(){let r="";try{r=URL.createObjectURL(new Blob)}catch{}const n=r.toString();try{URL.revokeObjectURL(r)}catch{}const s=n.split(/[:/]/g).pop();return s?s.toLowerCase():pr()}async function vr(){const r=await xr(),n=mr(),s=yt(St);return{$user_pseudo_id:r,$session_id:n,$am_id:s}}async function xr(){let r=await dr(wt);return r||(r=Mt(),await Bt(wt,r)),r}function mr(){let r=yt(bt);return r||(r=Mt(),Pe(bt,r)),r}const lt=r=>r==null;function Ze(r){return Array.isArray(r)?r.map(Ze).filter(n=>!lt(n)):typeof r=="object"&&!lt(r)?Object.fromEntries(Object.entries(r).map(([n,s])=>[n,Ze(s)]).filter(([,n])=>!lt(n))):r}class gr{constructor(){this.formatEventData=(n,...s)=>{const[h]=s,{customer_id:w,...C}=h??{};return{$event_name:n,$event_timestamp:Date.now(),$user_properties:{...this.state.userProperties,customer_id:w},$lib_version:this.state.$lib_version,$params:{page_location:window.location.href,page_title:document.title,page_referrer:document.referrer,...C}}},this.track=async(n,...s)=>{await this.waitInit(),await this.eventQueue.enqueue(n,this.formatEventData(n,...s))},this.events={clicked:this.eventFactory("$clicked"),pageViewed:this.eventFactory("$page_viewed"),modalViewed:this.eventFactory("$modal_viewed"),submitted:this.eventFactory("$submitted"),purchaseCompleted:this.eventFactory("$purchase_completed"),itemClicked:this.eventFactory("$item_clicked"),itemViewed:this.eventFactory("$item_viewed"),refundCompleted:this.eventFactory("$refund_completed"),searchSubmitted:this.eventFactory("$search_submitted"),addedToCart:this.eventFactory("$added_to_cart"),checkoutStarted:this.eventFactory("$checkout_started"),cartViewed:this.eventFactory("$cart_viewed"),promotionViewed:this.eventFactory("$promotion_viewed"),promotionEngaged:this.eventFactory("$promotion_engaged"),accountRegistered:this.eventFactory("$account_registered"),subscribed:this.eventFactory("$subscribed")},this.state={hasInit:!1,pixel_id:"",$lib_version:"",userProperties:{customer_id:"",$user_pseudo_id:"",$am_id:"",$session_id:""}},this.eventQueue=new er({maxQueueCount:10,maxQueueSize:16e3,processInterval:1250,handleQueue:this.processQueue.bind(this)}),this.reporter=new fr({endpoint:"https://api.aftership-pixel.com/analytics/v1/collect",commonQueryParams:this.getCommonQueryParams.bind(this)}),this.logger=new _r}getCommonQueryParams(){return{pixel_id:this.state.pixel_id}}async init(n){Wt();const s=await vr();this.state={...this.state,userProperties:s,...n,hasInit:!0}}debug(n){this.logger.setStatus(n)}formatEventPayload(n){const s=n.map(h=>h.data);return Ze({events:s})}async waitInit(){return new Promise(n=>{if(this.state.hasInit)n(!0);else{const s=setInterval(()=>{this.state.hasInit&&(n(!0),clearInterval(s))},10)}})}async processQueue(n){const s=this.formatEventPayload(n);if(s){if(this.logger.enabled){n.forEach(h=>{this.logger.success({title:`AfterShip Pixel [ID: ${h.id}]`,description:`Event: ${h.name}`,details:Ze(h.data)})});return}await this.reporter.report(s)}}eventFactory(n){return(...s)=>{this.track(n,...s)}}}class wr extends gr{constructor(){super(),this.state.$lib_version="web@0.1.4"}}const br=new wr;(function(){window[Ve]=br})()});