diff --git a/scripts/build-tracker.ts b/scripts/build-tracker.ts index 8be4f72..da4d9cc 100644 --- a/scripts/build-tracker.ts +++ b/scripts/build-tracker.ts @@ -13,7 +13,7 @@ vite formats: ['iife'], }, emptyOutDir: false, - outDir: resolve(__dirname, '../dist/src/server/public'), + outDir: resolve(__dirname, '../src/client/public'), }, }) .then((res) => { diff --git a/src/client/public/tracker.js b/src/client/public/tracker.js deleted file mode 100644 index 272d8a0..0000000 --- a/src/client/public/tracker.js +++ /dev/null @@ -1 +0,0 @@ -(function(){"use strict";(h=>{const{screen:{width:K,height:O},navigator:{language:R},location:N,localStorage:S,document:i,history:m}=h,{hostname:A,pathname:U,search:_}=N,{currentScript:g}=i;if(!g)return;const l="data-",C="false",d=g.getAttribute.bind(g),q=d(l+"website-id"),P=d(l+"host-url"),z=d(l+"auto-track")!==C,I=d(l+"do-not-track"),x=d(l+"domains")||"",J=x.split(",").map(t=>t.trim()),M=`${P?P.replace(/\/$/,""):g.src.split("/").slice(0,-1).join("/")}/api/website/send`,B=`${K}x${O}`,F=/data-tianji-event-([\w-_]+)/,E=l+"tianji-event",G=300,D=(t,r,e)=>{const n=t[r];return(...a)=>(e.apply(null,a),n.apply(t,a))},H=t=>{try{return new URL(t).pathname}catch{return t}},p=()=>({website:q,hostname:A,screen:B,language:R,title:L,url:y,referrer:k}),Q=()=>{const{doNotTrack:t,navigator:r,external:e}=h,n="msTrackingProtectionEnabled",a=()=>e&&n in e&&e[n](),c=t||r.doNotTrack||r.msDoNotTrack||a();return c=="1"||c==="yes"},$=()=>S&&S.getItem("tianji.disabled")||I&&Q()||x&&!J.includes(A),j=(t,r,e)=>{e&&(k=y,y=H(e.toString()),y!==k&&setTimeout(b,G))},V=()=>{const t=e=>{const n=e.getAttribute.bind(e),a=n(E);if(a){const c={};return e.getAttributeNames().forEach(s=>{const u=s.match(F);u&&(c[u[1]]=n(s))}),b(a,c)}return Promise.resolve()},r=e=>{const n=(s,u)=>{let o=s;for(let T=0;T{o||(N.href=s)})}else t(a)};i.addEventListener("click",r,!0)},W=()=>{const t=([n])=>{L=n&&n.target?n.target.text:void 0},r=new MutationObserver(t),e=i.querySelector("head > title");e&&r.observe(e,{subtree:!0,characterData:!0,childList:!0})},f=(t,r="event")=>{if($())return;const e={"Content-Type":"application/json"};return typeof v<"u"&&(e["x-tianji-cache"]=v),fetch(M,{method:"POST",body:JSON.stringify({type:r,payload:t}),headers:e}).then(n=>n.text()).then(n=>v=n).catch(()=>{})},b=(t,r)=>f(typeof t=="string"?{...p(),name:t,data:typeof r=="object"?r:void 0}:typeof t=="object"?t:typeof t=="function"?t(p()):p()),X=t=>f({...p(),data:t},"identify");h.tianji||(h.tianji={track:b,identify:X});let y=`${U}${_}`,k=i.referrer,L=i.title,v,w;if(z&&!$()){m.pushState=D(m,"pushState",j),m.replaceState=D(m,"replaceState",j),V(),W();const t=()=>{i.readyState==="complete"&&!w&&(b(),w=!0)};i.addEventListener("readystatechange",t,!0),t()}})(window)})();