var __defProp=Object.defineProperty,__defNormalProp=(t,e,a)=>e in t?__defProp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a,__publicField=(t,e,a)=>__defNormalProp(t,"symbol"!=typeof e?e+"":e,a);!function(){"use strict";class t{constructor(t){__publicField(this,"queue",[]),__publicField(this,"timer",null),__publicField(this,"options"),this.options={batchDelay:200,maxBatchSize:100,disableBatch:!1,...t}}add(t,e){this.options.disableBatch?this.options.onSingleSend({type:t,payload:e}).catch((t=>{})):(this.queue.push({type:t,payload:e}),this.queue.length>=(this.options.maxBatchSize||100)?this.flush().catch((t=>{})):this.timer||(this.timer=setTimeout((()=>{this.sendBatch().catch((t=>{}))}),this.options.batchDelay)))}async sendBatch(){if(0===this.queue.length)return;const t=[...this.queue];this.queue=[],this.timer=null,await this.options.onBatchSend(t)}async flush(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.queue.length>0&&await this.sendBatch()}clear(){this.queue=[],this.timer&&(clearTimeout(this.timer),this.timer=null)}updateOptions(t){this.options={...this.options,...t}}getQueueSize(){return this.queue.length}}function e(){if("undefined"==typeof window)return{};const{screen:{width:t,height:e},navigator:{language:a},location:{hostname:i,pathname:n,search:r},document:{title:s,referrer:o}}=window;return{hostname:i,screen:`${t}x${e}`,language:a,title:s,url:`${n}${r}`,referrer:o||void 0}}function a(a){const{serverUrl:i,websiteId:n,batchDelay:r=200,disableBatch:s=!1}=a,o=`${i}/api/website/send`,c=`${i}/api/website/batch`,l=new t({batchDelay:r,disableBatch:s,onBatchSend:async t=>{try{await fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:t})})}catch(e){}},onSingleSend:t=>(async(t,e)=>{try{await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:t,payload:e})})}catch(a){}})(t.type,t.payload)}),h=t=>({website:n,...e(),...t});return{track:(t,e)=>{let a;a="object"==typeof t&&null!==t?t:h(t?{name:t,data:e}:void 0),l.add("event",a)},identify:t=>{const e=h({data:t});l.add("identify",e)},flush:()=>l.flush(),getPayload:h}}(t=>{const{location:e,localStorage:i,document:n,history:r}=t,{hostname:s,pathname:o,search:c}=e,{currentScript:l}=n;if(!l)return;const h="data-",u=l.getAttribute.bind(l),d=u(h+"website-id"),p=u(h+"host-url"),f="false"!==u(h+"auto-track"),m=u(h+"do-not-track"),y=u(h+"domains")||"",b=y.split(",").map((t=>t.trim())),g=p?p.replace(/\/$/,""):l.src.split("/").slice(0,-1).join("/"),w=/data-tianji-event-([\w-_]+)/,S=h+"tianji-event",v=(t,e,a)=>{const i=t[e];return(...e)=>(a.apply(null,e),i.apply(t,e))},_=()=>i&&i.getItem("tianji.disabled")||m&&(()=>{const{doNotTrack:e,navigator:a,external:i}=t,n="msTrackingProtectionEnabled",r=e||a.doNotTrack||a.msDoNotTrack||i&&n in i&&i[n]();return"1"==r||"yes"===r})()||y&&!b.includes(s);if(!d||_())return;const T=a({serverUrl:g,websiteId:d,batchDelay:200,disableBatch:!1});let B=`${o}${c}`,j=n.referrer,k=n.title,q=!1;const N=(t,e)=>{if(_())return;let a,i;"object"==typeof t&&null!==t?(a=t.name,i=t.data):(a=t,i=e);const n=T.getPayload({title:k,url:B,referrer:j,name:a,data:i});T.track(n.name,n.data)},P=t=>{_()||T.identify(t)},$=(t,e,a)=>{a&&(j=B,B=(t=>{try{return new URL(t).pathname}catch(e){return t}})(a.toString()),B!==j&&setTimeout((()=>N()),300))},D=()=>{T.flush()};if(t.tianji||(t.tianji={track:N,identify:P}),f){r.pushState=v(r,"pushState",$),r.replaceState=v(r,"replaceState",$),(()=>{const t=t=>{const e=t.getAttribute.bind(t),a=e(S);if(a){const i={};return t.getAttributeNames().forEach((t=>{const a=t.match(w);a&&(i[a[1]]=e(t))})),N(a,i),!0}return!1};n.addEventListener("click",(a=>{const i=a.target,n="A"===i.tagName?i:((t,e)=>{let a=t;for(let i=0;i{e.href=i}),100))}else t(i)}),!0)})(),(()=>{const t=new MutationObserver((([t])=>{k=t&&t.target?t.target.text:void 0})),e=n.querySelector("head > title");e&&t.observe(e,{subtree:!0,characterData:!0,childList:!0})})(),t.addEventListener("beforeunload",D),t.addEventListener("pagehide",D);const a=()=>{"complete"!==n.readyState||q||(N(),q=!0)};n.addEventListener("readystatechange",a,!0),a()}})(window)}();