@edgeplus/sdk 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.global.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,13 @@ interface InitOptions {
|
|
|
6
6
|
debug?: boolean;
|
|
7
7
|
}
|
|
8
8
|
declare function init(opts: InitOptions): void;
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* 사용자 정의 이벤트 발행.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { track } from '@edgeplus/sdk';
|
|
14
|
+
* track('signup', { plan: 'pro', source: 'landing' });
|
|
15
|
+
*/
|
|
16
|
+
declare function track(name: string, properties?: Record<string, unknown>): void;
|
|
10
17
|
|
|
11
18
|
export { init, track };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ interface InitOptions {
|
|
|
6
6
|
debug?: boolean;
|
|
7
7
|
}
|
|
8
8
|
declare function init(opts: InitOptions): void;
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* 사용자 정의 이벤트 발행.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { track } from '@edgeplus/sdk';
|
|
14
|
+
* track('signup', { plan: 'pro', source: 'landing' });
|
|
15
|
+
*/
|
|
16
|
+
declare function track(name: string, properties?: Record<string, unknown>): void;
|
|
10
17
|
|
|
11
18
|
export { init, track };
|
package/dist/index.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var EdgePlus=(()=>{var M=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var be=(e,t)=>()=>(e&&(t=e(e=0)),t);var W=(e,t)=>{for(var n in t)M(e,n,{get:t[n],enumerable:!0})},Te=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ee(t))!ye.call(e,r)&&r!==n&&M(e,r,{get:()=>t[r],enumerable:!(i=he(t,r))||i.enumerable});return e};var Se=e=>Te(M({},"__esModule",{value:!0}),e);var ue={};W(ue,{CLSThresholds:()=>H,FCPThresholds:()=>K,FIDThresholds:()=>z,INPThresholds:()=>O,LCPThresholds:()=>V,TTFBThresholds:()=>j,onCLS:()=>we,onFCP:()=>ne,onFID:()=>De,onINP:()=>Fe,onLCP:()=>xe,onTTFB:()=>Me});var B,p,y,ee,C,te,v,J,A,u,h,f,X,b,F,g,G,L,Y,_e,Q,T,K,ne,H,we,re,R,I,Ie,ie,Pe,d,P,oe,Ce,Le,Ae,ae,O,Fe,V,D,xe,j,ke,Me,E,Ne,Z,se,Re,ce,z,De,fe=be(()=>{"use strict";te=-1,v=function(e){addEventListener("pageshow",(function(t){t.persisted&&(te=t.timeStamp,e(t))}),!0)},J=function(){var e=self.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},A=function(){var e=J();return e&&e.activationStart||0},u=function(e,t){var n=J(),i="navigate";return te>=0?i="back-forward-cache":n&&(document.prerendering||A()>0?i="prerender":document.wasDiscarded?i="restore":n.type&&(i=n.type.replace(/_/g,"-"))),{name:e,value:t===void 0?-1:t,rating:"good",delta:0,entries:[],id:"v4-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:i}},h=function(e,t,n){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(r){Promise.resolve().then((function(){t(r.getEntries())}))}));return i.observe(Object.assign({type:e,buffered:!0},n||{})),i}}catch{}},f=function(e,t,n,i){var r,o;return function(a){t.value>=0&&(a||i)&&((o=t.value-(r||0))||r===void 0)&&(r=t.value,t.delta=o,t.rating=(function(c,s){return c>s[1]?"poor":c>s[0]?"needs-improvement":"good"})(t.value,n),e(t))}},X=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},b=function(e){document.addEventListener("visibilitychange",(function(){document.visibilityState==="hidden"&&e()}))},F=function(e){var t=!1;return function(){t||(e(),t=!0)}},g=-1,G=function(){return document.visibilityState!=="hidden"||document.prerendering?1/0:0},L=function(e){document.visibilityState==="hidden"&&g>-1&&(g=e.type==="visibilitychange"?e.timeStamp:0,_e())},Y=function(){addEventListener("visibilitychange",L,!0),addEventListener("prerenderingchange",L,!0)},_e=function(){removeEventListener("visibilitychange",L,!0),removeEventListener("prerenderingchange",L,!0)},Q=function(){return g<0&&(g=G(),Y(),v((function(){setTimeout((function(){g=G(),Y()}),0)}))),{get firstHiddenTime(){return g}}},T=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},K=[1800,3e3],ne=function(e,t){t=t||{},T((function(){var n,i=Q(),r=u("FCP"),o=h("paint",(function(a){a.forEach((function(c){c.name==="first-contentful-paint"&&(o.disconnect(),c.startTime<i.firstHiddenTime&&(r.value=Math.max(c.startTime-A(),0),r.entries.push(c),n(!0)))}))}));o&&(n=f(e,r,K,t.reportAllChanges),v((function(a){r=u("FCP"),n=f(e,r,K,t.reportAllChanges),X((function(){r.value=performance.now()-a.timeStamp,n(!0)}))})))}))},H=[.1,.25],we=function(e,t){t=t||{},ne(F((function(){var n,i=u("CLS",0),r=0,o=[],a=function(s){s.forEach((function(l){if(!l.hadRecentInput){var ve=o[0],ge=o[o.length-1];r&&l.startTime-ge.startTime<1e3&&l.startTime-ve.startTime<5e3?(r+=l.value,o.push(l)):(r=l.value,o=[l])}})),r>i.value&&(i.value=r,i.entries=o,n())},c=h("layout-shift",a);c&&(n=f(e,i,H,t.reportAllChanges),b((function(){a(c.takeRecords()),n(!0)})),v((function(){r=0,i=u("CLS",0),n=f(e,i,H,t.reportAllChanges),X((function(){return n()}))})),setTimeout(n,0))})))},re=0,R=1/0,I=0,Ie=function(e){e.forEach((function(t){t.interactionId&&(R=Math.min(R,t.interactionId),I=Math.max(I,t.interactionId),re=I?(I-R)/7+1:0)}))},ie=function(){return B?re:performance.interactionCount||0},Pe=function(){"interactionCount"in performance||B||(B=h("event",Ie,{type:"event",buffered:!0,durationThreshold:0}))},d=[],P=new Map,oe=0,Ce=function(){var e=Math.min(d.length-1,Math.floor((ie()-oe)/50));return d[e]},Le=[],Ae=function(e){if(Le.forEach((function(r){return r(e)})),e.interactionId||e.entryType==="first-input"){var t=d[d.length-1],n=P.get(e.interactionId);if(n||d.length<10||e.duration>t.latency){if(n)e.duration>n.latency?(n.entries=[e],n.latency=e.duration):e.duration===n.latency&&e.startTime===n.entries[0].startTime&&n.entries.push(e);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};P.set(i.id,i),d.push(i)}d.sort((function(r,o){return o.latency-r.latency})),d.length>10&&d.splice(10).forEach((function(r){return P.delete(r.id)}))}}},ae=function(e){var t=self.requestIdleCallback||self.setTimeout,n=-1;return e=F(e),document.visibilityState==="hidden"?e():(n=t(e),b(e)),n},O=[200,500],Fe=function(e,t){"PerformanceEventTiming"in self&&"interactionId"in PerformanceEventTiming.prototype&&(t=t||{},T((function(){var n;Pe();var i,r=u("INP"),o=function(c){ae((function(){c.forEach(Ae);var s=Ce();s&&s.latency!==r.value&&(r.value=s.latency,r.entries=s.entries,i())}))},a=h("event",o,{durationThreshold:(n=t.durationThreshold)!==null&&n!==void 0?n:40});i=f(e,r,O,t.reportAllChanges),a&&(a.observe({type:"first-input",buffered:!0}),b((function(){o(a.takeRecords()),i(!0)})),v((function(){oe=ie(),d.length=0,P.clear(),r=u("INP"),i=f(e,r,O,t.reportAllChanges)})))})))},V=[2500,4e3],D={},xe=function(e,t){t=t||{},T((function(){var n,i=Q(),r=u("LCP"),o=function(s){t.reportAllChanges||(s=s.slice(-1)),s.forEach((function(l){l.startTime<i.firstHiddenTime&&(r.value=Math.max(l.startTime-A(),0),r.entries=[l],n())}))},a=h("largest-contentful-paint",o);if(a){n=f(e,r,V,t.reportAllChanges);var c=F((function(){D[r.id]||(o(a.takeRecords()),a.disconnect(),D[r.id]=!0,n(!0))}));["keydown","click"].forEach((function(s){addEventListener(s,(function(){return ae(c)}),{once:!0,capture:!0})})),b(c),v((function(s){r=u("LCP"),n=f(e,r,V,t.reportAllChanges),X((function(){r.value=performance.now()-s.timeStamp,D[r.id]=!0,n(!0)}))}))}}))},j=[800,1800],ke=function e(t){document.prerendering?T((function(){return e(t)})):document.readyState!=="complete"?addEventListener("load",(function(){return e(t)}),!0):setTimeout(t,0)},Me=function(e,t){t=t||{};var n=u("TTFB"),i=f(e,n,j,t.reportAllChanges);ke((function(){var r=J();r&&(n.value=Math.max(r.responseStart-A(),0),n.entries=[r],i(!0),v((function(){n=u("TTFB",0),(i=f(e,n,j,t.reportAllChanges))(!0)})))}))},E={passive:!0,capture:!0},Ne=new Date,Z=function(e,t){p||(p=t,y=e,ee=new Date,ce(removeEventListener),se())},se=function(){if(y>=0&&y<ee-Ne){var e={entryType:"first-input",name:p.type,target:p.target,cancelable:p.cancelable,startTime:p.timeStamp,processingStart:p.timeStamp+y};C.forEach((function(t){t(e)})),C=[]}},Re=function(e){if(e.cancelable){var t=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;e.type=="pointerdown"?(function(n,i){var r=function(){Z(n,i),a()},o=function(){a()},a=function(){removeEventListener("pointerup",r,E),removeEventListener("pointercancel",o,E)};addEventListener("pointerup",r,E),addEventListener("pointercancel",o,E)})(t,e):Z(t,e)}},ce=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,Re,E)}))},z=[100,300],De=function(e,t){t=t||{},T((function(){var n,i=Q(),r=u("FID"),o=function(s){s.startTime<i.firstHiddenTime&&(r.value=s.processingStart-s.startTime,r.entries.push(s),n(!0))},a=function(s){s.forEach(o)},c=h("first-input",a);n=f(e,r,z,t.reportAllChanges),c&&(b(F((function(){a(c.takeRecords()),c.disconnect()}))),v((function(){var s;r=u("FID"),n=f(e,r,z,t.reportAllChanges),C=[],y=-1,p=null,ce(addEventListener),s=o,C.push(s),se()})))}))}});var ze={};W(ze,{init:()=>U,track:()=>me});var N="ep_site_";function q(e){let t=()=>{e({type:"page_view",referrer:document.referrer,title:document.title})};t();let n=history.pushState;history.pushState=function(...i){n.apply(this,i),t()},window.addEventListener("popstate",t)}function $(e){window.addEventListener("error",t=>{e({type:"js_error",message:t.message||"Unknown error",stack:(t.error?.stack||"").slice(0,2e3),line:t.lineno||0,column:t.colno||0})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason;e({type:"js_error",message:n?.message||String(n)||"Unhandled rejection",stack:(n?.stack||"").slice(0,2e3),line:0,column:0})})}async function le(e){try{let{onLCP:t,onFID:n,onCLS:i,onINP:r,onTTFB:o}=await Promise.resolve().then(()=>(fe(),ue)),a=c=>{e({type:"web_vital",metric:c.name,value:Math.round(c.value*100)/100,rating:c.rating})};t(a),n(a),i(a),r(a),o(a)}catch{}}var Ke=100,He=5,_=[],x=0,m,S;function Oe(){if(!S){let e=sessionStorage.getItem("ep_session");e?S=e:(S=`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,sessionStorage.setItem("ep_session",S))}return S}function w(e){if(x>=He)return;let t={...e,v:1,ts:e.ts||Date.now(),url:e.url||location.href,session_id:Oe()};_.push(t),m&&_.length>=m.batchSize&&k()}async function k(){if(_.length===0||!m)return;let e=_.splice(0,m.batchSize);try{let t=await fetch(m.endpoint,{method:"POST",headers:{"Content-Type":"application/json","X-Site-Key":m.siteKey},body:JSON.stringify({site_key:m.siteKey,events:e}),keepalive:!0});if(t.status===429){_.unshift(...e),x++;return}if(!t.ok)throw new Error(`HTTP ${t.status}`);x=0}catch{x++;try{let n=[...JSON.parse(sessionStorage.getItem("ep_buffer")||"[]"),...e].slice(-Ke);sessionStorage.setItem("ep_buffer",JSON.stringify(n))}catch{}}}function de(e){m=e,setInterval(k,e.batchIntervalMs)}var Ve="https://collect.edgeplus.pro/api/collect",pe=!1;function U(e){if(pe)return;if(!e.siteKey?.startsWith(N)){console.warn(`[EdgePlus] Invalid siteKey: must start with "${N}"`);return}let t={siteKey:e.siteKey,endpoint:e.endpoint||Ve,batchSize:e.batchSize||10,batchIntervalMs:e.batchIntervalMs||5e3,debug:e.debug||!1};pe=!0,je(),q(w),$(w),le(w),de(t),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&k()}),t.debug&&console.log("[EdgePlus] Initialized:",e.siteKey)}function me(e,t){}function je(){try{let e=sessionStorage.getItem("ep_buffer");if(e){let t=JSON.parse(e);t.length>0&&(t.forEach(n=>w(n)),sessionStorage.removeItem("ep_buffer"))}}catch{}}if(typeof document<"u"){let e=document.currentScript,t=e?.getAttribute("data-site-key");if(t)try{U({siteKey:t,endpoint:e?.getAttribute("data-endpoint")||void 0,debug:e?.hasAttribute("data-debug")||!1})}catch{}}return Se(ze);})();
|
|
1
|
+
"use strict";var EdgePlus=(()=>{var H=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var we=(e,t)=>()=>(e&&(t=e(e=0)),t);var q=(e,t)=>{for(var n in t)H(e,n,{get:t[n],enumerable:!0})},ke=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _e(t))!Se.call(e,r)&&r!==n&&H(e,r,{get:()=>t[r],enumerable:!(i=be(t,r))||i.enumerable});return e};var Ce=e=>ke(H({},"__esModule",{value:!0}),e);var pe={};q(pe,{CLSThresholds:()=>K,FCPThresholds:()=>G,FIDThresholds:()=>W,INPThresholds:()=>V,LCPThresholds:()=>j,TTFBThresholds:()=>Q,onCLS:()=>Ie,onFCP:()=>se,onFID:()=>Xe,onINP:()=>Ne,onLCP:()=>Fe,onTTFB:()=>De});var X,p,b,ie,L,oe,v,z,P,l,y,d,J,_,R,E,te,A,ne,xe,U,S,G,se,K,Ie,ae,O,x,Le,ce,Ae,f,I,ue,Pe,Re,Me,le,V,Ne,j,B,Fe,Q,He,De,T,Oe,re,de,Be,fe,W,Xe,me=we(()=>{"use strict";oe=-1,v=function(e){addEventListener("pageshow",(function(t){t.persisted&&(oe=t.timeStamp,e(t))}),!0)},z=function(){var e=self.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},P=function(){var e=z();return e&&e.activationStart||0},l=function(e,t){var n=z(),i="navigate";return oe>=0?i="back-forward-cache":n&&(document.prerendering||P()>0?i="prerender":document.wasDiscarded?i="restore":n.type&&(i=n.type.replace(/_/g,"-"))),{name:e,value:t===void 0?-1:t,rating:"good",delta:0,entries:[],id:"v4-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:i}},y=function(e,t,n){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(r){Promise.resolve().then((function(){t(r.getEntries())}))}));return i.observe(Object.assign({type:e,buffered:!0},n||{})),i}}catch{}},d=function(e,t,n,i){var r,o;return function(s){t.value>=0&&(s||i)&&((o=t.value-(r||0))||r===void 0)&&(r=t.value,t.delta=o,t.rating=(function(a,c){return a>c[1]?"poor":a>c[0]?"needs-improvement":"good"})(t.value,n),e(t))}},J=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},_=function(e){document.addEventListener("visibilitychange",(function(){document.visibilityState==="hidden"&&e()}))},R=function(e){var t=!1;return function(){t||(e(),t=!0)}},E=-1,te=function(){return document.visibilityState!=="hidden"||document.prerendering?1/0:0},A=function(e){document.visibilityState==="hidden"&&E>-1&&(E=e.type==="visibilitychange"?e.timeStamp:0,xe())},ne=function(){addEventListener("visibilitychange",A,!0),addEventListener("prerenderingchange",A,!0)},xe=function(){removeEventListener("visibilitychange",A,!0),removeEventListener("prerenderingchange",A,!0)},U=function(){return E<0&&(E=te(),ne(),v((function(){setTimeout((function(){E=te(),ne()}),0)}))),{get firstHiddenTime(){return E}}},S=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},G=[1800,3e3],se=function(e,t){t=t||{},S((function(){var n,i=U(),r=l("FCP"),o=y("paint",(function(s){s.forEach((function(a){a.name==="first-contentful-paint"&&(o.disconnect(),a.startTime<i.firstHiddenTime&&(r.value=Math.max(a.startTime-P(),0),r.entries.push(a),n(!0)))}))}));o&&(n=d(e,r,G,t.reportAllChanges),v((function(s){r=l("FCP"),n=d(e,r,G,t.reportAllChanges),J((function(){r.value=performance.now()-s.timeStamp,n(!0)}))})))}))},K=[.1,.25],Ie=function(e,t){t=t||{},se(R((function(){var n,i=l("CLS",0),r=0,o=[],s=function(c){c.forEach((function(u){if(!u.hadRecentInput){var C=o[0],h=o[o.length-1];r&&u.startTime-h.startTime<1e3&&u.startTime-C.startTime<5e3?(r+=u.value,o.push(u)):(r=u.value,o=[u])}})),r>i.value&&(i.value=r,i.entries=o,n())},a=y("layout-shift",s);a&&(n=d(e,i,K,t.reportAllChanges),_((function(){s(a.takeRecords()),n(!0)})),v((function(){r=0,i=l("CLS",0),n=d(e,i,K,t.reportAllChanges),J((function(){return n()}))})),setTimeout(n,0))})))},ae=0,O=1/0,x=0,Le=function(e){e.forEach((function(t){t.interactionId&&(O=Math.min(O,t.interactionId),x=Math.max(x,t.interactionId),ae=x?(x-O)/7+1:0)}))},ce=function(){return X?ae:performance.interactionCount||0},Ae=function(){"interactionCount"in performance||X||(X=y("event",Le,{type:"event",buffered:!0,durationThreshold:0}))},f=[],I=new Map,ue=0,Pe=function(){var e=Math.min(f.length-1,Math.floor((ce()-ue)/50));return f[e]},Re=[],Me=function(e){if(Re.forEach((function(r){return r(e)})),e.interactionId||e.entryType==="first-input"){var t=f[f.length-1],n=I.get(e.interactionId);if(n||f.length<10||e.duration>t.latency){if(n)e.duration>n.latency?(n.entries=[e],n.latency=e.duration):e.duration===n.latency&&e.startTime===n.entries[0].startTime&&n.entries.push(e);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};I.set(i.id,i),f.push(i)}f.sort((function(r,o){return o.latency-r.latency})),f.length>10&&f.splice(10).forEach((function(r){return I.delete(r.id)}))}}},le=function(e){var t=self.requestIdleCallback||self.setTimeout,n=-1;return e=R(e),document.visibilityState==="hidden"?e():(n=t(e),_(e)),n},V=[200,500],Ne=function(e,t){"PerformanceEventTiming"in self&&"interactionId"in PerformanceEventTiming.prototype&&(t=t||{},S((function(){var n;Ae();var i,r=l("INP"),o=function(a){le((function(){a.forEach(Me);var c=Pe();c&&c.latency!==r.value&&(r.value=c.latency,r.entries=c.entries,i())}))},s=y("event",o,{durationThreshold:(n=t.durationThreshold)!==null&&n!==void 0?n:40});i=d(e,r,V,t.reportAllChanges),s&&(s.observe({type:"first-input",buffered:!0}),_((function(){o(s.takeRecords()),i(!0)})),v((function(){ue=ce(),f.length=0,I.clear(),r=l("INP"),i=d(e,r,V,t.reportAllChanges)})))})))},j=[2500,4e3],B={},Fe=function(e,t){t=t||{},S((function(){var n,i=U(),r=l("LCP"),o=function(c){t.reportAllChanges||(c=c.slice(-1)),c.forEach((function(u){u.startTime<i.firstHiddenTime&&(r.value=Math.max(u.startTime-P(),0),r.entries=[u],n())}))},s=y("largest-contentful-paint",o);if(s){n=d(e,r,j,t.reportAllChanges);var a=R((function(){B[r.id]||(o(s.takeRecords()),s.disconnect(),B[r.id]=!0,n(!0))}));["keydown","click"].forEach((function(c){addEventListener(c,(function(){return le(a)}),{once:!0,capture:!0})})),_(a),v((function(c){r=l("LCP"),n=d(e,r,j,t.reportAllChanges),J((function(){r.value=performance.now()-c.timeStamp,B[r.id]=!0,n(!0)}))}))}}))},Q=[800,1800],He=function e(t){document.prerendering?S((function(){return e(t)})):document.readyState!=="complete"?addEventListener("load",(function(){return e(t)}),!0):setTimeout(t,0)},De=function(e,t){t=t||{};var n=l("TTFB"),i=d(e,n,Q,t.reportAllChanges);He((function(){var r=z();r&&(n.value=Math.max(r.responseStart-P(),0),n.entries=[r],i(!0),v((function(){n=l("TTFB",0),(i=d(e,n,Q,t.reportAllChanges))(!0)})))}))},T={passive:!0,capture:!0},Oe=new Date,re=function(e,t){p||(p=t,b=e,ie=new Date,fe(removeEventListener),de())},de=function(){if(b>=0&&b<ie-Oe){var e={entryType:"first-input",name:p.type,target:p.target,cancelable:p.cancelable,startTime:p.timeStamp,processingStart:p.timeStamp+b};L.forEach((function(t){t(e)})),L=[]}},Be=function(e){if(e.cancelable){var t=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;e.type=="pointerdown"?(function(n,i){var r=function(){re(n,i),s()},o=function(){s()},s=function(){removeEventListener("pointerup",r,T),removeEventListener("pointercancel",o,T)};addEventListener("pointerup",r,T),addEventListener("pointercancel",o,T)})(t,e):re(t,e)}},fe=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,Be,T)}))},W=[100,300],Xe=function(e,t){t=t||{},S((function(){var n,i=U(),r=l("FID"),o=function(c){c.startTime<i.firstHiddenTime&&(r.value=c.processingStart-c.startTime,r.entries.push(c),n(!0))},s=function(c){c.forEach(o)},a=y("first-input",s);n=d(e,r,W,t.reportAllChanges),a&&(_(R((function(){s(a.takeRecords()),a.disconnect()}))),v((function(){var c;r=l("FID"),n=d(e,r,W,t.reportAllChanges),L=[],b=-1,p=null,fe(addEventListener),c=o,L.push(c),de()})))}))}});var et={};q(et,{init:()=>Y,track:()=>Te});var D="ep_site_";function Z(e){let t=()=>{e({type:"page_view",referrer:document.referrer,title:document.title})};t();let n=history.pushState;history.pushState=function(...i){n.apply(this,i),t()},window.addEventListener("popstate",t)}function ee(e){window.addEventListener("error",t=>{e({type:"js_error",message:t.message||"Unknown error",stack:(t.error?.stack||"").slice(0,2e3),line:t.lineno||0,column:t.colno||0})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason;e({type:"js_error",message:n?.message||String(n)||"Unhandled rejection",stack:(n?.stack||"").slice(0,2e3),line:0,column:0})})}async function ge(e){try{let{onLCP:t,onFID:n,onCLS:i,onINP:r,onTTFB:o}=await Promise.resolve().then(()=>(me(),pe)),s=a=>{e({type:"web_vital",metric:a.name,value:Math.round(a.value*100)/100,rating:a.rating})};t(s),n(s),i(s),r(s),o(s)}catch{}}var ve='a,button,input,select,textarea,label,summary,[role="button"],[role="link"],[role="tab"],[role="menuitem"],[onclick],[contenteditable="true"]',M=[];function Ge(e){let t=[],n=e,i=0;for(;n&&n!==document.body&&i<4;){let r=n.tagName.toLowerCase();if(n.id){r+=`#${n.id}`,t.unshift(r);break}if(typeof n.className=="string"&&n.className.trim()){let o=n.className.trim().split(/\s+/).slice(0,2).join(".");o&&(r+=`.${o}`)}t.unshift(r),n=n.parentElement,i++}return t.join(">").slice(0,120)}function Ke(e){let t=e.getAttribute("aria-label")||e.getAttribute("title");return t?t.trim().slice(0,60):(e.innerText||e.textContent||"").trim().replace(/\s+/g," ").slice(0,60)}function Ve(e){if(e.tagName==="A")return e.href||void 0;let t=e.closest("a");return t&&t.href||void 0}function je(e){return e.matches(ve)?!0:e.closest(ve)!==null}function Qe(e,t,n){return{selector:Ge(e),tag:e.tagName.toLowerCase(),text:Ke(e),href:Ve(e),x:t,y:n}}function We(e,t,n){return M=M.filter(r=>n-r.ts<1e3),M.filter(r=>{let o=r.x-e,s=r.y-t;return o*o+s*s<=900}).length+1}function he(e){document.addEventListener("click",t=>{let n=t.target;if(!n||n.nodeType!==1)return;let i=n.tagName?.toLowerCase();if(i==="input"||i==="textarea")return;let r=Math.round(t.clientX),o=Math.round(t.clientY),s=Date.now(),a=Qe(n,r,o),c=je(n);e({type:"click",...a});let u=We(r,o,s);M.push({x:r,y:o,ts:s}),u>=3&&e({type:"rage_click",...a,click_count:u,window_ms:1e3}),c||e({type:"dead_click",...a})},!0)}var ze=[25,50,75,100];function Ee(e){let t=new Set,n=!1;function i(){t.clear()}function r(){let a=window.scrollY||document.documentElement.scrollTop,c=window.innerHeight;if(document.documentElement.scrollHeight-c<=0)return;let C=Math.min(100,Math.round((a+c)/document.documentElement.scrollHeight*100));for(let h of ze)!t.has(h)&&C>=h&&(t.add(h),e({type:"scroll_depth",milestone:h,max_depth:C}))}window.addEventListener("scroll",()=>{n||(requestAnimationFrame(()=>{r(),n=!1}),n=!0)},{passive:!0});let o=history.pushState,s=history.replaceState;history.pushState=function(...a){return i(),o.apply(this,a)},history.replaceState=function(...a){return i(),s.apply(this,a)},window.addEventListener("popstate",i),r()}var Ue=100,$e=5,k=[],N=0,m,w;function Ye(){if(!w){let e=sessionStorage.getItem("ep_session");e?w=e:(w=`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,sessionStorage.setItem("ep_session",w))}return w}function g(e){if(N>=$e)return;let t={...e,v:1,ts:e.ts||Date.now(),url:e.url||location.href,session_id:Ye()};k.push(t),m&&k.length>=m.batchSize&&F()}async function F(){if(k.length===0||!m)return;let e=k.splice(0,m.batchSize);try{let t=await fetch(m.endpoint,{method:"POST",headers:{"Content-Type":"application/json","X-Site-Key":m.siteKey},body:JSON.stringify({site_key:m.siteKey,events:e}),keepalive:!0});if(t.status===429){k.unshift(...e),N++;return}if(!t.ok)throw new Error(`HTTP ${t.status}`);N=0}catch{N++;try{let n=[...JSON.parse(sessionStorage.getItem("ep_buffer")||"[]"),...e].slice(-Ue);sessionStorage.setItem("ep_buffer",JSON.stringify(n))}catch{}}}function ye(e){m=e,setInterval(F,e.batchIntervalMs)}var qe="https://collect.edgeplus.pro/api/collect",$=!1;function Y(e){if($)return;if(!e.siteKey?.startsWith(D)){console.warn(`[EdgePlus] Invalid siteKey: must start with "${D}"`);return}let t={siteKey:e.siteKey,endpoint:e.endpoint||qe,batchSize:e.batchSize||10,batchIntervalMs:e.batchIntervalMs||5e3,debug:e.debug||!1};$=!0,Ze(),Z(g),ee(g),ge(g),he(g),Ee(g),ye(t),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&F()}),t.debug&&console.log("[EdgePlus] Initialized:",e.siteKey)}function Te(e,t){if(!$){console.warn("[EdgePlus] track() called before init()");return}if(!e||typeof e!="string"){console.warn("[EdgePlus] track() name must be a non-empty string");return}g({type:"custom",name:e,properties:t||{}})}function Ze(){try{let e=sessionStorage.getItem("ep_buffer");if(e){let t=JSON.parse(e);t.length>0&&(t.forEach(n=>g(n)),sessionStorage.removeItem("ep_buffer"))}}catch{}}if(typeof document<"u"){let e=document.currentScript,t=e?.getAttribute("data-site-key");if(t)try{Y({siteKey:t,endpoint:e?.getAttribute("data-endpoint")||void 0,debug:e?.hasAttribute("data-debug")||!1})}catch{}}return Ce(et);})();
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var P=Object.create;var f=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var F=(e,t)=>{for(var n in t)f(e,n,{get:t[n],enumerable:!0})},T=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of M(t))!D.call(e,r)&&r!==n&&f(e,r,{get:()=>t[r],enumerable:!(i=N(t,r))||i.enumerable});return e};var O=(e,t,n)=>(n=e!=null?P(H(e)):{},T(t||!e||!e.__esModule?f(n,"default",{value:e,enumerable:!0}):n,e)),X=e=>T(f({},"__esModule",{value:!0}),e);var q={};F(q,{init:()=>y,track:()=>L});module.exports=X(q);var v="ep_site_";function k(e){let t=()=>{e({type:"page_view",referrer:document.referrer,title:document.title})};t();let n=history.pushState;history.pushState=function(...i){n.apply(this,i),t()},window.addEventListener("popstate",t)}function w(e){window.addEventListener("error",t=>{e({type:"js_error",message:t.message||"Unknown error",stack:(t.error?.stack||"").slice(0,2e3),line:t.lineno||0,column:t.colno||0})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason;e({type:"js_error",message:n?.message||String(n)||"Unhandled rejection",stack:(n?.stack||"").slice(0,2e3),line:0,column:0})})}async function x(e){try{let{onLCP:t,onFID:n,onCLS:i,onINP:r,onTTFB:s}=await import("web-vitals"),o=c=>{e({type:"web_vital",metric:c.name,value:Math.round(c.value*100)/100,rating:c.rating})};t(o),n(o),i(o),r(o),s(o)}catch{}}var A='a,button,input,select,textarea,label,summary,[role="button"],[role="link"],[role="tab"],[role="menuitem"],[onclick],[contenteditable="true"]',g=[];function G(e){let t=[],n=e,i=0;for(;n&&n!==document.body&&i<4;){let r=n.tagName.toLowerCase();if(n.id){r+=`#${n.id}`,t.unshift(r);break}if(typeof n.className=="string"&&n.className.trim()){let s=n.className.trim().split(/\s+/).slice(0,2).join(".");s&&(r+=`.${s}`)}t.unshift(r),n=n.parentElement,i++}return t.join(">").slice(0,120)}function K(e){let t=e.getAttribute("aria-label")||e.getAttribute("title");return t?t.trim().slice(0,60):(e.innerText||e.textContent||"").trim().replace(/\s+/g," ").slice(0,60)}function B(e){if(e.tagName==="A")return e.href||void 0;let t=e.closest("a");return t&&t.href||void 0}function V(e){return e.matches(A)?!0:e.closest(A)!==null}function Q(e,t,n){return{selector:G(e),tag:e.tagName.toLowerCase(),text:K(e),href:B(e),x:t,y:n}}function W(e,t,n){return g=g.filter(r=>n-r.ts<1e3),g.filter(r=>{let s=r.x-e,o=r.y-t;return s*s+o*o<=900}).length+1}function I(e){document.addEventListener("click",t=>{let n=t.target;if(!n||n.nodeType!==1)return;let i=n.tagName?.toLowerCase();if(i==="input"||i==="textarea")return;let r=Math.round(t.clientX),s=Math.round(t.clientY),o=Date.now(),c=Q(n,r,s),p=V(n);e({type:"click",...c});let _=W(r,s,o);g.push({x:r,y:s,ts:o}),_>=3&&e({type:"rage_click",...c,click_count:_,window_ms:1e3}),p||e({type:"dead_click",...c})},!0)}var j=[25,50,75,100];function R(e){let t=new Set,n=!1;function i(){t.clear()}function r(){let c=window.scrollY||document.documentElement.scrollTop,p=window.innerHeight;if(document.documentElement.scrollHeight-p<=0)return;let S=Math.min(100,Math.round((c+p)/document.documentElement.scrollHeight*100));for(let m of j)!t.has(m)&&S>=m&&(t.add(m),e({type:"scroll_depth",milestone:m,max_depth:S}))}window.addEventListener("scroll",()=>{n||(requestAnimationFrame(()=>{r(),n=!1}),n=!0)},{passive:!0});let s=history.pushState,o=history.replaceState;history.pushState=function(...c){return i(),s.apply(this,c)},history.replaceState=function(...c){return i(),o.apply(this,c)},window.addEventListener("popstate",i),r()}var J=100,U=5,d=[],E=0,a,l;function $(){if(!l){let e=sessionStorage.getItem("ep_session");e?l=e:(l=`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,sessionStorage.setItem("ep_session",l))}return l}function u(e){if(E>=U)return;let t={...e,v:1,ts:e.ts||Date.now(),url:e.url||location.href,session_id:$()};d.push(t),a&&d.length>=a.batchSize&&h()}async function h(){if(d.length===0||!a)return;let e=d.splice(0,a.batchSize);try{let t=await fetch(a.endpoint,{method:"POST",headers:{"Content-Type":"application/json","X-Site-Key":a.siteKey},body:JSON.stringify({site_key:a.siteKey,events:e}),keepalive:!0});if(t.status===429){d.unshift(...e),E++;return}if(!t.ok)throw new Error(`HTTP ${t.status}`);E=0}catch{E++;try{let n=[...JSON.parse(sessionStorage.getItem("ep_buffer")||"[]"),...e].slice(-J);sessionStorage.setItem("ep_buffer",JSON.stringify(n))}catch{}}}function C(e){a=e,setInterval(h,e.batchIntervalMs)}var Y="https://collect.edgeplus.pro/api/collect",b=!1;function y(e){if(b)return;if(!e.siteKey?.startsWith(v)){console.warn(`[EdgePlus] Invalid siteKey: must start with "${v}"`);return}let t={siteKey:e.siteKey,endpoint:e.endpoint||Y,batchSize:e.batchSize||10,batchIntervalMs:e.batchIntervalMs||5e3,debug:e.debug||!1};b=!0,Z(),k(u),w(u),x(u),I(u),R(u),C(t),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&h()}),t.debug&&console.log("[EdgePlus] Initialized:",e.siteKey)}function L(e,t){if(!b){console.warn("[EdgePlus] track() called before init()");return}if(!e||typeof e!="string"){console.warn("[EdgePlus] track() name must be a non-empty string");return}u({type:"custom",name:e,properties:t||{}})}function Z(){try{let e=sessionStorage.getItem("ep_buffer");if(e){let t=JSON.parse(e);t.length>0&&(t.forEach(n=>u(n)),sessionStorage.removeItem("ep_buffer"))}}catch{}}if(typeof document<"u"){let e=document.currentScript,t=e?.getAttribute("data-site-key");if(t)try{y({siteKey:t,endpoint:e?.getAttribute("data-endpoint")||void 0,debug:e?.hasAttribute("data-debug")||!1})}catch{}}0&&(module.exports={init,track});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var _="ep_site_";function y(e){let t=()=>{e({type:"page_view",referrer:document.referrer,title:document.title})};t();let n=history.pushState;history.pushState=function(...i){n.apply(this,i),t()},window.addEventListener("popstate",t)}function S(e){window.addEventListener("error",t=>{e({type:"js_error",message:t.message||"Unknown error",stack:(t.error?.stack||"").slice(0,2e3),line:t.lineno||0,column:t.colno||0})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason;e({type:"js_error",message:n?.message||String(n)||"Unhandled rejection",stack:(n?.stack||"").slice(0,2e3),line:0,column:0})})}async function T(e){try{let{onLCP:t,onFID:n,onCLS:i,onINP:r,onTTFB:s}=await import("web-vitals"),o=c=>{e({type:"web_vital",metric:c.name,value:Math.round(c.value*100)/100,rating:c.rating})};t(o),n(o),i(o),r(o),s(o)}catch{}}var k='a,button,input,select,textarea,label,summary,[role="button"],[role="link"],[role="tab"],[role="menuitem"],[onclick],[contenteditable="true"]',f=[];function R(e){let t=[],n=e,i=0;for(;n&&n!==document.body&&i<4;){let r=n.tagName.toLowerCase();if(n.id){r+=`#${n.id}`,t.unshift(r);break}if(typeof n.className=="string"&&n.className.trim()){let s=n.className.trim().split(/\s+/).slice(0,2).join(".");s&&(r+=`.${s}`)}t.unshift(r),n=n.parentElement,i++}return t.join(">").slice(0,120)}function C(e){let t=e.getAttribute("aria-label")||e.getAttribute("title");return t?t.trim().slice(0,60):(e.innerText||e.textContent||"").trim().replace(/\s+/g," ").slice(0,60)}function L(e){if(e.tagName==="A")return e.href||void 0;let t=e.closest("a");return t&&t.href||void 0}function P(e){return e.matches(k)?!0:e.closest(k)!==null}function N(e,t,n){return{selector:R(e),tag:e.tagName.toLowerCase(),text:C(e),href:L(e),x:t,y:n}}function M(e,t,n){return f=f.filter(r=>n-r.ts<1e3),f.filter(r=>{let s=r.x-e,o=r.y-t;return s*s+o*o<=900}).length+1}function w(e){document.addEventListener("click",t=>{let n=t.target;if(!n||n.nodeType!==1)return;let i=n.tagName?.toLowerCase();if(i==="input"||i==="textarea")return;let r=Math.round(t.clientX),s=Math.round(t.clientY),o=Date.now(),c=N(n,r,s),p=P(n);e({type:"click",...c});let h=M(r,s,o);f.push({x:r,y:s,ts:o}),h>=3&&e({type:"rage_click",...c,click_count:h,window_ms:1e3}),p||e({type:"dead_click",...c})},!0)}var H=[25,50,75,100];function x(e){let t=new Set,n=!1;function i(){t.clear()}function r(){let c=window.scrollY||document.documentElement.scrollTop,p=window.innerHeight;if(document.documentElement.scrollHeight-p<=0)return;let b=Math.min(100,Math.round((c+p)/document.documentElement.scrollHeight*100));for(let m of H)!t.has(m)&&b>=m&&(t.add(m),e({type:"scroll_depth",milestone:m,max_depth:b}))}window.addEventListener("scroll",()=>{n||(requestAnimationFrame(()=>{r(),n=!1}),n=!0)},{passive:!0});let s=history.pushState,o=history.replaceState;history.pushState=function(...c){return i(),s.apply(this,c)},history.replaceState=function(...c){return i(),o.apply(this,c)},window.addEventListener("popstate",i),r()}var F=100,O=5,d=[],g=0,a,l;function X(){if(!l){let e=sessionStorage.getItem("ep_session");e?l=e:(l=`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,sessionStorage.setItem("ep_session",l))}return l}function u(e){if(g>=O)return;let t={...e,v:1,ts:e.ts||Date.now(),url:e.url||location.href,session_id:X()};d.push(t),a&&d.length>=a.batchSize&&E()}async function E(){if(d.length===0||!a)return;let e=d.splice(0,a.batchSize);try{let t=await fetch(a.endpoint,{method:"POST",headers:{"Content-Type":"application/json","X-Site-Key":a.siteKey},body:JSON.stringify({site_key:a.siteKey,events:e}),keepalive:!0});if(t.status===429){d.unshift(...e),g++;return}if(!t.ok)throw new Error(`HTTP ${t.status}`);g=0}catch{g++;try{let n=[...JSON.parse(sessionStorage.getItem("ep_buffer")||"[]"),...e].slice(-F);sessionStorage.setItem("ep_buffer",JSON.stringify(n))}catch{}}}function A(e){a=e,setInterval(E,e.batchIntervalMs)}var G="https://collect.edgeplus.pro/api/collect",v=!1;function I(e){if(v)return;if(!e.siteKey?.startsWith(_)){console.warn(`[EdgePlus] Invalid siteKey: must start with "${_}"`);return}let t={siteKey:e.siteKey,endpoint:e.endpoint||G,batchSize:e.batchSize||10,batchIntervalMs:e.batchIntervalMs||5e3,debug:e.debug||!1};v=!0,B(),y(u),S(u),T(u),w(u),x(u),A(t),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&E()}),t.debug&&console.log("[EdgePlus] Initialized:",e.siteKey)}function K(e,t){if(!v){console.warn("[EdgePlus] track() called before init()");return}if(!e||typeof e!="string"){console.warn("[EdgePlus] track() name must be a non-empty string");return}u({type:"custom",name:e,properties:t||{}})}function B(){try{let e=sessionStorage.getItem("ep_buffer");if(e){let t=JSON.parse(e);t.length>0&&(t.forEach(n=>u(n)),sessionStorage.removeItem("ep_buffer"))}}catch{}}if(typeof document<"u"){let e=document.currentScript,t=e?.getAttribute("data-site-key");if(t)try{I({siteKey:t,endpoint:e?.getAttribute("data-endpoint")||void 0,debug:e?.hasAttribute("data-debug")||!1})}catch{}}export{I as init,K as track};
|