@rybbit/js 0.2.0 → 0.4.0
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 +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +10 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
interface RybbitConfig {
|
|
2
2
|
analyticsHost: string;
|
|
3
|
-
siteId: string
|
|
3
|
+
siteId: string;
|
|
4
4
|
debounce?: number;
|
|
5
|
-
autoTrackPageviews?: boolean;
|
|
6
|
-
autoTrackSpaRoutes?: boolean;
|
|
7
|
-
trackQuerystring?: boolean;
|
|
8
|
-
trackOutboundLinks?: boolean;
|
|
9
|
-
trackHashRoutes?: boolean;
|
|
10
|
-
trackDataAttributes?: boolean;
|
|
11
|
-
trackWebVitals?: boolean;
|
|
12
|
-
webVitalsTimeout?: number;
|
|
13
5
|
skipPatterns?: string[];
|
|
14
6
|
maskPatterns?: string[];
|
|
15
7
|
debug?: boolean;
|
|
8
|
+
replayPrivacyConfig?: {
|
|
9
|
+
maskAllInputs?: boolean;
|
|
10
|
+
maskTextSelectors?: string[];
|
|
11
|
+
};
|
|
16
12
|
}
|
|
17
13
|
type PropertyValue = string | number | boolean;
|
|
18
14
|
interface TrackProperties {
|
|
19
15
|
[key: string]: PropertyValue | PropertyValue[];
|
|
20
16
|
}
|
|
17
|
+
type PageChangeCallback = (pathname: string, previousPathname: string) => void;
|
|
21
18
|
interface RybbitAPI {
|
|
22
|
-
init: (config: RybbitConfig) => void
|
|
19
|
+
init: (config: RybbitConfig) => Promise<void>;
|
|
23
20
|
pageview: (path?: string) => void;
|
|
24
21
|
event: (name: string, properties?: TrackProperties) => void;
|
|
25
22
|
outbound: (url: string, text?: string, target?: string) => void;
|
|
@@ -27,6 +24,11 @@ interface RybbitAPI {
|
|
|
27
24
|
clearUserId: () => void;
|
|
28
25
|
getUserId: () => string | null;
|
|
29
26
|
cleanup: () => void;
|
|
27
|
+
captureError: (error: Error | ErrorEvent, context?: TrackProperties) => void;
|
|
28
|
+
onPageChange: (callback: PageChangeCallback) => () => void;
|
|
29
|
+
startSessionReplay: () => void;
|
|
30
|
+
stopSessionReplay: () => void;
|
|
31
|
+
isSessionReplayActive: () => boolean;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
declare const rybbit: RybbitAPI;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
interface RybbitConfig {
|
|
2
2
|
analyticsHost: string;
|
|
3
|
-
siteId: string
|
|
3
|
+
siteId: string;
|
|
4
4
|
debounce?: number;
|
|
5
|
-
autoTrackPageviews?: boolean;
|
|
6
|
-
autoTrackSpaRoutes?: boolean;
|
|
7
|
-
trackQuerystring?: boolean;
|
|
8
|
-
trackOutboundLinks?: boolean;
|
|
9
|
-
trackHashRoutes?: boolean;
|
|
10
|
-
trackDataAttributes?: boolean;
|
|
11
|
-
trackWebVitals?: boolean;
|
|
12
|
-
webVitalsTimeout?: number;
|
|
13
5
|
skipPatterns?: string[];
|
|
14
6
|
maskPatterns?: string[];
|
|
15
7
|
debug?: boolean;
|
|
8
|
+
replayPrivacyConfig?: {
|
|
9
|
+
maskAllInputs?: boolean;
|
|
10
|
+
maskTextSelectors?: string[];
|
|
11
|
+
};
|
|
16
12
|
}
|
|
17
13
|
type PropertyValue = string | number | boolean;
|
|
18
14
|
interface TrackProperties {
|
|
19
15
|
[key: string]: PropertyValue | PropertyValue[];
|
|
20
16
|
}
|
|
17
|
+
type PageChangeCallback = (pathname: string, previousPathname: string) => void;
|
|
21
18
|
interface RybbitAPI {
|
|
22
|
-
init: (config: RybbitConfig) => void
|
|
19
|
+
init: (config: RybbitConfig) => Promise<void>;
|
|
23
20
|
pageview: (path?: string) => void;
|
|
24
21
|
event: (name: string, properties?: TrackProperties) => void;
|
|
25
22
|
outbound: (url: string, text?: string, target?: string) => void;
|
|
@@ -27,6 +24,11 @@ interface RybbitAPI {
|
|
|
27
24
|
clearUserId: () => void;
|
|
28
25
|
getUserId: () => string | null;
|
|
29
26
|
cleanup: () => void;
|
|
27
|
+
captureError: (error: Error | ErrorEvent, context?: TrackProperties) => void;
|
|
28
|
+
onPageChange: (callback: PageChangeCallback) => () => void;
|
|
29
|
+
startSessionReplay: () => void;
|
|
30
|
+
stopSessionReplay: () => void;
|
|
31
|
+
isSessionReplayActive: () => boolean;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
declare const rybbit: RybbitAPI;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @rybbit/js v0.
|
|
2
|
+
* @rybbit/js v0.4.0
|
|
3
3
|
* Rybbit Web SDK
|
|
4
4
|
* (c) 2025 Rybbit
|
|
5
5
|
* Released under the AGPL-3.0-only license.
|
|
6
6
|
*/
|
|
7
|
-
"use strict";var D=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var Ut=Object.getOwnPropertyNames,st=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,Nt=Object.prototype.propertyIsEnumerable;var N=(e,t,i)=>t in e?D(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,m=(e,t)=>{for(var i in t||(t={}))lt.call(t,i)&&N(e,i,t[i]);if(st)for(var i of st(t))Nt.call(t,i)&&N(e,i,t[i]);return e};var Ft=(e,t)=>{for(var i in t)D(e,i,{get:t[i],enumerable:!0})},zt=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ut(t))!lt.call(e,n)&&n!==i&&D(e,n,{get:()=>t[n],enumerable:!(r=Ht(t,n))||r.enumerable});return e};var $t=e=>zt(D({},"__esModule",{value:!0}),e);var y=(e,t,i)=>N(e,typeof t!="symbol"?t+"":t,i);var Yt={};Ft(Yt,{default:()=>Jt});module.exports=$t(Yt);function ct(e,t){let i=null;return function(...r){let n=this;i!==null&&clearTimeout(i),i=setTimeout(()=>{i=null,e.apply(n,r)},t)}}function ut(e){try{let t=window.location.hostname,i=new URL(e,window.location.href).hostname;return!!i&&i!==t}catch(t){return!1}}function Bt(e){try{let t="__DOUBLE_ASTERISK_TOKEN__",i="__SINGLE_ASTERISK_TOKEN__",n=e.replace(/\*\*/g,t).replace(/\*/g,i).replace(/[.+?^${}()|[\]\\]/g,"\\$&");n=n.replace(/\//g,"\\/");let u=n.replace(new RegExp(t,"g"),".*").replace(new RegExp(i,"g"),"[^/]+");return new RegExp("^"+u+"$")}catch(t){return o(`Invalid pattern: ${e}`,t),null}}function F(e,t=[]){if(!t||t.length===0)return null;for(let i of t){let r=Bt(i);if(r&&r.test(e))return i}return null}function s(...e){l.debug&&console.log("[Rybbit]",...e)}function o(...e){l.debug&&console.error("[Rybbit Error]",...e)}function z(){let e=new URL(window.location.href),t=e.pathname;return l.trackHashRoutes&&e.hash&&(t+=e.hash),t}var g={debounce:500,autoTrackPageviews:!0,autoTrackSpaRoutes:!0,trackQuerystring:!0,trackOutboundLinks:!0,trackHashRoutes:!0,trackDataAttributes:!0,trackWebVitals:!0,webVitalsTimeout:2e4,skipPatterns:[],maskPatterns:[],debug:!1},O=null,l=new Proxy({},{get:(e,t)=>{var i;return O?O[t]:(t!=="debug"&&o("Rybbit SDK accessed before initialization. Call rybbit.init() first."),(i=g[t])!=null?i:void 0)},set:()=>(o("Rybbit config is read-only after initialization."),!1)});function dt(e){var d,f,w,C,P,S,rt,nt,at,ot;if(O)return o("Rybbit SDK already initialized."),!1;if(typeof e!="object"||e===null)return o("Invalid configuration provided to rybbit.init(). Expected an object."),!1;let t=e,i=t.analyticsHost;if(!i)return o("`analyticsHost` is required in Rybbit config and must be a string."),!1;let r=i.replace(/\/$/,""),n=t.siteId;if(n==null||String(n).trim()==="")return o("`siteId` is required in Rybbit config and must be a non-empty string or number."),!1;let u=String(n),c=Array.isArray(t.skipPatterns)?t.skipPatterns:g.skipPatterns,a=Array.isArray(t.maskPatterns)?t.maskPatterns:g.maskPatterns;return O={analyticsHost:r,siteId:u,debounce:Math.max(0,(d=t.debounce)!=null?d:g.debounce),autoTrackPageviews:(f=t.autoTrackPageviews)!=null?f:g.autoTrackPageviews,autoTrackSpaRoutes:(w=t.autoTrackSpaRoutes)!=null?w:g.autoTrackSpaRoutes,trackQuerystring:(C=t.trackQuerystring)!=null?C:g.trackQuerystring,trackOutboundLinks:(P=t.trackOutboundLinks)!=null?P:g.trackOutboundLinks,trackHashRoutes:(S=t.trackHashRoutes)!=null?S:g.trackHashRoutes,trackDataAttributes:(rt=t.trackDataAttributes)!=null?rt:g.trackDataAttributes,trackWebVitals:(nt=t.trackWebVitals)!=null?nt:g.trackWebVitals,webVitalsTimeout:Math.max(1e3,(at=t.webVitalsTimeout)!=null?at:g.webVitalsTimeout),skipPatterns:c,maskPatterns:a,debug:(ot=t.debug)!=null?ot:g.debug},!0}var v=null,$=!1;try{let e=localStorage.getItem("rybbit-user-id");e&&(v=e),localStorage.getItem("disable-rybbit")!==null&&($=!0)}catch(e){o("localStorage unavailable")}typeof window!="undefined"&&window.__RYBBIT_OPTOUT__&&($=!0);function p(e,t={}){if($){s("Opted out of tracking.");return}if(!l||!l.analyticsHost||!l.siteId){o("Rybbit config not available. Ensure rybbit.init() was called successfully.");return}let{eventName:i,properties:r,pathOverride:n,webVitals:u}=t;if((e==="custom_event"||e==="performance")&&!i){o("Event name is required and must be a string for performance or custom events.");return}try{let c=new URL(window.location.href),a,d="";if(e==="pageview"&&typeof n=="string"&&n.trim()){s(`Using path override: ${n}`);try{let S=new URL(n,"http://dummybase");a=S.pathname,d=S.search||"",s(`Parsed override path: ${a}, search: ${d}`)}catch(S){o(`Invalid pathOverride format: ${n}. Using window location.`),a=z(),d=l.trackQuerystring?c.search:""}}else a=z(),d=l.trackQuerystring?c.search:"";if(e!=="performance"&&F(a,l.skipPatterns)){s(`Skipping track for path: ${a}`);return}let f=F(a,l.maskPatterns);f&&e!=="performance"&&(s(`Masking path ${a} as ${f}`),a=f,d="");let w=m(m(m(m({site_id:l.siteId,hostname:c.hostname,pathname:a,querystring:d,screenWidth:window.innerWidth,screenHeight:window.innerHeight,language:navigator.language,page_title:document.title,referrer:document.referrer||"direct",type:e},(e==="custom_event"||e==="performance")&&{event_name:i}),(e==="custom_event"||e==="outbound")&&Object.keys(r!=null?r:{}).length>0&&{properties:JSON.stringify(r)}),e==="performance"&&u&&m({},u)),v&&{user_id:v});s("Sending track event:",w);let C=JSON.stringify(w),P=`${l.analyticsHost}/track`;navigator.sendBeacon?navigator.sendBeacon(P,new Blob([C],{type:"application/json"}))||(o("sendBeacon failed, falling back to fetch."),ft(P,C)):ft(P,C)}catch(c){o("Error during tracking:",c)}}function ft(e,t){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:t,mode:"cors",keepalive:!0}).catch(i=>{o("Fetch request failed:",i)})}function gt(e){if(e.trim()===""){o("User ID must be a non-empty string");return}v=e.trim();try{localStorage.setItem("rybbit-user-id",v),s("User identified:",v)}catch(t){o("Could not persist user ID to localStorage")}}function pt(){v=null;try{localStorage.removeItem("rybbit-user-id"),s("User ID cleared")}catch(e){o("Could not remove user ID from localStorage")}}function mt(){return v}var k,_=!1;function bt(){if(_){s("Automatic tracking already set up.");return}if(!l.autoTrackPageviews){s("Automatic pageview tracking is disabled.");return}if(s("Setting up automatic tracking..."),k=l.debounce&&l.debounce>0?ct(()=>p("pageview"),l.debounce):()=>p("pageview"),requestAnimationFrame(()=>{k()}),l.autoTrackSpaRoutes){s("Setting up SPA route change tracking.");let e=history.pushState,t=history.replaceState;history.pushState=function(...i){e.apply(this,i),k()},history.replaceState=function(...i){t.apply(this,i),k()},window.addEventListener("popstate",k)}else s("SPA route change tracking is disabled.");l.trackHashRoutes?window.addEventListener("hashchange",k):s("Hash route tracking is disabled."),_=!0}function ht(){if(!l.trackDataAttributes){s("Data attribute tracking is disabled.");return}s("Setting up data attribute and outbound link tracking."),document.addEventListener("click",yt,!0)}function yt(e){if(!(e.target instanceof Element))return;let t=e.target;for(;t;){if(t.hasAttribute("data-rybbit-event")){let i=t.getAttribute("data-rybbit-event");if(i){let r={};for(let n of t.attributes)if(n.name.startsWith("data-rybbit-prop-")){let u=n.name.replace("data-rybbit-prop-","");r[u]=n.value}s("Data attribute event triggered:",i,r),p("custom_event",{eventName:i,properties:r})}break}t=t.parentElement}if(l.trackOutboundLinks&&e.target instanceof Element){let i=e.target.closest("a");if(i&&i.href&&ut(i.href)){s("Outbound link clicked:",i.href);let r={url:i.href,text:i.innerText||i.textContent||"",target:i.target||"_self"};p("outbound",{properties:r})}}}function vt(){_&&(s("Cleaning up automatic tracking listeners."),window.removeEventListener("popstate",k),window.removeEventListener("hashchange",k),document.removeEventListener("click",yt,!0),_=!1)}var Lt=-1,E=e=>{addEventListener("pageshow",t=>{t.persisted&&(Lt=t.timeStamp,e(t))},!0)},b=(e,t,i,r)=>{let n,u;return c=>{t.value>=0&&(c||r)&&(u=t.value-(n!=null?n:0),(u||n===void 0)&&(n=t.value,t.delta=u,t.rating=((a,d)=>a>d[1]?"poor":a>d[0]?"needs-improvement":"good")(t.value,i),e(t)))}},Y=e=>{requestAnimationFrame(()=>requestAnimationFrame(()=>e()))},X=()=>{let e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},L=()=>{var t;let e=X();return(t=e==null?void 0:e.activationStart)!=null?t:0},h=(e,t=-1)=>{let i=X(),r="navigate";return Lt>=0?r="back-forward-cache":i&&(document.prerendering||L()>0?r="prerender":document.wasDiscarded?r="restore":i.type&&(r=i.type.replace(/_/g,"-"))),{name:e,value:t,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:r}},B=new WeakMap;function Z(e,t){return B.get(e)||B.set(e,new t),B.get(e)}var q=class{constructor(){y(this,"t");y(this,"i",0);y(this,"o",[])}h(t){var n;if(t.hadRecentInput)return;let i=this.o[0],r=this.o.at(-1);this.i&&i&&r&&t.startTime-r.startTime<1e3&&t.startTime-i.startTime<5e3?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),(n=this.t)==null||n.call(this,t)}},A=(e,t,i={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){let r=new PerformanceObserver(n=>{Promise.resolve().then(()=>{t(n.getEntries())})});return r.observe(m({type:e,buffered:!0},i)),r}}catch(r){}},tt=e=>{let t=!1;return()=>{t||(e(),t=!0)}},R=-1,kt=()=>document.visibilityState!=="hidden"||document.prerendering?1/0:0,V=e=>{document.visibilityState==="hidden"&&R>-1&&(R=e.type==="visibilitychange"?e.timeStamp:0,Kt())},Tt=()=>{addEventListener("visibilitychange",V,!0),addEventListener("prerenderingchange",V,!0)},Kt=()=>{removeEventListener("visibilitychange",V,!0),removeEventListener("prerenderingchange",V,!0)},At=()=>{var e;if(R<0){let t=L(),i=document.prerendering||(e=globalThis.performance.getEntriesByType("visibility-state").filter(r=>r.name==="hidden"&&r.startTime>t)[0])==null?void 0:e.startTime;R=i!=null?i:kt(),Tt(),E(()=>{setTimeout(()=>{R=kt(),Tt()})})}return{get firstHiddenTime(){return R}}},W=e=>{document.prerendering?addEventListener("prerenderingchange",()=>e(),!0):e()},wt=[1800,3e3],et=(e,t={})=>{W(()=>{let i=At(),r,n=h("FCP"),u=A("paint",c=>{for(let a of c)a.name==="first-contentful-paint"&&(u.disconnect(),a.startTime<i.firstHiddenTime&&(n.value=Math.max(a.startTime-L(),0),n.entries.push(a),r(!0)))});u&&(r=b(e,n,wt,t.reportAllChanges),E(c=>{n=h("FCP"),r=b(e,n,wt,t.reportAllChanges),Y(()=>{n.value=performance.now()-c.timeStamp,r(!0)})}))})},St=[.1,.25],xt=(e,t={})=>{et(tt(()=>{let i,r=h("CLS",0),n=Z(t,q),u=a=>{for(let d of a)n.h(d);n.i>r.value&&(r.value=n.i,r.entries=n.o,i())},c=A("layout-shift",u);c&&(i=b(e,r,St,t.reportAllChanges),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&(u(c.takeRecords()),i(!0))}),E(()=>{n.i=0,r=h("CLS",0),i=b(e,r,St,t.reportAllChanges),Y(()=>i())}),setTimeout(i))}))},Dt=0,K=1/0,M=0,qt=e=>{for(let t of e)t.interactionId&&(K=Math.min(K,t.interactionId),M=Math.max(M,t.interactionId),Dt=M?(M-K)/7+1:0)},j,Ct=()=>{var e;return j?Dt:(e=performance.interactionCount)!=null?e:0},jt=()=>{"interactionCount"in performance||j||(j=A("event",qt,{type:"event",buffered:!0,durationThreshold:0}))},Pt=0,Q=class{constructor(){y(this,"u",[]);y(this,"l",new Map);y(this,"m");y(this,"v")}p(){Pt=Ct(),this.u.length=0,this.l.clear()}P(){let t=Math.min(this.u.length-1,Math.floor((Ct()-Pt)/50));return this.u[t]}h(t){var n,u;if((n=this.m)==null||n.call(this,t),!t.interactionId&&t.entryType!=="first-input")return;let i=this.u.at(-1),r=this.l.get(t.interactionId);if(r||this.u.length<10||t.duration>i.T){if(r?t.duration>r.T?(r.entries=[t],r.T=t.duration):t.duration===r.T&&t.startTime===r.entries[0].startTime&&r.entries.push(t):(r={id:t.interactionId,entries:[t],T:t.duration},this.l.set(r.id,r),this.u.push(r)),this.u.sort((c,a)=>a.T-c.T),this.u.length>10){let c=this.u.splice(10);for(let a of c)this.l.delete(a.id)}(u=this.v)==null||u.call(this,r)}}},Ot=e=>{let t=globalThis.requestIdleCallback||setTimeout;document.visibilityState==="hidden"?e():(e=tt(e),document.addEventListener("visibilitychange",e,{once:!0}),t(()=>{e(),document.removeEventListener("visibilitychange",e)}))},Rt=[200,500],_t=(e,t={})=>{globalThis.PerformanceEventTiming&&"interactionId"in PerformanceEventTiming.prototype&&W(()=>{var a;jt();let i,r=h("INP"),n=Z(t,Q),u=d=>{Ot(()=>{for(let w of d)n.h(w);let f=n.P();f&&f.T!==r.value&&(r.value=f.T,r.entries=f.entries,i())})},c=A("event",u,{durationThreshold:(a=t.durationThreshold)!=null?a:40});i=b(e,r,Rt,t.reportAllChanges),c&&(c.observe({type:"first-input",buffered:!0}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&(u(c.takeRecords()),i(!0))}),E(()=>{n.p(),r=h("INP"),i=b(e,r,Rt,t.reportAllChanges)}))})},G=class{constructor(){y(this,"m")}h(t){var i;(i=this.m)==null||i.call(this,t)}},Et=[2500,4e3],Mt=(e,t={})=>{W(()=>{let i=At(),r,n=h("LCP"),u=Z(t,G),c=d=>{t.reportAllChanges||(d=d.slice(-1));for(let f of d)u.h(f),f.startTime<i.firstHiddenTime&&(n.value=Math.max(f.startTime-L(),0),n.entries=[f],r())},a=A("largest-contentful-paint",c);if(a){r=b(e,n,Et,t.reportAllChanges);let d=tt(()=>{c(a.takeRecords()),a.disconnect(),r(!0)});for(let f of["keydown","click","visibilitychange"])addEventListener(f,()=>Ot(d),{capture:!0,once:!0});E(f=>{n=h("LCP"),r=b(e,n,Et,t.reportAllChanges),Y(()=>{n.value=performance.now()-f.timeStamp,r(!0)})})}})},It=[800,1800],J=e=>{document.prerendering?W(()=>J(e)):document.readyState!=="complete"?addEventListener("load",()=>J(e),!0):setTimeout(e)},Vt=(e,t={})=>{let i=h("TTFB"),r=b(e,i,It,t.reportAllChanges);J(()=>{let n=X();n&&(i.value=Math.max(n.responseStart-L(),0),i.entries=[n],r(!0),E(()=>{i=h("TTFB",0),r=b(e,i,It,t.reportAllChanges),r(!0)}))})};var U={lcp:null,cls:null,inp:null,fcp:null,ttfb:null},I=!1,H=null;function Qt(){if(I)return;Object.values(U).every(t=>t!==null)&&it()}function it(){I||(I=!0,H&&(clearTimeout(H),H=null),s("Sending web vitals data:",U),p("performance",{eventName:"web-vitals",webVitals:U}))}function x(e){if(I)return;let t=e.name.toLowerCase();U[t]=e.value,s(`Collected ${t}:`,e.value),Qt()}function Wt(){if(!l.trackWebVitals){s("Web vitals tracking is disabled.");return}s("Initializing web vitals tracking...");try{Mt(x),xt(x),_t(x),et(x),Vt(x),H=setTimeout(()=>{I||(s("Web vitals timeout reached, sending collected metrics."),it())},l.webVitalsTimeout||2e4),window.addEventListener("beforeunload",()=>{I||it()}),s("Web vitals tracking initialized successfully.")}catch(e){o("Error setting up web vitals tracking:",e)}}var T=!1,Gt={init:e=>{if(T){o("Rybbit SDK already initialized. Call init() only once.");return}dt(e)&&(T=!0,s("Config:",m({},l)),bt(),ht(),Wt())},pageview:e=>{if(!T){o("Rybbit SDK not initialized. Call rybbit.init() first.");return}p("pageview",{pathOverride:e})},event:(e,t)=>{if(!T){o("Rybbit SDK not initialized. Call rybbit.init() first.");return}if(!e){o("Event name is required and must be a string.");return}p("custom_event",{eventName:e,properties:t})},outbound:(e,t="",i="_self")=>{if(!T){o("Rybbit SDK not initialized. Call rybbit.init() first.");return}if(!e){o("Outbound link URL is required and must be a string.");return}p("outbound",{properties:{url:e,text:t,target:i}})},identify:e=>{if(!T){o("Rybbit SDK not initialized. Call rybbit.init() first.");return}gt(e)},clearUserId:()=>{if(!T){o("Rybbit SDK not initialized. Call rybbit.init() first.");return}pt()},getUserId:()=>T?mt():(o("Rybbit SDK not initialized. Call rybbit.init() first."),null),cleanup:vt},Jt=Gt;
|
|
7
|
+
"use strict";var lt=Object.create;var D=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames,ve=Object.getOwnPropertySymbols,dt=Object.getPrototypeOf,ke=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var G=(e,t,r)=>t in e?D(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,b=(e,t)=>{for(var r in t||(t={}))ke.call(t,r)&&G(e,r,t[r]);if(ve)for(var r of ve(t))ft.call(t,r)&&G(e,r,t[r]);return e};var gt=(e,t)=>{for(var r in t)D(e,r,{get:t[r],enumerable:!0})},Ee=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ut(t))!ke.call(e,i)&&i!==r&&D(e,i,{get:()=>t[i],enumerable:!(n=ct(t,i))||n.enumerable});return e};var pt=(e,t,r)=>(r=e!=null?lt(dt(e)):{},Ee(t||!e||!e.__esModule?D(r,"default",{value:e,enumerable:!0}):r,e)),mt=e=>Ee(D({},"__esModule",{value:!0}),e);var v=(e,t,r)=>G(e,typeof t!="symbol"?t+"":t,r);var xt={};gt(xt,{default:()=>Lt});module.exports=mt(xt);function Se(e,t){let r=null;return function(...n){let i=this;r!==null&&clearTimeout(r),r=setTimeout(()=>{r=null,e.apply(i,n)},t)}}function Te(e){try{let t=window.location.hostname,r=new URL(e,window.location.href).hostname;return!!r&&r!==t}catch(t){return!1}}function bt(e){try{let t="__DOUBLE_ASTERISK_TOKEN__",r="__SINGLE_ASTERISK_TOKEN__",i=e.replace(/\*\*/g,t).replace(/\*/g,r).replace(/[.+?^${}()|[\]\\]/g,"\\$&");i=i.replace(/\//g,"\\/");let s=i.replace(new RegExp(t,"g"),".*").replace(new RegExp(r,"g"),"[^/]+");return new RegExp("^"+s+"$")}catch(t){return a(`Invalid pattern: ${e}`,t),null}}function Y(e,t=[]){if(!t||t.length===0)return null;for(let r of t){let n=bt(r);if(n&&n.test(e))return r}return null}function o(...e){c.debug&&console.log("[Rybbit]",...e)}function a(...e){c.debug&&console.error("[Rybbit Error]",...e)}function R(){let e=new URL(window.location.href),t=e.pathname;return e.hash&&(t+=e.hash),t}var O={debounce:500,skipPatterns:[],maskPatterns:[],debug:!1},k={autoTrackPageviews:!0,autoTrackSpaRoutes:!0,trackQuerystring:!0,trackOutboundLinks:!0,trackWebVitals:!1,captureErrors:!1,enableSessionReplay:!1},$=null,c=new Proxy({},{get:(e,t)=>{var r,n;return $?$[t]:(t!=="debug"&&a("Rybbit SDK accessed before initialization. Call rybbit.init() first."),(n=(r=O[t])!=null?r:k[t])!=null?n:void 0)},set:()=>(a("Rybbit config is read-only after initialization."),!1)});async function ht(e,t){var r,n,i,s,u,l,f;try{o("Fetching remote configuration...");let d=new AbortController,C=setTimeout(()=>d.abort(),3e3),w=await fetch(`${e}/site/${t}/tracking-config`,{signal:d.signal});if(clearTimeout(C),w.ok){let m=await w.json();return o("Remote configuration fetched successfully",m),{autoTrackPageviews:(r=m.trackInitialPageView)!=null?r:k.autoTrackPageviews,autoTrackSpaRoutes:(n=m.trackSpaNavigation)!=null?n:k.autoTrackSpaRoutes,trackQuerystring:(i=m.trackUrlParams)!=null?i:k.trackQuerystring,trackOutboundLinks:(s=m.trackOutbound)!=null?s:k.trackOutboundLinks,trackWebVitals:(u=m.webVitals)!=null?u:k.trackWebVitals,captureErrors:(l=m.trackErrors)!=null?l:k.captureErrors,enableSessionReplay:(f=m.sessionReplay)!=null?f:k.enableSessionReplay}}else return a(`Failed to fetch remote config: ${w.status}`),null}catch(d){return d.name==="AbortError"?a("Remote config fetch timed out"):a("Error fetching remote config:",d),null}}async function we(e){var f,d;if($)return a("Rybbit SDK already initialized."),!1;if(typeof e!="object"||e===null)return a("Invalid configuration provided to rybbit.init(). Expected an object."),!1;let t=e.analyticsHost;if(!t||t.trim()==="")return a("`analyticsHost` is required in Rybbit config and must be a non-empty string."),!1;let r=t.replace(/\/$/,""),n=e.siteId;if(!n||n.trim()==="")return a("`siteId` is required in Rybbit config and must be a non-empty string."),!1;let s=await ht(r,n)||k,u=Array.isArray(e.skipPatterns)?e.skipPatterns:O.skipPatterns,l=Array.isArray(e.maskPatterns)?e.maskPatterns:O.maskPatterns;return $={analyticsHost:r,siteId:n,debounce:Math.max(0,(f=e.debounce)!=null?f:O.debounce),skipPatterns:u,maskPatterns:l,debug:(d=e.debug)!=null?d:O.debug,replayPrivacyConfig:e.replayPrivacyConfig,autoTrackPageviews:s.autoTrackPageviews,autoTrackSpaRoutes:s.autoTrackSpaRoutes,trackQuerystring:s.trackQuerystring,trackOutboundLinks:s.trackOutboundLinks,trackWebVitals:s.trackWebVitals,captureErrors:s.captureErrors,enableSessionReplay:s.enableSessionReplay},!0}var E=null,X=!1;try{let e=localStorage.getItem("rybbit-user-id");e&&(E=e),localStorage.getItem("disable-rybbit")!==null&&(X=!0)}catch(e){a("localStorage unavailable")}typeof window!="undefined"&&window.__RYBBIT_OPTOUT__&&(X=!0);function p(e,t={}){if(X){o("Opted out of tracking.");return}if(!c||!c.analyticsHost||!c.siteId){a("Rybbit config not available. Ensure rybbit.init() was called successfully.");return}let{eventName:r,properties:n,pathOverride:i,webVitals:s}=t;if((e==="custom_event"||e==="performance")&&!r){a("Event name is required and must be a string for performance or custom events.");return}try{let u=new URL(window.location.href),l,f="";if(e==="pageview"&&typeof i=="string"&&i.trim()){o(`Using path override: ${i}`);try{let W=new URL(i,"http://dummybase");l=W.pathname,f=W.search||"",o(`Parsed override path: ${l}, search: ${f}`)}catch(W){a(`Invalid pathOverride format: ${i}. Using window location.`),l=R(),f=c.trackQuerystring?u.search:""}}else l=R(),f=c.trackQuerystring?u.search:"";if(e!=="performance"&&Y(l,c.skipPatterns)){o(`Skipping track for path: ${l}`);return}let d=Y(l,c.maskPatterns);d&&e!=="performance"&&(o(`Masking path ${l} as ${d}`),l=d,f="");let C=b(b(b(b({site_id:c.siteId,hostname:u.hostname,pathname:l,querystring:f,screenWidth:window.screen.width,screenHeight:window.screen.height,language:navigator.language,page_title:document.title,referrer:document.referrer||"direct",type:e},(e==="custom_event"||e==="performance")&&{event_name:r}),(e==="custom_event"||e==="outbound")&&Object.keys(n!=null?n:{}).length>0&&{properties:JSON.stringify(n)}),e==="performance"&&s&&b({},s)),E&&{user_id:E});o("Sending track event:",C);let w=JSON.stringify(C),m=`${c.analyticsHost}/track`;navigator.sendBeacon?navigator.sendBeacon(m,new Blob([w],{type:"application/json"}))||(a("sendBeacon failed, falling back to fetch."),Re(m,w)):Re(m,w)}catch(u){a("Error during tracking:",u)}}function Re(e,t){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:t,mode:"cors",keepalive:!0}).catch(r=>{a("Fetch request failed:",r)})}function Ce(e){if(e.trim()===""){a("User ID must be a non-empty string");return}E=e.trim();try{localStorage.setItem("rybbit-user-id",E),o("User identified:",E)}catch(t){a("Could not persist user ID to localStorage")}}function Pe(){E=null;try{localStorage.removeItem("rybbit-user-id"),o("User ID cleared")}catch(e){a("Could not remove user ID from localStorage")}}function Z(){return E}var S,V=!1,A=[],ee="";function Le(){if(V){o("Automatic tracking already set up.");return}if(!c.autoTrackPageviews){o("Automatic pageview tracking is disabled.");return}if(o("Setting up automatic tracking..."),ee=R(),S=c.debounce&&c.debounce>0?Se(()=>{let e=R();Ie(e),p("pageview")},c.debounce):()=>{let e=R();Ie(e),p("pageview")},requestAnimationFrame(()=>{S()}),c.autoTrackSpaRoutes){o("Setting up SPA route change tracking.");let e=history.pushState,t=history.replaceState;history.pushState=function(...r){e.apply(this,r),S()},history.replaceState=function(...r){t.apply(this,r),S()},window.addEventListener("popstate",S)}else o("SPA route change tracking is disabled.");window.addEventListener("hashchange",S),V=!0}function xe(){o("Setting up data attribute and outbound link tracking."),document.addEventListener("click",De,!0)}function De(e){if(!(e.target instanceof Element))return;let t=e.target;for(;t;){if(t.hasAttribute("data-rybbit-event")){let r=t.getAttribute("data-rybbit-event");if(r){let n={};for(let i of t.attributes)if(i.name.startsWith("data-rybbit-prop-")){let s=i.name.replace("data-rybbit-prop-","");n[s]=i.value}o("Data attribute event triggered:",r,n),p("custom_event",{eventName:r,properties:n})}break}t=t.parentElement}if(c.trackOutboundLinks&&e.target instanceof Element){let r=e.target.closest("a");if(r&&r.href&&Te(r.href)){o("Outbound link clicked:",r.href);let n={url:r.href,text:r.innerText||r.textContent||"",target:r.target||"_self"};p("outbound",{properties:n})}}}function Oe(e){return A.push(e),o("Page change callback added"),()=>{A=A.filter(t=>t!==e),o("Page change callback removed")}}function Ie(e){let t=ee;ee=e,t!==e&&(o(`Page changed from ${t} to ${e}`),A.forEach(r=>{try{r(e,t)}catch(n){a("Error in page change callback:",n)}}))}function Ae(){V&&(o("Cleaning up automatic tracking listeners."),window.removeEventListener("popstate",S),window.removeEventListener("hashchange",S),document.removeEventListener("click",De,!0),A=[],V=!1)}var ze=-1,I=e=>{addEventListener("pageshow",t=>{t.persisted&&(ze=t.timeStamp,e(t))},!0)},h=(e,t,r,n)=>{let i,s;return u=>{t.value>=0&&(u||n)&&(s=t.value-(i!=null?i:0),(s||i===void 0)&&(i=t.value,t.delta=s,t.rating=((l,f)=>l>f[1]?"poor":l>f[0]?"needs-improvement":"good")(t.value,r),e(t)))}},le=e=>{requestAnimationFrame(()=>requestAnimationFrame(()=>e()))},ce=()=>{let e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},_=()=>{var t;let e=ce();return(t=e==null?void 0:e.activationStart)!=null?t:0},y=(e,t=-1)=>{let r=ce(),n="navigate";return ze>=0?n="back-forward-cache":r&&(document.prerendering||_()>0?n="prerender":document.wasDiscarded?n="restore":r.type&&(n=r.type.replace(/_/g,"-"))),{name:e,value:t,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:n}},te=new WeakMap;function ue(e,t){return te.get(e)||te.set(e,new t),te.get(e)}var ne=class{constructor(){v(this,"t");v(this,"i",0);v(this,"o",[])}h(t){var i;if(t.hadRecentInput)return;let r=this.o[0],n=this.o.at(-1);this.i&&r&&n&&t.startTime-n.startTime<1e3&&t.startTime-r.startTime<5e3?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),(i=this.t)==null||i.call(this,t)}},M=(e,t,r={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){let n=new PerformanceObserver(i=>{Promise.resolve().then(()=>{t(i.getEntries())})});return n.observe(b({type:e,buffered:!0},r)),n}}catch(n){}},de=e=>{let t=!1;return()=>{t||(e(),t=!0)}},P=-1,_e=()=>document.visibilityState!=="hidden"||document.prerendering?1/0:0,z=e=>{document.visibilityState==="hidden"&&P>-1&&(P=e.type==="visibilitychange"?e.timeStamp:0,yt())},Me=()=>{addEventListener("visibilitychange",z,!0),addEventListener("prerenderingchange",z,!0)},yt=()=>{removeEventListener("visibilitychange",z,!0),removeEventListener("prerenderingchange",z,!0)},Ke=()=>{var e;if(P<0){let t=_(),r=document.prerendering||(e=globalThis.performance.getEntriesByType("visibility-state").filter(n=>n.name==="hidden"&&n.startTime>t)[0])==null?void 0:e.startTime;P=r!=null?r:_e(),Me(),I(()=>{setTimeout(()=>{P=_e(),Me()})})}return{get firstHiddenTime(){return P}}},K=e=>{document.prerendering?addEventListener("prerenderingchange",()=>e(),!0):e()},Ue=[1800,3e3],fe=(e,t={})=>{K(()=>{let r=Ke(),n,i=y("FCP"),s=M("paint",u=>{for(let l of u)l.name==="first-contentful-paint"&&(s.disconnect(),l.startTime<r.firstHiddenTime&&(i.value=Math.max(l.startTime-_(),0),i.entries.push(l),n(!0)))});s&&(n=h(e,i,Ue,t.reportAllChanges),I(u=>{i=y("FCP"),n=h(e,i,Ue,t.reportAllChanges),le(()=>{i.value=performance.now()-u.timeStamp,n(!0)})}))})},Fe=[.1,.25],je=(e,t={})=>{fe(de(()=>{let r,n=y("CLS",0),i=ue(t,ne),s=l=>{for(let f of l)i.h(f);i.i>n.value&&(n.value=i.i,n.entries=i.o,r())},u=M("layout-shift",s);u&&(r=h(e,n,Fe,t.reportAllChanges),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&(s(u.takeRecords()),r(!0))}),I(()=>{i.i=0,n=y("CLS",0),r=h(e,n,Fe,t.reportAllChanges),le(()=>r())}),setTimeout(r))}))},He=0,re=1/0,B=0,vt=e=>{for(let t of e)t.interactionId&&(re=Math.min(re,t.interactionId),B=Math.max(B,t.interactionId),He=B?(B-re)/7+1:0)},ie,Ne=()=>{var e;return ie?He:(e=performance.interactionCount)!=null?e:0},kt=()=>{"interactionCount"in performance||ie||(ie=M("event",vt,{type:"event",buffered:!0,durationThreshold:0}))},We=0,ae=class{constructor(){v(this,"u",[]);v(this,"l",new Map);v(this,"m");v(this,"v")}p(){We=Ne(),this.u.length=0,this.l.clear()}P(){let t=Math.min(this.u.length-1,Math.floor((Ne()-We)/50));return this.u[t]}h(t){var i,s;if((i=this.m)==null||i.call(this,t),!t.interactionId&&t.entryType!=="first-input")return;let r=this.u.at(-1),n=this.l.get(t.interactionId);if(n||this.u.length<10||t.duration>r.T){if(n?t.duration>n.T?(n.entries=[t],n.T=t.duration):t.duration===n.T&&t.startTime===n.entries[0].startTime&&n.entries.push(t):(n={id:t.interactionId,entries:[t],T:t.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort((u,l)=>l.T-u.T),this.u.length>10){let u=this.u.splice(10);for(let l of u)this.l.delete(l.id)}(s=this.v)==null||s.call(this,n)}}},qe=e=>{let t=globalThis.requestIdleCallback||setTimeout;document.visibilityState==="hidden"?e():(e=de(e),document.addEventListener("visibilitychange",e,{once:!0}),t(()=>{e(),document.removeEventListener("visibilitychange",e)}))},$e=[200,500],Qe=(e,t={})=>{globalThis.PerformanceEventTiming&&"interactionId"in PerformanceEventTiming.prototype&&K(()=>{var l;kt();let r,n=y("INP"),i=ue(t,ae),s=f=>{qe(()=>{for(let C of f)i.h(C);let d=i.P();d&&d.T!==n.value&&(n.value=d.T,n.entries=d.entries,r())})},u=M("event",s,{durationThreshold:(l=t.durationThreshold)!=null?l:40});r=h(e,n,$e,t.reportAllChanges),u&&(u.observe({type:"first-input",buffered:!0}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&(s(u.takeRecords()),r(!0))}),I(()=>{i.p(),n=y("INP"),r=h(e,n,$e,t.reportAllChanges)}))})},oe=class{constructor(){v(this,"m")}h(t){var r;(r=this.m)==null||r.call(this,t)}},Ve=[2500,4e3],Je=(e,t={})=>{K(()=>{let r=Ke(),n,i=y("LCP"),s=ue(t,oe),u=f=>{t.reportAllChanges||(f=f.slice(-1));for(let d of f)s.h(d),d.startTime<r.firstHiddenTime&&(i.value=Math.max(d.startTime-_(),0),i.entries=[d],n())},l=M("largest-contentful-paint",u);if(l){n=h(e,i,Ve,t.reportAllChanges);let f=de(()=>{u(l.takeRecords()),l.disconnect(),n(!0)});for(let d of["keydown","click","visibilitychange"])addEventListener(d,()=>qe(f),{capture:!0,once:!0});I(d=>{i=y("LCP"),n=h(e,i,Ve,t.reportAllChanges),le(()=>{i.value=performance.now()-d.timeStamp,n(!0)})})}})},Be=[800,1800],se=e=>{document.prerendering?K(()=>se(e)):document.readyState!=="complete"?addEventListener("load",()=>se(e),!0):setTimeout(e)},Ge=(e,t={})=>{let r=y("TTFB"),n=h(e,r,Be,t.reportAllChanges);se(()=>{let i=ce();i&&(r.value=Math.max(i.responseStart-_(),0),r.entries=[i],n(!0),I(()=>{r=y("TTFB",0),n=h(e,r,Be,t.reportAllChanges),n(!0)}))})};var H={lcp:null,cls:null,inp:null,fcp:null,ttfb:null},L=!1,j=null;function Et(){if(L)return;Object.values(H).every(t=>t!==null)&&ge()}function ge(){L||(L=!0,j&&(clearTimeout(j),j=null),o("Sending web vitals data:",H),p("performance",{eventName:"web-vitals",webVitals:H}))}function U(e){if(L)return;let t=e.name.toLowerCase();H[t]=e.value,o(`Collected ${t}:`,e.value),Et()}function Ye(){if(!c.trackWebVitals){o("Web vitals tracking is disabled.");return}o("Initializing web vitals tracking...");try{Je(U),je(U),Qe(U),fe(U),Ge(U),j=setTimeout(()=>{L||(o("Web vitals timeout reached, sending collected metrics."),ge())},2e4),window.addEventListener("beforeunload",()=>{L||ge()}),o("Web vitals tracking initialized successfully.")}catch(e){a("Error setting up web vitals tracking:",e)}}var F=null,N=null;function Xe(){c.captureErrors&&(o("Setting up error tracking"),F=e=>{St(e)},N=e=>{Tt(e)},window.addEventListener("error",F),window.addEventListener("unhandledrejection",N))}function Ze(){F&&(window.removeEventListener("error",F),F=null),N&&(window.removeEventListener("unhandledrejection",N),N=null),o("Error tracking cleaned up")}function St(e){var s,u;let t=window.location.origin,r=e.filename||"";if(r)try{if(new URL(r).origin!==t){o("Skipping third-party error:",r);return}}catch(l){}let n=((s=e.error)==null?void 0:s.stack)||"";if(!r&&n&&!n.includes(t)){o("Skipping third-party error based on stack trace");return}let i={message:(e.message||"Unknown error").substring(0,500),stack:n.substring(0,2e3),filename:r||void 0,lineno:e.lineno||void 0,colno:e.colno||void 0,timestamp:Date.now()};q(((u=e.error)==null?void 0:u.name)||"Error",i)}function Tt(e){let t="Unhandled promise rejection",r="";e.reason instanceof Error?(t=e.reason.message||t,r=e.reason.stack||""):typeof e.reason=="string"?t=e.reason:e.reason&&typeof e.reason=="object"&&(t=JSON.stringify(e.reason));let n={message:t.substring(0,500),stack:r.substring(0,2e3),timestamp:Date.now()};q("UnhandledRejection",n)}function q(e,t,r){let n=b({error_name:e,message:t.message},r);t.stack&&(n.stack=t.stack),t.filename&&(n.filename=t.filename),t.lineno&&(n.line_number=t.lineno),t.colno&&(n.column_number=t.colno),p("error",{eventName:e,properties:n})}function et(e,t){var r,n;if(!c.captureErrors){a("Error tracking is not enabled. Set captureErrors: true in config.");return}if(e instanceof ErrorEvent){let i={message:(e.message||"Unknown error").substring(0,500),stack:(((r=e.error)==null?void 0:r.stack)||"").substring(0,2e3),filename:e.filename||void 0,lineno:e.lineno||void 0,colno:e.colno||void 0,timestamp:Date.now()};q(((n=e.error)==null?void 0:n.name)||"Error",i,t)}else{let i={message:(e.message||"Unknown error").substring(0,500),stack:(e.stack||"").substring(0,2e3),timestamp:Date.now()};q(e.name||"Error",i,t)}}var J=null,x=!1,pe=null,T=[],Q,me=null,be;function wt(){return`${Date.now()}-${Math.random().toString(36).substring(2,15)}`}async function tt(e){if(c.enableSessionReplay){be=e,me=wt();try{J=(await import("rrweb")).record,o("rrweb loaded successfully"),rt()}catch(t){a("Failed to load rrweb. Make sure it's installed as a peer dependency:",t)}}}function rt(){var e;if(!(x||!J||!c.enableSessionReplay))try{let t=c.replayPrivacyConfig||{},r={emit:n=>{Rt({type:n.type,data:n.data,timestamp:n.timestamp||Date.now()})},recordCanvas:!1,collectFonts:!1,checkoutEveryNms:6e4,checkoutEveryNth:500,maskAllInputs:(e=t.maskAllInputs)!=null?e:!0,maskInputOptions:{password:!0,email:!0},slimDOMOptions:{script:!1,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:!0,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0},sampling:{mousemove:!1,mouseInteraction:{MouseUp:!1,MouseDown:!1,Click:!0,ContextMenu:!1,DblClick:!0,Focus:!0,Blur:!0,TouchStart:!1,TouchEnd:!1},scroll:500,input:"last",media:800}};t.maskTextSelectors&&t.maskTextSelectors.length>0&&(r.maskTextSelector=t.maskTextSelectors.join(", ")),pe=J(r),x=!0,Ct(),o("Session replay recording started")}catch(t){a("Failed to start session replay recording:",t)}}function nt(){if(!c.enableSessionReplay){a("Session replay is not enabled. Enable it via remote config.");return}if(!J){a("rrweb is not loaded. Ensure it's installed as a peer dependency.");return}if(x){o("Session replay is already recording");return}rt()}function he(){if(!x){o("Session replay is not currently recording");return}pe&&pe(),x=!1,at(),T.length>0&&ye(),o("Session replay recording stopped")}function it(){return x}function Rt(e){T.push(e),T.length>=250&&ye()}function Ct(){at(),Q=window.setInterval(()=>{T.length>0&&ye()},5e3)}function at(){Q!==void 0&&(clearInterval(Q),Q=void 0)}function ye(){if(T.length===0||!me)return;let e=[...T];T=[];let t={sessionId:me,siteId:c.siteId,userId:be,events:e,metadata:{pageUrl:window.location.href,screenWidth:window.screen.width,screenHeight:window.screen.height,language:navigator.language}};Pt(t).catch(r=>{a("Failed to send session replay batch:",r),T.unshift(...e)})}async function Pt(e){let t=`${c.analyticsHost}/replay`,r=JSON.stringify(e),n=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:r,mode:"cors",keepalive:!0});if(!n.ok)throw new Error(`Failed to send replay batch: ${n.status}`);o(`Session replay batch sent: ${e.events.length} events`)}function ot(e){be=e}function st(){he()}var g=!1,It={init:async e=>{if(g){a("Rybbit SDK already initialized. Call init() only once.");return}await we(e)&&(g=!0,o("Config:",b({},c)),Le(),xe(),Ye(),Xe(),await tt(Z()||void 0))},pageview:e=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}p("pageview",{pathOverride:e})},event:(e,t)=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}if(!e){a("Event name is required and must be a string.");return}p("custom_event",{eventName:e,properties:t})},outbound:(e,t="",r="_self")=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}if(!e){a("Outbound link URL is required and must be a string.");return}p("outbound",{properties:{url:e,text:t,target:r}})},identify:e=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}Ce(e),ot(e)},clearUserId:()=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}Pe()},getUserId:()=>g?Z():(a("Rybbit SDK not initialized. Call rybbit.init() first."),null),captureError:(e,t)=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}et(e,t)},onPageChange:e=>g?Oe(e):(a("Rybbit SDK not initialized. Call rybbit.init() first."),()=>{}),startSessionReplay:()=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}nt()},stopSessionReplay:()=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}he()},isSessionReplayActive:()=>g?it():(a("Rybbit SDK not initialized. Call rybbit.init() first."),!1),cleanup:()=>{Ae(),Ze(),st(),g=!1}},Lt=It;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @rybbit/js v0.
|
|
2
|
+
* @rybbit/js v0.4.0
|
|
3
3
|
* Rybbit Web SDK
|
|
4
4
|
* (c) 2025 Rybbit
|
|
5
5
|
* Released under the AGPL-3.0-only license.
|
|
6
6
|
*/
|
|
7
|
-
var Vt=Object.defineProperty;var ot=Object.getOwnPropertySymbols;var Wt=Object.prototype.hasOwnProperty,Ht=Object.prototype.propertyIsEnumerable;var U=(e,t,i)=>t in e?Vt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,m=(e,t)=>{for(var i in t||(t={}))Wt.call(t,i)&&U(e,i,t[i]);if(ot)for(var i of ot(t))Ht.call(t,i)&&U(e,i,t[i]);return e};var y=(e,t,i)=>U(e,typeof t!="symbol"?t+"":t,i);function st(e,t){let i=null;return function(...r){let n=this;i!==null&&clearTimeout(i),i=setTimeout(()=>{i=null,e.apply(n,r)},t)}}function lt(e){try{let t=window.location.hostname,i=new URL(e,window.location.href).hostname;return!!i&&i!==t}catch(t){return!1}}function Ut(e){try{let t="__DOUBLE_ASTERISK_TOKEN__",i="__SINGLE_ASTERISK_TOKEN__",n=e.replace(/\*\*/g,t).replace(/\*/g,i).replace(/[.+?^${}()|[\]\\]/g,"\\$&");n=n.replace(/\//g,"\\/");let u=n.replace(new RegExp(t,"g"),".*").replace(new RegExp(i,"g"),"[^/]+");return new RegExp("^"+u+"$")}catch(t){return o(`Invalid pattern: ${e}`,t),null}}function N(e,t=[]){if(!t||t.length===0)return null;for(let i of t){let r=Ut(i);if(r&&r.test(e))return i}return null}function s(...e){l.debug&&console.log("[Rybbit]",...e)}function o(...e){l.debug&&console.error("[Rybbit Error]",...e)}function F(){let e=new URL(window.location.href),t=e.pathname;return l.trackHashRoutes&&e.hash&&(t+=e.hash),t}var g={debounce:500,autoTrackPageviews:!0,autoTrackSpaRoutes:!0,trackQuerystring:!0,trackOutboundLinks:!0,trackHashRoutes:!0,trackDataAttributes:!0,trackWebVitals:!0,webVitalsTimeout:2e4,skipPatterns:[],maskPatterns:[],debug:!1},D=null,l=new Proxy({},{get:(e,t)=>{var i;return D?D[t]:(t!=="debug"&&o("Rybbit SDK accessed before initialization. Call rybbit.init() first."),(i=g[t])!=null?i:void 0)},set:()=>(o("Rybbit config is read-only after initialization."),!1)});function ct(e){var d,f,w,C,P,S,it,rt,nt,at;if(D)return o("Rybbit SDK already initialized."),!1;if(typeof e!="object"||e===null)return o("Invalid configuration provided to rybbit.init(). Expected an object."),!1;let t=e,i=t.analyticsHost;if(!i)return o("`analyticsHost` is required in Rybbit config and must be a string."),!1;let r=i.replace(/\/$/,""),n=t.siteId;if(n==null||String(n).trim()==="")return o("`siteId` is required in Rybbit config and must be a non-empty string or number."),!1;let u=String(n),c=Array.isArray(t.skipPatterns)?t.skipPatterns:g.skipPatterns,a=Array.isArray(t.maskPatterns)?t.maskPatterns:g.maskPatterns;return D={analyticsHost:r,siteId:u,debounce:Math.max(0,(d=t.debounce)!=null?d:g.debounce),autoTrackPageviews:(f=t.autoTrackPageviews)!=null?f:g.autoTrackPageviews,autoTrackSpaRoutes:(w=t.autoTrackSpaRoutes)!=null?w:g.autoTrackSpaRoutes,trackQuerystring:(C=t.trackQuerystring)!=null?C:g.trackQuerystring,trackOutboundLinks:(P=t.trackOutboundLinks)!=null?P:g.trackOutboundLinks,trackHashRoutes:(S=t.trackHashRoutes)!=null?S:g.trackHashRoutes,trackDataAttributes:(it=t.trackDataAttributes)!=null?it:g.trackDataAttributes,trackWebVitals:(rt=t.trackWebVitals)!=null?rt:g.trackWebVitals,webVitalsTimeout:Math.max(1e3,(nt=t.webVitalsTimeout)!=null?nt:g.webVitalsTimeout),skipPatterns:c,maskPatterns:a,debug:(at=t.debug)!=null?at:g.debug},!0}var v=null,z=!1;try{let e=localStorage.getItem("rybbit-user-id");e&&(v=e),localStorage.getItem("disable-rybbit")!==null&&(z=!0)}catch(e){o("localStorage unavailable")}typeof window!="undefined"&&window.__RYBBIT_OPTOUT__&&(z=!0);function p(e,t={}){if(z){s("Opted out of tracking.");return}if(!l||!l.analyticsHost||!l.siteId){o("Rybbit config not available. Ensure rybbit.init() was called successfully.");return}let{eventName:i,properties:r,pathOverride:n,webVitals:u}=t;if((e==="custom_event"||e==="performance")&&!i){o("Event name is required and must be a string for performance or custom events.");return}try{let c=new URL(window.location.href),a,d="";if(e==="pageview"&&typeof n=="string"&&n.trim()){s(`Using path override: ${n}`);try{let S=new URL(n,"http://dummybase");a=S.pathname,d=S.search||"",s(`Parsed override path: ${a}, search: ${d}`)}catch(S){o(`Invalid pathOverride format: ${n}. Using window location.`),a=F(),d=l.trackQuerystring?c.search:""}}else a=F(),d=l.trackQuerystring?c.search:"";if(e!=="performance"&&N(a,l.skipPatterns)){s(`Skipping track for path: ${a}`);return}let f=N(a,l.maskPatterns);f&&e!=="performance"&&(s(`Masking path ${a} as ${f}`),a=f,d="");let w=m(m(m(m({site_id:l.siteId,hostname:c.hostname,pathname:a,querystring:d,screenWidth:window.innerWidth,screenHeight:window.innerHeight,language:navigator.language,page_title:document.title,referrer:document.referrer||"direct",type:e},(e==="custom_event"||e==="performance")&&{event_name:i}),(e==="custom_event"||e==="outbound")&&Object.keys(r!=null?r:{}).length>0&&{properties:JSON.stringify(r)}),e==="performance"&&u&&m({},u)),v&&{user_id:v});s("Sending track event:",w);let C=JSON.stringify(w),P=`${l.analyticsHost}/track`;navigator.sendBeacon?navigator.sendBeacon(P,new Blob([C],{type:"application/json"}))||(o("sendBeacon failed, falling back to fetch."),ut(P,C)):ut(P,C)}catch(c){o("Error during tracking:",c)}}function ut(e,t){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:t,mode:"cors",keepalive:!0}).catch(i=>{o("Fetch request failed:",i)})}function dt(e){if(e.trim()===""){o("User ID must be a non-empty string");return}v=e.trim();try{localStorage.setItem("rybbit-user-id",v),s("User identified:",v)}catch(t){o("Could not persist user ID to localStorage")}}function ft(){v=null;try{localStorage.removeItem("rybbit-user-id"),s("User ID cleared")}catch(e){o("Could not remove user ID from localStorage")}}function gt(){return v}var k,O=!1;function pt(){if(O){s("Automatic tracking already set up.");return}if(!l.autoTrackPageviews){s("Automatic pageview tracking is disabled.");return}if(s("Setting up automatic tracking..."),k=l.debounce&&l.debounce>0?st(()=>p("pageview"),l.debounce):()=>p("pageview"),requestAnimationFrame(()=>{k()}),l.autoTrackSpaRoutes){s("Setting up SPA route change tracking.");let e=history.pushState,t=history.replaceState;history.pushState=function(...i){e.apply(this,i),k()},history.replaceState=function(...i){t.apply(this,i),k()},window.addEventListener("popstate",k)}else s("SPA route change tracking is disabled.");l.trackHashRoutes?window.addEventListener("hashchange",k):s("Hash route tracking is disabled."),O=!0}function mt(){if(!l.trackDataAttributes){s("Data attribute tracking is disabled.");return}s("Setting up data attribute and outbound link tracking."),document.addEventListener("click",bt,!0)}function bt(e){if(!(e.target instanceof Element))return;let t=e.target;for(;t;){if(t.hasAttribute("data-rybbit-event")){let i=t.getAttribute("data-rybbit-event");if(i){let r={};for(let n of t.attributes)if(n.name.startsWith("data-rybbit-prop-")){let u=n.name.replace("data-rybbit-prop-","");r[u]=n.value}s("Data attribute event triggered:",i,r),p("custom_event",{eventName:i,properties:r})}break}t=t.parentElement}if(l.trackOutboundLinks&&e.target instanceof Element){let i=e.target.closest("a");if(i&&i.href&<(i.href)){s("Outbound link clicked:",i.href);let r={url:i.href,text:i.innerText||i.textContent||"",target:i.target||"_self"};p("outbound",{properties:r})}}}function ht(){O&&(s("Cleaning up automatic tracking listeners."),window.removeEventListener("popstate",k),window.removeEventListener("hashchange",k),document.removeEventListener("click",bt,!0),O=!1)}var Et=-1,E=e=>{addEventListener("pageshow",t=>{t.persisted&&(Et=t.timeStamp,e(t))},!0)},b=(e,t,i,r)=>{let n,u;return c=>{t.value>=0&&(c||r)&&(u=t.value-(n!=null?n:0),(u||n===void 0)&&(n=t.value,t.delta=u,t.rating=((a,d)=>a>d[1]?"poor":a>d[0]?"needs-improvement":"good")(t.value,i),e(t)))}},J=e=>{requestAnimationFrame(()=>requestAnimationFrame(()=>e()))},Y=()=>{let e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},L=()=>{var t;let e=Y();return(t=e==null?void 0:e.activationStart)!=null?t:0},h=(e,t=-1)=>{let i=Y(),r="navigate";return Et>=0?r="back-forward-cache":i&&(document.prerendering||L()>0?r="prerender":document.wasDiscarded?r="restore":i.type&&(r=i.type.replace(/_/g,"-"))),{name:e,value:t,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:r}},$=new WeakMap;function X(e,t){return $.get(e)||$.set(e,new t),$.get(e)}var K=class{constructor(){y(this,"t");y(this,"i",0);y(this,"o",[])}h(t){var n;if(t.hadRecentInput)return;let i=this.o[0],r=this.o.at(-1);this.i&&i&&r&&t.startTime-r.startTime<1e3&&t.startTime-i.startTime<5e3?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),(n=this.t)==null||n.call(this,t)}},A=(e,t,i={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){let r=new PerformanceObserver(n=>{Promise.resolve().then(()=>{t(n.getEntries())})});return r.observe(m({type:e,buffered:!0},i)),r}}catch(r){}},Z=e=>{let t=!1;return()=>{t||(e(),t=!0)}},R=-1,yt=()=>document.visibilityState!=="hidden"||document.prerendering?1/0:0,M=e=>{document.visibilityState==="hidden"&&R>-1&&(R=e.type==="visibilitychange"?e.timeStamp:0,Nt())},vt=()=>{addEventListener("visibilitychange",M,!0),addEventListener("prerenderingchange",M,!0)},Nt=()=>{removeEventListener("visibilitychange",M,!0),removeEventListener("prerenderingchange",M,!0)},It=()=>{var e;if(R<0){let t=L(),i=document.prerendering||(e=globalThis.performance.getEntriesByType("visibility-state").filter(r=>r.name==="hidden"&&r.startTime>t)[0])==null?void 0:e.startTime;R=i!=null?i:yt(),vt(),E(()=>{setTimeout(()=>{R=yt(),vt()})})}return{get firstHiddenTime(){return R}}},V=e=>{document.prerendering?addEventListener("prerenderingchange",()=>e(),!0):e()},kt=[1800,3e3],tt=(e,t={})=>{V(()=>{let i=It(),r,n=h("FCP"),u=A("paint",c=>{for(let a of c)a.name==="first-contentful-paint"&&(u.disconnect(),a.startTime<i.firstHiddenTime&&(n.value=Math.max(a.startTime-L(),0),n.entries.push(a),r(!0)))});u&&(r=b(e,n,kt,t.reportAllChanges),E(c=>{n=h("FCP"),r=b(e,n,kt,t.reportAllChanges),J(()=>{n.value=performance.now()-c.timeStamp,r(!0)})}))})},Tt=[.1,.25],Lt=(e,t={})=>{tt(Z(()=>{let i,r=h("CLS",0),n=X(t,K),u=a=>{for(let d of a)n.h(d);n.i>r.value&&(r.value=n.i,r.entries=n.o,i())},c=A("layout-shift",u);c&&(i=b(e,r,Tt,t.reportAllChanges),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&(u(c.takeRecords()),i(!0))}),E(()=>{n.i=0,r=h("CLS",0),i=b(e,r,Tt,t.reportAllChanges),J(()=>i())}),setTimeout(i))}))},At=0,B=1/0,_=0,Ft=e=>{for(let t of e)t.interactionId&&(B=Math.min(B,t.interactionId),_=Math.max(_,t.interactionId),At=_?(_-B)/7+1:0)},q,wt=()=>{var e;return q?At:(e=performance.interactionCount)!=null?e:0},zt=()=>{"interactionCount"in performance||q||(q=A("event",Ft,{type:"event",buffered:!0,durationThreshold:0}))},St=0,j=class{constructor(){y(this,"u",[]);y(this,"l",new Map);y(this,"m");y(this,"v")}p(){St=wt(),this.u.length=0,this.l.clear()}P(){let t=Math.min(this.u.length-1,Math.floor((wt()-St)/50));return this.u[t]}h(t){var n,u;if((n=this.m)==null||n.call(this,t),!t.interactionId&&t.entryType!=="first-input")return;let i=this.u.at(-1),r=this.l.get(t.interactionId);if(r||this.u.length<10||t.duration>i.T){if(r?t.duration>r.T?(r.entries=[t],r.T=t.duration):t.duration===r.T&&t.startTime===r.entries[0].startTime&&r.entries.push(t):(r={id:t.interactionId,entries:[t],T:t.duration},this.l.set(r.id,r),this.u.push(r)),this.u.sort((c,a)=>a.T-c.T),this.u.length>10){let c=this.u.splice(10);for(let a of c)this.l.delete(a.id)}(u=this.v)==null||u.call(this,r)}}},xt=e=>{let t=globalThis.requestIdleCallback||setTimeout;document.visibilityState==="hidden"?e():(e=Z(e),document.addEventListener("visibilitychange",e,{once:!0}),t(()=>{e(),document.removeEventListener("visibilitychange",e)}))},Ct=[200,500],Dt=(e,t={})=>{globalThis.PerformanceEventTiming&&"interactionId"in PerformanceEventTiming.prototype&&V(()=>{var a;zt();let i,r=h("INP"),n=X(t,j),u=d=>{xt(()=>{for(let w of d)n.h(w);let f=n.P();f&&f.T!==r.value&&(r.value=f.T,r.entries=f.entries,i())})},c=A("event",u,{durationThreshold:(a=t.durationThreshold)!=null?a:40});i=b(e,r,Ct,t.reportAllChanges),c&&(c.observe({type:"first-input",buffered:!0}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&(u(c.takeRecords()),i(!0))}),E(()=>{n.p(),r=h("INP"),i=b(e,r,Ct,t.reportAllChanges)}))})},Q=class{constructor(){y(this,"m")}h(t){var i;(i=this.m)==null||i.call(this,t)}},Pt=[2500,4e3],Ot=(e,t={})=>{V(()=>{let i=It(),r,n=h("LCP"),u=X(t,Q),c=d=>{t.reportAllChanges||(d=d.slice(-1));for(let f of d)u.h(f),f.startTime<i.firstHiddenTime&&(n.value=Math.max(f.startTime-L(),0),n.entries=[f],r())},a=A("largest-contentful-paint",c);if(a){r=b(e,n,Pt,t.reportAllChanges);let d=Z(()=>{c(a.takeRecords()),a.disconnect(),r(!0)});for(let f of["keydown","click","visibilitychange"])addEventListener(f,()=>xt(d),{capture:!0,once:!0});E(f=>{n=h("LCP"),r=b(e,n,Pt,t.reportAllChanges),J(()=>{n.value=performance.now()-f.timeStamp,r(!0)})})}})},Rt=[800,1800],G=e=>{document.prerendering?V(()=>G(e)):document.readyState!=="complete"?addEventListener("load",()=>G(e),!0):setTimeout(e)},_t=(e,t={})=>{let i=h("TTFB"),r=b(e,i,Rt,t.reportAllChanges);G(()=>{let n=Y();n&&(i.value=Math.max(n.responseStart-L(),0),i.entries=[n],r(!0),E(()=>{i=h("TTFB",0),r=b(e,i,Rt,t.reportAllChanges),r(!0)}))})};var H={lcp:null,cls:null,inp:null,fcp:null,ttfb:null},I=!1,W=null;function $t(){if(I)return;Object.values(H).every(t=>t!==null)&&et()}function et(){I||(I=!0,W&&(clearTimeout(W),W=null),s("Sending web vitals data:",H),p("performance",{eventName:"web-vitals",webVitals:H}))}function x(e){if(I)return;let t=e.name.toLowerCase();H[t]=e.value,s(`Collected ${t}:`,e.value),$t()}function Mt(){if(!l.trackWebVitals){s("Web vitals tracking is disabled.");return}s("Initializing web vitals tracking...");try{Ot(x),Lt(x),Dt(x),tt(x),_t(x),W=setTimeout(()=>{I||(s("Web vitals timeout reached, sending collected metrics."),et())},l.webVitalsTimeout||2e4),window.addEventListener("beforeunload",()=>{I||et()}),s("Web vitals tracking initialized successfully.")}catch(e){o("Error setting up web vitals tracking:",e)}}var T=!1,Bt={init:e=>{if(T){o("Rybbit SDK already initialized. Call init() only once.");return}ct(e)&&(T=!0,s("Config:",m({},l)),pt(),mt(),Mt())},pageview:e=>{if(!T){o("Rybbit SDK not initialized. Call rybbit.init() first.");return}p("pageview",{pathOverride:e})},event:(e,t)=>{if(!T){o("Rybbit SDK not initialized. Call rybbit.init() first.");return}if(!e){o("Event name is required and must be a string.");return}p("custom_event",{eventName:e,properties:t})},outbound:(e,t="",i="_self")=>{if(!T){o("Rybbit SDK not initialized. Call rybbit.init() first.");return}if(!e){o("Outbound link URL is required and must be a string.");return}p("outbound",{properties:{url:e,text:t,target:i}})},identify:e=>{if(!T){o("Rybbit SDK not initialized. Call rybbit.init() first.");return}dt(e)},clearUserId:()=>{if(!T){o("Rybbit SDK not initialized. Call rybbit.init() first.");return}ft()},getUserId:()=>T?gt():(o("Rybbit SDK not initialized. Call rybbit.init() first."),null),cleanup:ht},he=Bt;export{he as default};
|
|
7
|
+
var at=Object.defineProperty;var ye=Object.getOwnPropertySymbols;var ot=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable;var J=(e,t,r)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,b=(e,t)=>{for(var r in t||(t={}))ot.call(t,r)&&J(e,r,t[r]);if(ye)for(var r of ye(t))st.call(t,r)&&J(e,r,t[r]);return e};var v=(e,t,r)=>J(e,typeof t!="symbol"?t+"":t,r);function ve(e,t){let r=null;return function(...n){let i=this;r!==null&&clearTimeout(r),r=setTimeout(()=>{r=null,e.apply(i,n)},t)}}function ke(e){try{let t=window.location.hostname,r=new URL(e,window.location.href).hostname;return!!r&&r!==t}catch(t){return!1}}function lt(e){try{let t="__DOUBLE_ASTERISK_TOKEN__",r="__SINGLE_ASTERISK_TOKEN__",i=e.replace(/\*\*/g,t).replace(/\*/g,r).replace(/[.+?^${}()|[\]\\]/g,"\\$&");i=i.replace(/\//g,"\\/");let s=i.replace(new RegExp(t,"g"),".*").replace(new RegExp(r,"g"),"[^/]+");return new RegExp("^"+s+"$")}catch(t){return a(`Invalid pattern: ${e}`,t),null}}function G(e,t=[]){if(!t||t.length===0)return null;for(let r of t){let n=lt(r);if(n&&n.test(e))return r}return null}function o(...e){c.debug&&console.log("[Rybbit]",...e)}function a(...e){c.debug&&console.error("[Rybbit Error]",...e)}function R(){let e=new URL(window.location.href),t=e.pathname;return e.hash&&(t+=e.hash),t}var D={debounce:500,skipPatterns:[],maskPatterns:[],debug:!1},k={autoTrackPageviews:!0,autoTrackSpaRoutes:!0,trackQuerystring:!0,trackOutboundLinks:!0,trackWebVitals:!1,captureErrors:!1,enableSessionReplay:!1},W=null,c=new Proxy({},{get:(e,t)=>{var r,n;return W?W[t]:(t!=="debug"&&a("Rybbit SDK accessed before initialization. Call rybbit.init() first."),(n=(r=D[t])!=null?r:k[t])!=null?n:void 0)},set:()=>(a("Rybbit config is read-only after initialization."),!1)});async function ct(e,t){var r,n,i,s,u,l,f;try{o("Fetching remote configuration...");let d=new AbortController,C=setTimeout(()=>d.abort(),3e3),w=await fetch(`${e}/site/${t}/tracking-config`,{signal:d.signal});if(clearTimeout(C),w.ok){let m=await w.json();return o("Remote configuration fetched successfully",m),{autoTrackPageviews:(r=m.trackInitialPageView)!=null?r:k.autoTrackPageviews,autoTrackSpaRoutes:(n=m.trackSpaNavigation)!=null?n:k.autoTrackSpaRoutes,trackQuerystring:(i=m.trackUrlParams)!=null?i:k.trackQuerystring,trackOutboundLinks:(s=m.trackOutbound)!=null?s:k.trackOutboundLinks,trackWebVitals:(u=m.webVitals)!=null?u:k.trackWebVitals,captureErrors:(l=m.trackErrors)!=null?l:k.captureErrors,enableSessionReplay:(f=m.sessionReplay)!=null?f:k.enableSessionReplay}}else return a(`Failed to fetch remote config: ${w.status}`),null}catch(d){return d.name==="AbortError"?a("Remote config fetch timed out"):a("Error fetching remote config:",d),null}}async function Ee(e){var f,d;if(W)return a("Rybbit SDK already initialized."),!1;if(typeof e!="object"||e===null)return a("Invalid configuration provided to rybbit.init(). Expected an object."),!1;let t=e.analyticsHost;if(!t||t.trim()==="")return a("`analyticsHost` is required in Rybbit config and must be a non-empty string."),!1;let r=t.replace(/\/$/,""),n=e.siteId;if(!n||n.trim()==="")return a("`siteId` is required in Rybbit config and must be a non-empty string."),!1;let s=await ct(r,n)||k,u=Array.isArray(e.skipPatterns)?e.skipPatterns:D.skipPatterns,l=Array.isArray(e.maskPatterns)?e.maskPatterns:D.maskPatterns;return W={analyticsHost:r,siteId:n,debounce:Math.max(0,(f=e.debounce)!=null?f:D.debounce),skipPatterns:u,maskPatterns:l,debug:(d=e.debug)!=null?d:D.debug,replayPrivacyConfig:e.replayPrivacyConfig,autoTrackPageviews:s.autoTrackPageviews,autoTrackSpaRoutes:s.autoTrackSpaRoutes,trackQuerystring:s.trackQuerystring,trackOutboundLinks:s.trackOutboundLinks,trackWebVitals:s.trackWebVitals,captureErrors:s.captureErrors,enableSessionReplay:s.enableSessionReplay},!0}var E=null,Y=!1;try{let e=localStorage.getItem("rybbit-user-id");e&&(E=e),localStorage.getItem("disable-rybbit")!==null&&(Y=!0)}catch(e){a("localStorage unavailable")}typeof window!="undefined"&&window.__RYBBIT_OPTOUT__&&(Y=!0);function p(e,t={}){if(Y){o("Opted out of tracking.");return}if(!c||!c.analyticsHost||!c.siteId){a("Rybbit config not available. Ensure rybbit.init() was called successfully.");return}let{eventName:r,properties:n,pathOverride:i,webVitals:s}=t;if((e==="custom_event"||e==="performance")&&!r){a("Event name is required and must be a string for performance or custom events.");return}try{let u=new URL(window.location.href),l,f="";if(e==="pageview"&&typeof i=="string"&&i.trim()){o(`Using path override: ${i}`);try{let N=new URL(i,"http://dummybase");l=N.pathname,f=N.search||"",o(`Parsed override path: ${l}, search: ${f}`)}catch(N){a(`Invalid pathOverride format: ${i}. Using window location.`),l=R(),f=c.trackQuerystring?u.search:""}}else l=R(),f=c.trackQuerystring?u.search:"";if(e!=="performance"&&G(l,c.skipPatterns)){o(`Skipping track for path: ${l}`);return}let d=G(l,c.maskPatterns);d&&e!=="performance"&&(o(`Masking path ${l} as ${d}`),l=d,f="");let C=b(b(b(b({site_id:c.siteId,hostname:u.hostname,pathname:l,querystring:f,screenWidth:window.screen.width,screenHeight:window.screen.height,language:navigator.language,page_title:document.title,referrer:document.referrer||"direct",type:e},(e==="custom_event"||e==="performance")&&{event_name:r}),(e==="custom_event"||e==="outbound")&&Object.keys(n!=null?n:{}).length>0&&{properties:JSON.stringify(n)}),e==="performance"&&s&&b({},s)),E&&{user_id:E});o("Sending track event:",C);let w=JSON.stringify(C),m=`${c.analyticsHost}/track`;navigator.sendBeacon?navigator.sendBeacon(m,new Blob([w],{type:"application/json"}))||(a("sendBeacon failed, falling back to fetch."),Se(m,w)):Se(m,w)}catch(u){a("Error during tracking:",u)}}function Se(e,t){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:t,mode:"cors",keepalive:!0}).catch(r=>{a("Fetch request failed:",r)})}function Te(e){if(e.trim()===""){a("User ID must be a non-empty string");return}E=e.trim();try{localStorage.setItem("rybbit-user-id",E),o("User identified:",E)}catch(t){a("Could not persist user ID to localStorage")}}function we(){E=null;try{localStorage.removeItem("rybbit-user-id"),o("User ID cleared")}catch(e){a("Could not remove user ID from localStorage")}}function X(){return E}var S,$=!1,O=[],Z="";function Ce(){if($){o("Automatic tracking already set up.");return}if(!c.autoTrackPageviews){o("Automatic pageview tracking is disabled.");return}if(o("Setting up automatic tracking..."),Z=R(),S=c.debounce&&c.debounce>0?ve(()=>{let e=R();Re(e),p("pageview")},c.debounce):()=>{let e=R();Re(e),p("pageview")},requestAnimationFrame(()=>{S()}),c.autoTrackSpaRoutes){o("Setting up SPA route change tracking.");let e=history.pushState,t=history.replaceState;history.pushState=function(...r){e.apply(this,r),S()},history.replaceState=function(...r){t.apply(this,r),S()},window.addEventListener("popstate",S)}else o("SPA route change tracking is disabled.");window.addEventListener("hashchange",S),$=!0}function Pe(){o("Setting up data attribute and outbound link tracking."),document.addEventListener("click",Ie,!0)}function Ie(e){if(!(e.target instanceof Element))return;let t=e.target;for(;t;){if(t.hasAttribute("data-rybbit-event")){let r=t.getAttribute("data-rybbit-event");if(r){let n={};for(let i of t.attributes)if(i.name.startsWith("data-rybbit-prop-")){let s=i.name.replace("data-rybbit-prop-","");n[s]=i.value}o("Data attribute event triggered:",r,n),p("custom_event",{eventName:r,properties:n})}break}t=t.parentElement}if(c.trackOutboundLinks&&e.target instanceof Element){let r=e.target.closest("a");if(r&&r.href&&ke(r.href)){o("Outbound link clicked:",r.href);let n={url:r.href,text:r.innerText||r.textContent||"",target:r.target||"_self"};p("outbound",{properties:n})}}}function Le(e){return O.push(e),o("Page change callback added"),()=>{O=O.filter(t=>t!==e),o("Page change callback removed")}}function Re(e){let t=Z;Z=e,t!==e&&(o(`Page changed from ${t} to ${e}`),O.forEach(r=>{try{r(e,t)}catch(n){a("Error in page change callback:",n)}}))}function xe(){$&&(o("Cleaning up automatic tracking listeners."),window.removeEventListener("popstate",S),window.removeEventListener("hashchange",S),document.removeEventListener("click",Ie,!0),O=[],$=!1)}var $e=-1,I=e=>{addEventListener("pageshow",t=>{t.persisted&&($e=t.timeStamp,e(t))},!0)},h=(e,t,r,n)=>{let i,s;return u=>{t.value>=0&&(u||n)&&(s=t.value-(i!=null?i:0),(s||i===void 0)&&(i=t.value,t.delta=s,t.rating=((l,f)=>l>f[1]?"poor":l>f[0]?"needs-improvement":"good")(t.value,r),e(t)))}},se=e=>{requestAnimationFrame(()=>requestAnimationFrame(()=>e()))},le=()=>{let e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},A=()=>{var t;let e=le();return(t=e==null?void 0:e.activationStart)!=null?t:0},y=(e,t=-1)=>{let r=le(),n="navigate";return $e>=0?n="back-forward-cache":r&&(document.prerendering||A()>0?n="prerender":document.wasDiscarded?n="restore":r.type&&(n=r.type.replace(/_/g,"-"))),{name:e,value:t,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:n}},ee=new WeakMap;function ce(e,t){return ee.get(e)||ee.set(e,new t),ee.get(e)}var re=class{constructor(){v(this,"t");v(this,"i",0);v(this,"o",[])}h(t){var i;if(t.hadRecentInput)return;let r=this.o[0],n=this.o.at(-1);this.i&&r&&n&&t.startTime-n.startTime<1e3&&t.startTime-r.startTime<5e3?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),(i=this.t)==null||i.call(this,t)}},_=(e,t,r={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){let n=new PerformanceObserver(i=>{Promise.resolve().then(()=>{t(i.getEntries())})});return n.observe(b({type:e,buffered:!0},r)),n}}catch(n){}},ue=e=>{let t=!1;return()=>{t||(e(),t=!0)}},P=-1,De=()=>document.visibilityState!=="hidden"||document.prerendering?1/0:0,B=e=>{document.visibilityState==="hidden"&&P>-1&&(P=e.type==="visibilitychange"?e.timeStamp:0,ut())},Oe=()=>{addEventListener("visibilitychange",B,!0),addEventListener("prerenderingchange",B,!0)},ut=()=>{removeEventListener("visibilitychange",B,!0),removeEventListener("prerenderingchange",B,!0)},Ve=()=>{var e;if(P<0){let t=A(),r=document.prerendering||(e=globalThis.performance.getEntriesByType("visibility-state").filter(n=>n.name==="hidden"&&n.startTime>t)[0])==null?void 0:e.startTime;P=r!=null?r:De(),Oe(),I(()=>{setTimeout(()=>{P=De(),Oe()})})}return{get firstHiddenTime(){return P}}},z=e=>{document.prerendering?addEventListener("prerenderingchange",()=>e(),!0):e()},Ae=[1800,3e3],de=(e,t={})=>{z(()=>{let r=Ve(),n,i=y("FCP"),s=_("paint",u=>{for(let l of u)l.name==="first-contentful-paint"&&(s.disconnect(),l.startTime<r.firstHiddenTime&&(i.value=Math.max(l.startTime-A(),0),i.entries.push(l),n(!0)))});s&&(n=h(e,i,Ae,t.reportAllChanges),I(u=>{i=y("FCP"),n=h(e,i,Ae,t.reportAllChanges),se(()=>{i.value=performance.now()-u.timeStamp,n(!0)})}))})},_e=[.1,.25],Be=(e,t={})=>{de(ue(()=>{let r,n=y("CLS",0),i=ce(t,re),s=l=>{for(let f of l)i.h(f);i.i>n.value&&(n.value=i.i,n.entries=i.o,r())},u=_("layout-shift",s);u&&(r=h(e,n,_e,t.reportAllChanges),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&(s(u.takeRecords()),r(!0))}),I(()=>{i.i=0,n=y("CLS",0),r=h(e,n,_e,t.reportAllChanges),se(()=>r())}),setTimeout(r))}))},ze=0,te=1/0,V=0,dt=e=>{for(let t of e)t.interactionId&&(te=Math.min(te,t.interactionId),V=Math.max(V,t.interactionId),ze=V?(V-te)/7+1:0)},ne,Me=()=>{var e;return ne?ze:(e=performance.interactionCount)!=null?e:0},ft=()=>{"interactionCount"in performance||ne||(ne=_("event",dt,{type:"event",buffered:!0,durationThreshold:0}))},Ue=0,ie=class{constructor(){v(this,"u",[]);v(this,"l",new Map);v(this,"m");v(this,"v")}p(){Ue=Me(),this.u.length=0,this.l.clear()}P(){let t=Math.min(this.u.length-1,Math.floor((Me()-Ue)/50));return this.u[t]}h(t){var i,s;if((i=this.m)==null||i.call(this,t),!t.interactionId&&t.entryType!=="first-input")return;let r=this.u.at(-1),n=this.l.get(t.interactionId);if(n||this.u.length<10||t.duration>r.T){if(n?t.duration>n.T?(n.entries=[t],n.T=t.duration):t.duration===n.T&&t.startTime===n.entries[0].startTime&&n.entries.push(t):(n={id:t.interactionId,entries:[t],T:t.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort((u,l)=>l.T-u.T),this.u.length>10){let u=this.u.splice(10);for(let l of u)this.l.delete(l.id)}(s=this.v)==null||s.call(this,n)}}},Ke=e=>{let t=globalThis.requestIdleCallback||setTimeout;document.visibilityState==="hidden"?e():(e=ue(e),document.addEventListener("visibilitychange",e,{once:!0}),t(()=>{e(),document.removeEventListener("visibilitychange",e)}))},Fe=[200,500],je=(e,t={})=>{globalThis.PerformanceEventTiming&&"interactionId"in PerformanceEventTiming.prototype&&z(()=>{var l;ft();let r,n=y("INP"),i=ce(t,ie),s=f=>{Ke(()=>{for(let C of f)i.h(C);let d=i.P();d&&d.T!==n.value&&(n.value=d.T,n.entries=d.entries,r())})},u=_("event",s,{durationThreshold:(l=t.durationThreshold)!=null?l:40});r=h(e,n,Fe,t.reportAllChanges),u&&(u.observe({type:"first-input",buffered:!0}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&(s(u.takeRecords()),r(!0))}),I(()=>{i.p(),n=y("INP"),r=h(e,n,Fe,t.reportAllChanges)}))})},ae=class{constructor(){v(this,"m")}h(t){var r;(r=this.m)==null||r.call(this,t)}},Ne=[2500,4e3],He=(e,t={})=>{z(()=>{let r=Ve(),n,i=y("LCP"),s=ce(t,ae),u=f=>{t.reportAllChanges||(f=f.slice(-1));for(let d of f)s.h(d),d.startTime<r.firstHiddenTime&&(i.value=Math.max(d.startTime-A(),0),i.entries=[d],n())},l=_("largest-contentful-paint",u);if(l){n=h(e,i,Ne,t.reportAllChanges);let f=ue(()=>{u(l.takeRecords()),l.disconnect(),n(!0)});for(let d of["keydown","click","visibilitychange"])addEventListener(d,()=>Ke(f),{capture:!0,once:!0});I(d=>{i=y("LCP"),n=h(e,i,Ne,t.reportAllChanges),se(()=>{i.value=performance.now()-d.timeStamp,n(!0)})})}})},We=[800,1800],oe=e=>{document.prerendering?z(()=>oe(e)):document.readyState!=="complete"?addEventListener("load",()=>oe(e),!0):setTimeout(e)},qe=(e,t={})=>{let r=y("TTFB"),n=h(e,r,We,t.reportAllChanges);oe(()=>{let i=le();i&&(r.value=Math.max(i.responseStart-A(),0),r.entries=[i],n(!0),I(()=>{r=y("TTFB",0),n=h(e,r,We,t.reportAllChanges),n(!0)}))})};var j={lcp:null,cls:null,inp:null,fcp:null,ttfb:null},L=!1,K=null;function gt(){if(L)return;Object.values(j).every(t=>t!==null)&&fe()}function fe(){L||(L=!0,K&&(clearTimeout(K),K=null),o("Sending web vitals data:",j),p("performance",{eventName:"web-vitals",webVitals:j}))}function M(e){if(L)return;let t=e.name.toLowerCase();j[t]=e.value,o(`Collected ${t}:`,e.value),gt()}function Qe(){if(!c.trackWebVitals){o("Web vitals tracking is disabled.");return}o("Initializing web vitals tracking...");try{He(M),Be(M),je(M),de(M),qe(M),K=setTimeout(()=>{L||(o("Web vitals timeout reached, sending collected metrics."),fe())},2e4),window.addEventListener("beforeunload",()=>{L||fe()}),o("Web vitals tracking initialized successfully.")}catch(e){a("Error setting up web vitals tracking:",e)}}var U=null,F=null;function Je(){c.captureErrors&&(o("Setting up error tracking"),U=e=>{pt(e)},F=e=>{mt(e)},window.addEventListener("error",U),window.addEventListener("unhandledrejection",F))}function Ge(){U&&(window.removeEventListener("error",U),U=null),F&&(window.removeEventListener("unhandledrejection",F),F=null),o("Error tracking cleaned up")}function pt(e){var s,u;let t=window.location.origin,r=e.filename||"";if(r)try{if(new URL(r).origin!==t){o("Skipping third-party error:",r);return}}catch(l){}let n=((s=e.error)==null?void 0:s.stack)||"";if(!r&&n&&!n.includes(t)){o("Skipping third-party error based on stack trace");return}let i={message:(e.message||"Unknown error").substring(0,500),stack:n.substring(0,2e3),filename:r||void 0,lineno:e.lineno||void 0,colno:e.colno||void 0,timestamp:Date.now()};H(((u=e.error)==null?void 0:u.name)||"Error",i)}function mt(e){let t="Unhandled promise rejection",r="";e.reason instanceof Error?(t=e.reason.message||t,r=e.reason.stack||""):typeof e.reason=="string"?t=e.reason:e.reason&&typeof e.reason=="object"&&(t=JSON.stringify(e.reason));let n={message:t.substring(0,500),stack:r.substring(0,2e3),timestamp:Date.now()};H("UnhandledRejection",n)}function H(e,t,r){let n=b({error_name:e,message:t.message},r);t.stack&&(n.stack=t.stack),t.filename&&(n.filename=t.filename),t.lineno&&(n.line_number=t.lineno),t.colno&&(n.column_number=t.colno),p("error",{eventName:e,properties:n})}function Ye(e,t){var r,n;if(!c.captureErrors){a("Error tracking is not enabled. Set captureErrors: true in config.");return}if(e instanceof ErrorEvent){let i={message:(e.message||"Unknown error").substring(0,500),stack:(((r=e.error)==null?void 0:r.stack)||"").substring(0,2e3),filename:e.filename||void 0,lineno:e.lineno||void 0,colno:e.colno||void 0,timestamp:Date.now()};H(((n=e.error)==null?void 0:n.name)||"Error",i,t)}else{let i={message:(e.message||"Unknown error").substring(0,500),stack:(e.stack||"").substring(0,2e3),timestamp:Date.now()};H(e.name||"Error",i,t)}}var Q=null,x=!1,ge=null,T=[],q,pe=null,me;function bt(){return`${Date.now()}-${Math.random().toString(36).substring(2,15)}`}async function Xe(e){if(c.enableSessionReplay){me=e,pe=bt();try{Q=(await import("rrweb")).record,o("rrweb loaded successfully"),Ze()}catch(t){a("Failed to load rrweb. Make sure it's installed as a peer dependency:",t)}}}function Ze(){var e;if(!(x||!Q||!c.enableSessionReplay))try{let t=c.replayPrivacyConfig||{},r={emit:n=>{ht({type:n.type,data:n.data,timestamp:n.timestamp||Date.now()})},recordCanvas:!1,collectFonts:!1,checkoutEveryNms:6e4,checkoutEveryNth:500,maskAllInputs:(e=t.maskAllInputs)!=null?e:!0,maskInputOptions:{password:!0,email:!0},slimDOMOptions:{script:!1,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:!0,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0},sampling:{mousemove:!1,mouseInteraction:{MouseUp:!1,MouseDown:!1,Click:!0,ContextMenu:!1,DblClick:!0,Focus:!0,Blur:!0,TouchStart:!1,TouchEnd:!1},scroll:500,input:"last",media:800}};t.maskTextSelectors&&t.maskTextSelectors.length>0&&(r.maskTextSelector=t.maskTextSelectors.join(", ")),ge=Q(r),x=!0,yt(),o("Session replay recording started")}catch(t){a("Failed to start session replay recording:",t)}}function et(){if(!c.enableSessionReplay){a("Session replay is not enabled. Enable it via remote config.");return}if(!Q){a("rrweb is not loaded. Ensure it's installed as a peer dependency.");return}if(x){o("Session replay is already recording");return}Ze()}function be(){if(!x){o("Session replay is not currently recording");return}ge&&ge(),x=!1,rt(),T.length>0&&he(),o("Session replay recording stopped")}function tt(){return x}function ht(e){T.push(e),T.length>=250&&he()}function yt(){rt(),q=window.setInterval(()=>{T.length>0&&he()},5e3)}function rt(){q!==void 0&&(clearInterval(q),q=void 0)}function he(){if(T.length===0||!pe)return;let e=[...T];T=[];let t={sessionId:pe,siteId:c.siteId,userId:me,events:e,metadata:{pageUrl:window.location.href,screenWidth:window.screen.width,screenHeight:window.screen.height,language:navigator.language}};vt(t).catch(r=>{a("Failed to send session replay batch:",r),T.unshift(...e)})}async function vt(e){let t=`${c.analyticsHost}/replay`,r=JSON.stringify(e),n=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:r,mode:"cors",keepalive:!0});if(!n.ok)throw new Error(`Failed to send replay batch: ${n.status}`);o(`Session replay batch sent: ${e.events.length} events`)}function nt(e){me=e}function it(){be()}var g=!1,kt={init:async e=>{if(g){a("Rybbit SDK already initialized. Call init() only once.");return}await Ee(e)&&(g=!0,o("Config:",b({},c)),Ce(),Pe(),Qe(),Je(),await Xe(X()||void 0))},pageview:e=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}p("pageview",{pathOverride:e})},event:(e,t)=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}if(!e){a("Event name is required and must be a string.");return}p("custom_event",{eventName:e,properties:t})},outbound:(e,t="",r="_self")=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}if(!e){a("Outbound link URL is required and must be a string.");return}p("outbound",{properties:{url:e,text:t,target:r}})},identify:e=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}Te(e),nt(e)},clearUserId:()=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}we()},getUserId:()=>g?X():(a("Rybbit SDK not initialized. Call rybbit.init() first."),null),captureError:(e,t)=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}Ye(e,t)},onPageChange:e=>g?Le(e):(a("Rybbit SDK not initialized. Call rybbit.init() first."),()=>{}),startSessionReplay:()=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}et()},stopSessionReplay:()=>{if(!g){a("Rybbit SDK not initialized. Call rybbit.init() first.");return}be()},isSessionReplayActive:()=>g?tt():(a("Rybbit SDK not initialized. Call rybbit.init() first."),!1),cleanup:()=>{xe(),Ge(),it(),g=!1}},nr=kt;export{nr as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rybbit/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Rybbit Web SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -35,8 +35,17 @@
|
|
|
35
35
|
"url": "https://github.com/rybbit-io/rybbit-js/issues"
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/rybbit-io/rybbit-js",
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"rrweb": "^2.0.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"rrweb": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
38
46
|
"devDependencies": {
|
|
39
47
|
"@types/node": "^22.14.1",
|
|
48
|
+
"rrweb": "^2.0.0-alpha.4",
|
|
40
49
|
"tsup": "^8.5.0",
|
|
41
50
|
"typescript": "^5.8.3",
|
|
42
51
|
"web-vitals": "^5.0.3"
|