@edgeplus/sdk 0.0.2 → 0.0.4
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.global.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
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.io/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 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);})();
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var I=Object.create;var l=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var n in t)l(e,n,{get:t[n],enumerable:!0})},E=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of P(t))!k.call(e,i)&&i!==n&&l(e,i,{get:()=>t[i],enumerable:!(s=T(t,i))||s.enumerable});return e};var F=(e,t,n)=>(n=e!=null?I(x(e)):{},E(t||!e||!e.__esModule?l(n,"default",{value:e,enumerable:!0}):n,e)),K=e=>E(l({},"__esModule",{value:!0}),e);var V={};A(V,{init:()=>m,track:()=>S});module.exports=K(V);var f="ep_site_";function v(e){let t=()=>{e({type:"page_view",referrer:document.referrer,title:document.title})};t();let n=history.pushState;history.pushState=function(...s){n.apply(this,s),t()},window.addEventListener("popstate",t)}function b(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 _(e){try{let{onLCP:t,onFID:n,onCLS:s,onINP:i,onTTFB:w}=await import("web-vitals"),o=g=>{e({type:"web_vital",metric:g.name,value:Math.round(g.value*100)/100,rating:g.rating})};t(o),n(o),s(o),i(o),w(o)}catch{}}var N=100,L=5,c=[],p=0,r,a;function R(){if(!a){let e=sessionStorage.getItem("ep_session");e?a=e:(a=`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,sessionStorage.setItem("ep_session",a))}return a}function u(e){if(p>=L)return;let t={...e,v:1,ts:e.ts||Date.now(),url:e.url||location.href,session_id:R()};c.push(t),r&&c.length>=r.batchSize&&d()}async function d(){if(c.length===0||!r)return;let e=c.splice(0,r.batchSize);try{let t=await fetch(r.endpoint,{method:"POST",headers:{"Content-Type":"application/json","X-Site-Key":r.siteKey},body:JSON.stringify({site_key:r.siteKey,events:e}),keepalive:!0});if(t.status===429){c.unshift(...e),p++;return}if(!t.ok)throw new Error(`HTTP ${t.status}`);p=0}catch{p++;try{let n=[...JSON.parse(sessionStorage.getItem("ep_buffer")||"[]"),...e].slice(-N);sessionStorage.setItem("ep_buffer",JSON.stringify(n))}catch{}}}function y(e){r=e,setInterval(d,e.batchIntervalMs)}var C="https://collect.edgeplus.
|
|
1
|
+
"use strict";var I=Object.create;var l=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var n in t)l(e,n,{get:t[n],enumerable:!0})},E=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of P(t))!k.call(e,i)&&i!==n&&l(e,i,{get:()=>t[i],enumerable:!(s=T(t,i))||s.enumerable});return e};var F=(e,t,n)=>(n=e!=null?I(x(e)):{},E(t||!e||!e.__esModule?l(n,"default",{value:e,enumerable:!0}):n,e)),K=e=>E(l({},"__esModule",{value:!0}),e);var V={};A(V,{init:()=>m,track:()=>S});module.exports=K(V);var f="ep_site_";function v(e){let t=()=>{e({type:"page_view",referrer:document.referrer,title:document.title})};t();let n=history.pushState;history.pushState=function(...s){n.apply(this,s),t()},window.addEventListener("popstate",t)}function b(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 _(e){try{let{onLCP:t,onFID:n,onCLS:s,onINP:i,onTTFB:w}=await import("web-vitals"),o=g=>{e({type:"web_vital",metric:g.name,value:Math.round(g.value*100)/100,rating:g.rating})};t(o),n(o),s(o),i(o),w(o)}catch{}}var N=100,L=5,c=[],p=0,r,a;function R(){if(!a){let e=sessionStorage.getItem("ep_session");e?a=e:(a=`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,sessionStorage.setItem("ep_session",a))}return a}function u(e){if(p>=L)return;let t={...e,v:1,ts:e.ts||Date.now(),url:e.url||location.href,session_id:R()};c.push(t),r&&c.length>=r.batchSize&&d()}async function d(){if(c.length===0||!r)return;let e=c.splice(0,r.batchSize);try{let t=await fetch(r.endpoint,{method:"POST",headers:{"Content-Type":"application/json","X-Site-Key":r.siteKey},body:JSON.stringify({site_key:r.siteKey,events:e}),keepalive:!0});if(t.status===429){c.unshift(...e),p++;return}if(!t.ok)throw new Error(`HTTP ${t.status}`);p=0}catch{p++;try{let n=[...JSON.parse(sessionStorage.getItem("ep_buffer")||"[]"),...e].slice(-N);sessionStorage.setItem("ep_buffer",JSON.stringify(n))}catch{}}}function y(e){r=e,setInterval(d,e.batchIntervalMs)}var C="https://collect.edgeplus.pro/api/collect",h=!1;function m(e){if(h)return;if(!e.siteKey?.startsWith(f)){console.warn(`[EdgePlus] Invalid siteKey: must start with "${f}"`);return}let t={siteKey:e.siteKey,endpoint:e.endpoint||C,batchSize:e.batchSize||10,batchIntervalMs:e.batchIntervalMs||5e3,debug:e.debug||!1};h=!0,O(),v(u),b(u),_(u),y(t),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&d()}),t.debug&&console.log("[EdgePlus] Initialized:",e.siteKey)}function S(e,t){}function O(){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{m({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 d="ep_site_";function g(e){let t=()=>{e({type:"page_view",referrer:document.referrer,title:document.title})};t();let n=history.pushState;history.pushState=function(...l){n.apply(this,l),t()},window.addEventListener("popstate",t)}function f(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 m(e){try{let{onLCP:t,onFID:n,onCLS:l,onINP:_,onTTFB:y}=await import("web-vitals"),i=p=>{e({type:"web_vital",metric:p.name,value:Math.round(p.value*100)/100,rating:p.rating})};t(i),n(i),l(i),_(i),y(i)}catch{}}var S=100,w=5,o=[],c=0,r,s;function I(){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 a(e){if(c>=w)return;let t={...e,v:1,ts:e.ts||Date.now(),url:e.url||location.href,session_id:I()};o.push(t),r&&o.length>=r.batchSize&&u()}async function u(){if(o.length===0||!r)return;let e=o.splice(0,r.batchSize);try{let t=await fetch(r.endpoint,{method:"POST",headers:{"Content-Type":"application/json","X-Site-Key":r.siteKey},body:JSON.stringify({site_key:r.siteKey,events:e}),keepalive:!0});if(t.status===429){o.unshift(...e),c++;return}if(!t.ok)throw new Error(`HTTP ${t.status}`);c=0}catch{c++;try{let n=[...JSON.parse(sessionStorage.getItem("ep_buffer")||"[]"),...e].slice(-S);sessionStorage.setItem("ep_buffer",JSON.stringify(n))}catch{}}}function E(e){r=e,setInterval(u,e.batchIntervalMs)}var T="https://collect.edgeplus.
|
|
1
|
+
var d="ep_site_";function g(e){let t=()=>{e({type:"page_view",referrer:document.referrer,title:document.title})};t();let n=history.pushState;history.pushState=function(...l){n.apply(this,l),t()},window.addEventListener("popstate",t)}function f(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 m(e){try{let{onLCP:t,onFID:n,onCLS:l,onINP:_,onTTFB:y}=await import("web-vitals"),i=p=>{e({type:"web_vital",metric:p.name,value:Math.round(p.value*100)/100,rating:p.rating})};t(i),n(i),l(i),_(i),y(i)}catch{}}var S=100,w=5,o=[],c=0,r,s;function I(){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 a(e){if(c>=w)return;let t={...e,v:1,ts:e.ts||Date.now(),url:e.url||location.href,session_id:I()};o.push(t),r&&o.length>=r.batchSize&&u()}async function u(){if(o.length===0||!r)return;let e=o.splice(0,r.batchSize);try{let t=await fetch(r.endpoint,{method:"POST",headers:{"Content-Type":"application/json","X-Site-Key":r.siteKey},body:JSON.stringify({site_key:r.siteKey,events:e}),keepalive:!0});if(t.status===429){o.unshift(...e),c++;return}if(!t.ok)throw new Error(`HTTP ${t.status}`);c=0}catch{c++;try{let n=[...JSON.parse(sessionStorage.getItem("ep_buffer")||"[]"),...e].slice(-S);sessionStorage.setItem("ep_buffer",JSON.stringify(n))}catch{}}}function E(e){r=e,setInterval(u,e.batchIntervalMs)}var T="https://collect.edgeplus.pro/api/collect",v=!1;function b(e){if(v)return;if(!e.siteKey?.startsWith(d)){console.warn(`[EdgePlus] Invalid siteKey: must start with "${d}"`);return}let t={siteKey:e.siteKey,endpoint:e.endpoint||T,batchSize:e.batchSize||10,batchIntervalMs:e.batchIntervalMs||5e3,debug:e.debug||!1};v=!0,x(),g(a),f(a),m(a),E(t),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&u()}),t.debug&&console.log("[EdgePlus] Initialized:",e.siteKey)}function P(e,t){}function x(){try{let e=sessionStorage.getItem("ep_buffer");if(e){let t=JSON.parse(e);t.length>0&&(t.forEach(n=>a(n)),sessionStorage.removeItem("ep_buffer"))}}catch{}}if(typeof document<"u"){let e=document.currentScript,t=e?.getAttribute("data-site-key");if(t)try{b({siteKey:t,endpoint:e?.getAttribute("data-endpoint")||void 0,debug:e?.hasAttribute("data-debug")||!1})}catch{}}export{b as init,P as track};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgeplus/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "EdgePlus browser SDK - Prescriptive web analytics",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
11
12
|
"import": "./dist/index.mjs",
|
|
12
|
-
"require": "./dist/index.js"
|
|
13
|
-
"types": "./dist/index.d.ts"
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"files": ["dist"],
|