Files
o2o-weather/frontend/public/embed/umami.js
T
skkim 11ce52a2d1 fix: umami 스크립트를 날씨각에 복사해 두고 써서 외부 스크립트를 직접 실행하지 않게 — 무결성 확인(SRI) 대신
- analytics.webforai.kr/script.js 를 frontend/public/embed/umami.js 로 복사(2026-11-26), 기록은 data-host-url 로 같은 umami 서버에 보냄
- 날씨각 웹(index.html)과 위젯 카드 모두 복사본을 씀. umami 서버가 다른 사이트의 파일 확인 요청(CORS)을 허락하지 않아 SRI 는 쓸 수 없음
- 복사본은 린트에서 뺌, 운영 문서에 다시 받는 법
2026-11-26 15:32:58 +09:00

5 lines
9.5 KiB
JavaScript

/* umami 방문 통계 스크립트 — https://analytics.webforai.kr/script.js 를 2026-11-26 그대로 복사한 것.
외부 스크립트를 날씨각 페이지에서 직접 실행하지 않으려고(무결성 확인 대신) 날씨각에서 준다. 기록은 data-host-url 의 umami 서버로 간다.
umami 서버를 업그레이드해 기록이 안 되면 같은 주소에서 다시 받아 덮어쓴다(이 주석은 남긴다). 손으로 고치지 않는다. */
!function(){"use strict";function e(e,t=2e3){return e.slice(0,t).replace(/https?:\/\/[^\s)]+/g,e=>{try{const t=e.match(/:\d+:\d+$/)?.[0]||"",n=new URL(t?e.slice(0,-t.length):e);return`${n.origin}${n.pathname}${t}`}catch{return"[url]"}}).replace(/[\w.+-]+@[\w.-]+\.[a-z]{2,}/gi,"[email]").replace(/\beyJ[\w-]+\.[\w-]+\.[\w-]+\b/g,"[token]").replace(/\b(password|secret|token|authorization|api[_-]?key)\s*[:=]\s*[^\s,;]+/gi,"$1=[redacted]").slice(0,t)}function t(t){try{return e(new URL(t,"https://localhost").pathname,500)}catch{return"/"}}function n(t={}){return Object.fromEntries(Object.entries(t).slice(0,20).filter(([e])=>!/password|secret|token|authorization|cookie|email|api.?key/i.test(e)).map(([t,n])=>[e(t,50),e(String(n),200)]))}function a(){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();const e=crypto.getRandomValues(new Uint8Array(16));e[6]=15&e[6]|64,e[8]=63&e[8]|128;const t=Array.from(e,e=>e.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function r(r){const i=new WeakMap,o=[];let s=!1,c=!1,l=0,d=0,f=0;async function u(u,m={},p=!0){try{if(!r.enabled||c||r.disabled()||o.length>=20)return;const h=Date.now();if(h<l)return;const y=Math.floor(h/6e4);if(d!==y&&(d=y,f=0),f>=20)return;if(u&&"object"==typeof u){if(h-(i.get(u)||0)<1e3)return;i.set(u,h)}f++;const g=r.context(),b=r.cache(),v=u&&"object"==typeof u?u:null,w="string"==typeof v?.message?v.message:"string"==typeof u?u:"Non-Error exception",T={version:1,website:g.website,eventId:a(),timestamp:h,name:e("string"==typeof v?.name?v.name:"Error",200)||"Error",message:e(w),stack:e("string"==typeof v?.stack?v.stack:"",16e3),handled:p,url:t(g.url),id:g.id,salt:g.salt,screen:g.screen,language:g.language,release:e(m.release||r.release,100),environment:e(m.environment||r.environment,50),tags:n(m.tags),...m.fingerprint?.length?{fingerprint:m.fingerprint.slice(0,5).map(t=>e(t,200))}:{}};let S;c=!0;try{S=r.beforeSend(T)}finally{c=!1}const k=await S;if(!k||r.disabled())return;o.push({payload:{...k,website:T.website,eventId:T.eventId,timestamp:h,version:1},cache:b}),async function(){if(!s){s=!0;try{for(;o.length;){const e=o.shift();if(!e||r.disabled())continue;const t=JSON.stringify({type:"error",payload:e.payload});if(!((new TextEncoder).encode(t).byteLength>48e3))for(let n=0;n<3&&!r.disabled();n++){try{const n=await fetch(r.endpoint,{method:"POST",keepalive:!0,credentials:"omit",body:t,headers:{"Content-Type":"application/json",...e.cache?{"x-umami-cache":e.cache}:{}}});if(n.ok){const t=await n.json();t.cache&&r.cache()===e.cache&&r.context().id===e.payload.id&&r.updateCache(t.cache);break}if(429===n.status){o.length=0;const e=Number(n.headers.get("Retry-After"))||60;l=Date.now()+1e3*Math.max(1,Math.min(e,300));break}if(n.status<500)break}catch{}n<2&&await new Promise(e=>setTimeout(e,1e3*2**n))}}}finally{s=!1}}}().catch(()=>{})}catch{}}return r.enabled&&(window.addEventListener("error",e=>{e.message&&u(e.error||{name:"Error",message:e.message,stack:e.filename?`at ${e.filename}:${e.lineno}:${e.colno}`:""},{},!1)}),window.addEventListener("unhandledrejection",e=>{u(e.reason,{},!1)})),{captureException:(e,t)=>u(e,t)}}(e=>{const{screen:{width:t,height:n},navigator:{language:a,doNotTrack:i,msDoNotTrack:o},location:s,document:c,history:l,top:d,doNotTrack:f}=e,{currentScript:u,referrer:m}=c,p=e.umamiConfig||{};if(!u&&!p.websiteId)return;const{hostname:h,href:y,origin:g}=s;let b;try{b=y.startsWith("data:")?void 0:e.localStorage}catch{}const v="data-",w="false",T="true",S=u?u.getAttribute.bind(u):()=>null,k=e=>{const t=S(`${v}${e}`);if(null!=t)return t;const n=p[(e=>e.replace(/-([a-z])/g,e=>e[1].toUpperCase()))(e)];return null==n||"function"==typeof n?null:Array.isArray(n)?n.join(","):String(n)},$=()=>{const t=k("before-send"),n=t?e[t]:p.beforeSend;return"function"==typeof n?n:void 0},x=k("website-id"),E=k("host-url"),j=k("distinct-id")||void 0,M=k("tag")||void 0,I=k("salt")||void 0,U=k("salt-rotation"),L=k("auto-track")!==w,O=k("do-not-track")===T,A=k("exclude-search")===T,D=k("exclude-hash")===T,C=k("domains")||"",N=k("fetch-credentials")||"omit",R=k("performance")===T,P=k("auto-pageview")!==w,z=C.split(",").map(e=>e.trim()),_=E||""||(u?u.src.split("/").slice(0,-1).join("/"):"");if(!u&&!_)return;const J=`${_.replace(/\/$/,"")}/api/send`,K=`${t}x${n}`,W=/data-umami-event-([\w-_]+)/,B=`${v}umami-event`,V=300,q=e=>{if(!e)return e;try{const t=new URL(e,s.href);return A&&(t.search=""),D&&(t.hash=""),t.toString()}catch{return e}},F=()=>{if(I)return I;const e={hourly:13,daily:10,weekly:10,monthly:7}[U];if(!e)return;const t=new Date;return"weekly"===U&&t.setUTCDate(t.getUTCDate()-t.getUTCDay()),t.toISOString().slice(0,e)},G=()=>{return{website:x,screen:K,language:a,title:c.title,hostname:h,url:re,referrer:(e=ie,e===g||e?.startsWith(`${g}/`)?e.slice(g.length):e),tag:M,id:ce||void 0,salt:F()};var e},H=(e,t,n)=>{n&&("function"==typeof ae&&ae(),ie=re,re=q(n),re!==ie&&P&&setTimeout(Z,V))},Q=()=>se||!x||b?.getItem("umami.disabled")||"umami.disabled"===e.name&&d!==e||C&&!z.includes(h)||O&&(()=>{const e=f||i||o;return 1===e||"1"===e||"yes"===e})(),X=async(e,t="event")=>{if(Q())return;const n=$();if("function"==typeof n&&(e=await Promise.resolve(n(t,e))),e)try{const n=await fetch(J,{keepalive:!0,method:"POST",body:JSON.stringify({type:t,payload:e}),headers:{"Content-Type":"application/json","x-umami-website-id":x,"x-umami-hostname":h,...void 0!==ne&&{"x-umami-cache":ne}},credentials:N}),a=await n.json();a&&(se=!!a.disabled,ne=a.cache)}catch{}},Y=()=>{oe||(oe=!0,P&&Z(),(()=>{const e=(e,t,n)=>{const a=e[t];return(...t)=>{const r=a.apply(e,t);return n.apply(null,t),r}};l.pushState=e(l,"pushState",H),l.replaceState=e(l,"replaceState",H)})(),(()=>{const e=async e=>{const t=e.getAttribute(B);if(t){const n={};return e.getAttributeNames().forEach(t=>{const a=t.match(W);a&&(n[a[1]]=e.getAttribute(t))}),Z(t,n)}};c.addEventListener("click",t=>{const n=t.target;if(!n||"function"!=typeof n.closest)return;const a=n.closest(`[${B}]`);if(a){if("A"===a.tagName&&a.href){const{href:n,target:r}=a,i="_blank"===r||t.ctrlKey||t.shiftKey||t.metaKey||t.button&&1===t.button;return i||t.preventDefault(),e(a).finally(()=>{i||(("_top"===r?d.location:s).href=n)})}return e(a)}},!0)})(),R&&te())},Z=(e,t)=>X("string"==typeof e?{...G(),name:e,data:t}:"object"==typeof e?{...e}:"function"==typeof e?e(G()):G()),ee=(e,t)=>{const n="string"==typeof e?e:e.id;return void 0!==n&&(ce=n),X({...G(),data:"object"==typeof e?e:t},"identify")},te=()=>{const t={};let n,a=!1,r=!0,i=0,o=0;const s=t=>{try{return e.performance?.getEntriesByType?.(t)||[]}catch{return[]}};let l=(()=>{if(c.prerendering)return 1/0;const e=s("navigation")?.[0],t=e?.activationStart||0,n=s("visibility-state")?.find(e=>"hidden"===e.name&&e.startTime>=t);return n?.startTime??("hidden"===c.visibilityState?0:1/0)})();const d=(e,t)=>{try{new PerformanceObserver(e=>{e.getEntries().forEach(t)}).observe({type:e,buffered:!0})}catch{}};d("navigation",e=>{i=e.activationStart||0,t.ttfb=Math.max(e.responseStart-i,0)}),d("paint",e=>{r&&"first-contentful-paint"===e.name&&e.startTime<l&&(t.fcp=Math.max(e.startTime-i,0))}),d("largest-contentful-paint",e=>{r&&e.startTime<l&&(t.lcp=Math.max(e.startTime-i,0))});let f=0,u=[];d("layout-shift",e=>{if(!e.hadRecentInput){const n=u[u.length-1],a=u[0];n&&e.startTime-n.startTime-n.duration<1e3&&e.startTime-a.startTime<5e3?(f+=e.value,u.push(e)):(f=e.value,u=[e]),f>(t.cls||0)&&(t.cls=f)}});let m,p={};const h=e=>{e.forEach(e=>{if(e.interactionId){const t=p[e.interactionId];(!t||e.duration>t)&&(p[e.interactionId]=e.duration)}})};try{m=new PerformanceObserver(e=>h(e.getEntries())),m.observe({type:"event",buffered:!0,durationThreshold:40})}catch{}const y=()=>{a||((()=>{if(r){if(void 0===t.ttfb){const e=s("navigation")?.[0];e&&(t.ttfb=Math.max(e.responseStart-(e.activationStart||0),0))}if(void 0===t.fcp){const e=s("paint")?.find(e=>"first-contentful-paint"===e.name);e&&e.startTime<l&&(t.fcp=Math.max(e.startTime-i,0))}if(void 0===t.lcp){const e=s("largest-contentful-paint"),n=e?.[e.length-1];n&&n.startTime<l&&(t.lcp=Math.max(n.startTime-i,0))}}})(),(()=>{m&&h(m.takeRecords());const e=Object.values(p).sort((e,t)=>t-e);if(e.length){const n=Math.floor(.02*Math.max(e.length,10));t.inp=e[Math.min(n,e.length-1)]}})(),t.duration=Math.round(performance.now()-o),a=!0,n&&clearTimeout(n),X({...G(),...t},"performance"))};ae=()=>{y(),r=!1,Object.keys(t).forEach(e=>{delete t[e]}),i=0,o=performance.now(),f=0,u=[],p={},a=!1,n&&clearTimeout(n),n=setTimeout(y,1e4)},n=setTimeout(y,1e4);const g=e=>{"hidden"===c.visibilityState&&(l===1/0&&(l=e.timeStamp||performance.now()),y())};c.addEventListener("visibilitychange",g,!0),c.addEventListener("prerenderingchange",g,!0),e.addEventListener("pagehide",y)};let ne,ae,re=q(y),ie=q(m),oe=!1,se=!1,ce=j;if(!e.umami){const t=r({endpoint:J,enabled:k("errors")===T,disabled:()=>!!Q(),context:G,cache:()=>ne,updateCache:e=>{ne=e},release:k("release")||"",environment:k("environment")||"production",beforeSend:async e=>{const t=$();return"function"==typeof t?t("error",e):e}});e.umami={track:Z,identify:ee,getSession:()=>({cache:ne,website:x}),...t}}j&&ee(j),L&&!Q()&&("complete"===c.readyState?Y():c.addEventListener("readystatechange",Y,!0))})(window)}();