@agentuity/frontend 0.1.10 → 0.1.11

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.
@@ -1,6 +1,6 @@
1
1
  // Auto-generated - do not edit
2
2
  // Minified analytics beacon script (overwrites TypeScript output)
3
- export const BEACON_SCRIPT = "/* @agentuity/frontend v0.1.10 */\n(()=>{function A(X){if(X===void 0||X===null)return\"\";try{let V=new WeakSet;return JSON.stringify(X,(Y,Z)=>{if(typeof Z===\"object\"&&Z!==null){if(V.has(Z))return\"[Circular]\";V.add(Z)}return Z})}catch(V){let Y=V instanceof Error?V.message:String(V);return console.warn(\"[Agentuity Analytics] Failed to stringify properties:\",Y),`[unserializable: ${Y}]`}}(function(){let X=window,V=document,Y=X.__AGENTUITY_ANALYTICS__;if(!Y||!Y.enabled)return;let Z=X;if(Y.isDevmode)console.debug(\"[Agentuity Analytics] Script loaded, init flag:\",Z.__AGENTUITY_BEACON_INIT__,\"path:\",location.pathname);if(Z.__AGENTUITY_BEACON_INIT__){if(Y.isDevmode)console.debug(\"[Agentuity Analytics] Already initialized, skipping\");return}Z.__AGENTUITY_BEACON_INIT__=!0;let J=Y,K=null,z=!1,C=Date.now(),Q=\"\",M={},q={id:\"\",timestamp:0,timezone_offset:0,url:\"\",path:\"\",referrer:\"\",title:\"\",screen_width:0,screen_height:0,viewport_width:0,viewport_height:0,device_pixel_ratio:1,user_agent:\"\",language:\"\",scroll_depth:0,time_on_page:0,scroll_events:[],custom_events:[]};function O(){return crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function T(){let x=new URLSearchParams(location.search),B={};return[\"utm_source\",\"utm_medium\",\"utm_campaign\",\"utm_term\",\"utm_content\"].forEach((G)=>{let W=x.get(G);if(W)B[G]=W}),B}function F(x){if(!x)return\"\";try{let B=new URL(x);return B.origin+B.pathname}catch{return x.split(\"?\")[0]}}function U(){q.id=O(),q.timestamp=Date.now(),q.timezone_offset=new Date().getTimezoneOffset(),q.url=F(location.href),q.path=location.pathname,q.referrer=F(V.referrer),q.title=V.title||\"\",q.screen_width=screen.width||0,q.screen_height=screen.height||0,q.viewport_width=innerWidth||0,q.viewport_height=innerHeight||0,q.device_pixel_ratio=devicePixelRatio||1,q.user_agent=navigator.userAgent||\"\",q.language=navigator.language||\"\";let x=T();for(let B in x)q[B]=x[B];if(q.scroll_events=[],q.custom_events=[],q.scroll_depth=0,z=!1,C=Date.now(),typeof performance<\"u\"&&performance.getEntriesByType){let B=performance.getEntriesByType(\"navigation\")[0];if(B)if(q.dom_ready=Math.round(B.domContentLoadedEventEnd-B.startTime),q.ttfb=Math.round(B.responseStart-B.requestStart),B.loadEventEnd>0)q.load_time=Math.round(B.loadEventEnd-B.startTime);else setTimeout(()=>{let G=performance.getEntriesByType(\"navigation\")[0];if(G&&G.loadEventEnd>0)q.load_time=Math.round(G.loadEventEnd-G.startTime)},0)}if(J.isDevmode)console.debug(\"[Agentuity Analytics] Session started (full init):\",q.id)}function j(){if(q.id=O(),q.timestamp=Date.now(),q.scroll_events=[],q.custom_events=[],q.scroll_depth=0,q.time_on_page=0,z=!1,C=Date.now(),J.isDevmode)console.debug(\"[Agentuity Analytics] Session started (soft reset):\",q.id)}fetch(\"https://agentuity.sh/location\").then((x)=>x.json()).then((x)=>{K=x;try{sessionStorage.setItem(\"agentuity_geo\",JSON.stringify(x))}catch{}}).catch(()=>{try{let x=sessionStorage.getItem(\"agentuity_geo\");if(x)K=JSON.parse(x)}catch{}});try{let x=sessionStorage.getItem(\"agentuity_geo\");if(x)K=JSON.parse(x)}catch{}function N(){return X.__AGENTUITY_SESSION__}function L(x=!1){if(z&&!x){if(J.isDevmode)console.debug(\"[Agentuity Analytics] send() skipped - already sent\");return}if(J.sampleRate!==void 0&&J.sampleRate<1&&Math.random()>J.sampleRate)return;if(z=!0,q.time_on_page=Date.now()-C,K){if(q.country=K.country||\"\",K.country_latitude)q.country_latitude=parseFloat(String(K.country_latitude));if(K.country_longitude)q.country_longitude=parseFloat(String(K.country_longitude));if(q.region=K.region||\"\",K.region_latitude)q.region_latitude=parseFloat(String(K.region_latitude));if(K.region_longitude)q.region_longitude=parseFloat(String(K.region_longitude));if(q.city=K.city||\"\",K.city_latitude)q.city_latitude=parseFloat(String(K.city_latitude));if(K.city_longitude)q.city_longitude=parseFloat(String(K.city_longitude));if(q.timezone=K.timezone||\"\",K.latitude)q.latitude=parseFloat(String(K.latitude));if(K.longitude)q.longitude=parseFloat(String(K.longitude))}if(q.cls)q.cls=Math.round(q.cls*1000)/1000;let B=N(),G=localStorage.getItem(\"agentuity_visitor_id\")||\"vid_\"+O();try{localStorage.setItem(\"agentuity_visitor_id\",G)}catch{}let W={org_id:J.orgId,project_id:J.projectId,thread_id:B?.threadId||\"\",visitor_id:G,user_id:Q,user_traits:M,is_devmode:J.isDevmode,pageview:q};try{sessionStorage.removeItem(\"agentuity_pending_pageview\")}catch{}if(J.isDevmode){console.debug(\"[Agentuity Analytics]\",JSON.stringify(W,null,2));return}let _=JSON.stringify(W);if(navigator.sendBeacon)navigator.sendBeacon(\"/_agentuity/webanalytics/collect\",_);else fetch(\"/_agentuity/webanalytics/collect\",{method:\"POST\",body:_,keepalive:!0}).catch(()=>{})}if(V.addEventListener(\"visibilitychange\",()=>{if(J.isDevmode)console.debug(\"[Agentuity Analytics] visibilitychange:\",V.visibilityState,\"sent:\",z);if(V.visibilityState===\"hidden\")L();else if(V.visibilityState===\"visible\")j()}),X.addEventListener(\"pagehide\",()=>{if(J.isDevmode){console.debug(\"[Agentuity Analytics] pagehide event\");try{sessionStorage.setItem(\"agentuity_last_event\",`pagehide:${Date.now()}:${q.path}`)}catch{}}L()}),X.addEventListener(\"beforeunload\",()=>{if(J.isDevmode){console.debug(\"[Agentuity Analytics] beforeunload event\");try{sessionStorage.setItem(\"agentuity_last_event\",`beforeunload:${Date.now()}:${q.path}`)}catch{}}L()}),J.isDevmode)try{let x=sessionStorage.getItem(\"agentuity_last_event\");if(x)console.debug(\"[Agentuity Analytics] Previous page event:\",x),sessionStorage.removeItem(\"agentuity_last_event\")}catch{}try{let x=sessionStorage.getItem(\"agentuity_pending_pageview\");if(x){sessionStorage.removeItem(\"agentuity_pending_pageview\");let B=JSON.parse(x);if(B.pageview?.path!==location.pathname)if(J.isDevmode)console.debug(\"[Agentuity Analytics] Sending unsent data from previous page:\",B.pageview?.path),console.debug(\"[Agentuity Analytics]\",JSON.stringify(B,null,2));else{let G=JSON.stringify(B);if(navigator.sendBeacon)navigator.sendBeacon(\"/_agentuity/webanalytics/collect\",G)}}}catch{}function H(){try{q.time_on_page=Date.now()-C;let x=N(),B=localStorage.getItem(\"agentuity_visitor_id\")||\"vid_\"+O(),G={org_id:J.orgId,project_id:J.projectId,thread_id:x?.threadId||\"\",visitor_id:B,user_id:Q,user_traits:M,is_devmode:J.isDevmode,pageview:{...q}};sessionStorage.setItem(\"agentuity_pending_pageview\",JSON.stringify(G))}catch{}}if(setInterval(H,2000),V.addEventListener(\"click\",H,{passive:!0}),V.addEventListener(\"scroll\",H,{passive:!0,once:!0}),J.isDevmode)console.debug(\"[Agentuity Analytics] Beacon initialized, visibility:\",V.visibilityState);if(J.trackScroll!==!1){let B=function(){let G=X.scrollY||V.documentElement.scrollTop,W=V.documentElement.scrollHeight-V.documentElement.clientHeight;return W<=0?100:Math.min(100,Math.round(G/W*100))};var D=B;let x=new Set;X.addEventListener(\"scroll\",()=>{let G=B();if(G>q.scroll_depth)q.scroll_depth=G;[25,50,75,100].forEach((W)=>{if(G>=W&&!x.has(W))x.add(W),q.scroll_events.push({depth:W,timestamp:Date.now()-C})})},{passive:!0})}if(J.trackWebVitals!==!1&&typeof PerformanceObserver<\"u\"){try{let x=new PerformanceObserver((B)=>{B.getEntries().forEach((G)=>{if(G.name===\"first-contentful-paint\")q.fcp=Math.round(G.startTime),x.disconnect()})});x.observe({type:\"paint\",buffered:!0})}catch{}try{new PerformanceObserver((x)=>{let B=x.getEntries();if(B.length)q.lcp=Math.round(B[B.length-1].startTime)}).observe({type:\"largest-contentful-paint\",buffered:!0})}catch{}try{new PerformanceObserver((x)=>{x.getEntries().forEach((B)=>{let G=B;if(!G.hadRecentInput&&G.value)q.cls=(q.cls||0)+G.value})}).observe({type:\"layout-shift\",buffered:!0})}catch{}try{new PerformanceObserver((x)=>{x.getEntries().forEach((B)=>{let G=B;if(G.duration&&G.duration>(q.inp||0))q.inp=Math.round(G.duration)})}).observe({type:\"event\",buffered:!0})}catch{}}if(J.trackSPANavigation!==!1){let _=function(){let $=location.pathname+location.search;if($!==G){if(J.isDevmode)console.debug(\"[Agentuity Analytics] SPA navigation:\",G,\"->\",$);L(!0),G=$,W=location.href,U()}};var R=_;let{pushState:x,replaceState:B}=history,G=location.pathname+location.search,W=location.href;if(J.isDevmode)console.debug(\"[Agentuity Analytics] SPA tracking enabled, initial path:\",G);history.pushState=function(...$){x.apply(this,$),setTimeout(_,0)},history.replaceState=function(...$){B.apply(this,$),setTimeout(_,0)},X.addEventListener(\"popstate\",_),setInterval(()=>{if(location.href!==W)W=location.href,_()},200)}if(J.trackClicks!==!1)V.addEventListener(\"click\",(x)=>{let B=x.target;if(!B)return;let G=B.closest(\"[data-analytics]\");if(!G)return;if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:\"click:\"+G.getAttribute(\"data-analytics\"),data:\"\"})},!0);if(J.trackErrors!==!1)X.addEventListener(\"error\",(x)=>{if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:\"error:js_error\",data:JSON.stringify({message:x.message||\"Unknown\",filename:x.filename||\"\",lineno:x.lineno||0})})}),X.addEventListener(\"unhandledrejection\",(x)=>{if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:\"error:unhandled_rejection\",data:JSON.stringify({message:x.reason instanceof Error?x.reason.message:String(x.reason)})})});if(V.readyState===\"complete\")U();else X.addEventListener(\"load\",U);X.agentuityAnalytics={track(x,B){if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:x,data:A(B)})},identify(x,B){if(Q=x,B){M={};for(let[G,W]of Object.entries(B))M[G]=String(W)}},flush:()=>L(!0)}})();})();\n";
3
+ export const BEACON_SCRIPT = "/* @agentuity/frontend v0.1.11 */\n(()=>{function A(X){if(X===void 0||X===null)return\"\";try{let V=new WeakSet;return JSON.stringify(X,(Y,Z)=>{if(typeof Z===\"object\"&&Z!==null){if(V.has(Z))return\"[Circular]\";V.add(Z)}return Z})}catch(V){let Y=V instanceof Error?V.message:String(V);return console.warn(\"[Agentuity Analytics] Failed to stringify properties:\",Y),`[unserializable: ${Y}]`}}(function(){let X=window,V=document,Y=X.__AGENTUITY_ANALYTICS__;if(!Y||!Y.enabled)return;let Z=X;if(Y.isDevmode)console.debug(\"[Agentuity Analytics] Script loaded, init flag:\",Z.__AGENTUITY_BEACON_INIT__,\"path:\",location.pathname);if(Z.__AGENTUITY_BEACON_INIT__){if(Y.isDevmode)console.debug(\"[Agentuity Analytics] Already initialized, skipping\");return}Z.__AGENTUITY_BEACON_INIT__=!0;let J=Y,K=null,z=!1,C=Date.now(),Q=\"\",M={},q={id:\"\",timestamp:0,timezone_offset:0,url:\"\",path:\"\",referrer:\"\",title:\"\",screen_width:0,screen_height:0,viewport_width:0,viewport_height:0,device_pixel_ratio:1,user_agent:\"\",language:\"\",scroll_depth:0,time_on_page:0,scroll_events:[],custom_events:[]};function O(){return crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function T(){let x=new URLSearchParams(location.search),B={};return[\"utm_source\",\"utm_medium\",\"utm_campaign\",\"utm_term\",\"utm_content\"].forEach((G)=>{let W=x.get(G);if(W)B[G]=W}),B}function F(x){if(!x)return\"\";try{let B=new URL(x);return B.origin+B.pathname}catch{return x.split(\"?\")[0]}}function U(){q.id=O(),q.timestamp=Date.now(),q.timezone_offset=new Date().getTimezoneOffset(),q.url=F(location.href),q.path=location.pathname,q.referrer=F(V.referrer),q.title=V.title||\"\",q.screen_width=screen.width||0,q.screen_height=screen.height||0,q.viewport_width=innerWidth||0,q.viewport_height=innerHeight||0,q.device_pixel_ratio=devicePixelRatio||1,q.user_agent=navigator.userAgent||\"\",q.language=navigator.language||\"\";let x=T();for(let B in x)q[B]=x[B];if(q.scroll_events=[],q.custom_events=[],q.scroll_depth=0,z=!1,C=Date.now(),typeof performance<\"u\"&&performance.getEntriesByType){let B=performance.getEntriesByType(\"navigation\")[0];if(B)if(q.dom_ready=Math.round(B.domContentLoadedEventEnd-B.startTime),q.ttfb=Math.round(B.responseStart-B.requestStart),B.loadEventEnd>0)q.load_time=Math.round(B.loadEventEnd-B.startTime);else setTimeout(()=>{let G=performance.getEntriesByType(\"navigation\")[0];if(G&&G.loadEventEnd>0)q.load_time=Math.round(G.loadEventEnd-G.startTime)},0)}if(J.isDevmode)console.debug(\"[Agentuity Analytics] Session started (full init):\",q.id)}function j(){if(q.id=O(),q.timestamp=Date.now(),q.scroll_events=[],q.custom_events=[],q.scroll_depth=0,q.time_on_page=0,z=!1,C=Date.now(),J.isDevmode)console.debug(\"[Agentuity Analytics] Session started (soft reset):\",q.id)}fetch(\"https://agentuity.sh/location\").then((x)=>x.json()).then((x)=>{K=x;try{sessionStorage.setItem(\"agentuity_geo\",JSON.stringify(x))}catch{}}).catch(()=>{try{let x=sessionStorage.getItem(\"agentuity_geo\");if(x)K=JSON.parse(x)}catch{}});try{let x=sessionStorage.getItem(\"agentuity_geo\");if(x)K=JSON.parse(x)}catch{}function N(){return X.__AGENTUITY_SESSION__}function L(x=!1){if(z&&!x){if(J.isDevmode)console.debug(\"[Agentuity Analytics] send() skipped - already sent\");return}if(J.sampleRate!==void 0&&J.sampleRate<1&&Math.random()>J.sampleRate)return;if(z=!0,q.time_on_page=Date.now()-C,K){if(q.country=K.country||\"\",K.country_latitude)q.country_latitude=parseFloat(String(K.country_latitude));if(K.country_longitude)q.country_longitude=parseFloat(String(K.country_longitude));if(q.region=K.region||\"\",K.region_latitude)q.region_latitude=parseFloat(String(K.region_latitude));if(K.region_longitude)q.region_longitude=parseFloat(String(K.region_longitude));if(q.city=K.city||\"\",K.city_latitude)q.city_latitude=parseFloat(String(K.city_latitude));if(K.city_longitude)q.city_longitude=parseFloat(String(K.city_longitude));if(q.timezone=K.timezone||\"\",K.latitude)q.latitude=parseFloat(String(K.latitude));if(K.longitude)q.longitude=parseFloat(String(K.longitude))}if(q.cls)q.cls=Math.round(q.cls*1000)/1000;let B=N(),G=localStorage.getItem(\"agentuity_visitor_id\")||\"vid_\"+O();try{localStorage.setItem(\"agentuity_visitor_id\",G)}catch{}let W={org_id:J.orgId,project_id:J.projectId,thread_id:B?.threadId||\"\",visitor_id:G,user_id:Q,user_traits:M,is_devmode:J.isDevmode,pageview:q};try{sessionStorage.removeItem(\"agentuity_pending_pageview\")}catch{}if(J.isDevmode){console.debug(\"[Agentuity Analytics]\",JSON.stringify(W,null,2));return}let _=JSON.stringify(W);if(navigator.sendBeacon)navigator.sendBeacon(\"/_agentuity/webanalytics/collect\",_);else fetch(\"/_agentuity/webanalytics/collect\",{method:\"POST\",body:_,keepalive:!0}).catch(()=>{})}if(V.addEventListener(\"visibilitychange\",()=>{if(J.isDevmode)console.debug(\"[Agentuity Analytics] visibilitychange:\",V.visibilityState,\"sent:\",z);if(V.visibilityState===\"hidden\")L();else if(V.visibilityState===\"visible\")j()}),X.addEventListener(\"pagehide\",()=>{if(J.isDevmode){console.debug(\"[Agentuity Analytics] pagehide event\");try{sessionStorage.setItem(\"agentuity_last_event\",`pagehide:${Date.now()}:${q.path}`)}catch{}}L()}),X.addEventListener(\"beforeunload\",()=>{if(J.isDevmode){console.debug(\"[Agentuity Analytics] beforeunload event\");try{sessionStorage.setItem(\"agentuity_last_event\",`beforeunload:${Date.now()}:${q.path}`)}catch{}}L()}),J.isDevmode)try{let x=sessionStorage.getItem(\"agentuity_last_event\");if(x)console.debug(\"[Agentuity Analytics] Previous page event:\",x),sessionStorage.removeItem(\"agentuity_last_event\")}catch{}try{let x=sessionStorage.getItem(\"agentuity_pending_pageview\");if(x){sessionStorage.removeItem(\"agentuity_pending_pageview\");let B=JSON.parse(x);if(B.pageview?.path!==location.pathname)if(J.isDevmode)console.debug(\"[Agentuity Analytics] Sending unsent data from previous page:\",B.pageview?.path),console.debug(\"[Agentuity Analytics]\",JSON.stringify(B,null,2));else{let G=JSON.stringify(B);if(navigator.sendBeacon)navigator.sendBeacon(\"/_agentuity/webanalytics/collect\",G)}}}catch{}function H(){try{q.time_on_page=Date.now()-C;let x=N(),B=localStorage.getItem(\"agentuity_visitor_id\")||\"vid_\"+O(),G={org_id:J.orgId,project_id:J.projectId,thread_id:x?.threadId||\"\",visitor_id:B,user_id:Q,user_traits:M,is_devmode:J.isDevmode,pageview:{...q}};sessionStorage.setItem(\"agentuity_pending_pageview\",JSON.stringify(G))}catch{}}if(setInterval(H,2000),V.addEventListener(\"click\",H,{passive:!0}),V.addEventListener(\"scroll\",H,{passive:!0,once:!0}),J.isDevmode)console.debug(\"[Agentuity Analytics] Beacon initialized, visibility:\",V.visibilityState);if(J.trackScroll!==!1){let B=function(){let G=X.scrollY||V.documentElement.scrollTop,W=V.documentElement.scrollHeight-V.documentElement.clientHeight;return W<=0?100:Math.min(100,Math.round(G/W*100))};var D=B;let x=new Set;X.addEventListener(\"scroll\",()=>{let G=B();if(G>q.scroll_depth)q.scroll_depth=G;[25,50,75,100].forEach((W)=>{if(G>=W&&!x.has(W))x.add(W),q.scroll_events.push({depth:W,timestamp:Date.now()-C})})},{passive:!0})}if(J.trackWebVitals!==!1&&typeof PerformanceObserver<\"u\"){try{let x=new PerformanceObserver((B)=>{B.getEntries().forEach((G)=>{if(G.name===\"first-contentful-paint\")q.fcp=Math.round(G.startTime),x.disconnect()})});x.observe({type:\"paint\",buffered:!0})}catch{}try{new PerformanceObserver((x)=>{let B=x.getEntries();if(B.length)q.lcp=Math.round(B[B.length-1].startTime)}).observe({type:\"largest-contentful-paint\",buffered:!0})}catch{}try{new PerformanceObserver((x)=>{x.getEntries().forEach((B)=>{let G=B;if(!G.hadRecentInput&&G.value)q.cls=(q.cls||0)+G.value})}).observe({type:\"layout-shift\",buffered:!0})}catch{}try{new PerformanceObserver((x)=>{x.getEntries().forEach((B)=>{let G=B;if(G.duration&&G.duration>(q.inp||0))q.inp=Math.round(G.duration)})}).observe({type:\"event\",buffered:!0})}catch{}}if(J.trackSPANavigation!==!1){let _=function(){let $=location.pathname+location.search;if($!==G){if(J.isDevmode)console.debug(\"[Agentuity Analytics] SPA navigation:\",G,\"->\",$);L(!0),G=$,W=location.href,U()}};var R=_;let{pushState:x,replaceState:B}=history,G=location.pathname+location.search,W=location.href;if(J.isDevmode)console.debug(\"[Agentuity Analytics] SPA tracking enabled, initial path:\",G);history.pushState=function(...$){x.apply(this,$),setTimeout(_,0)},history.replaceState=function(...$){B.apply(this,$),setTimeout(_,0)},X.addEventListener(\"popstate\",_),setInterval(()=>{if(location.href!==W)W=location.href,_()},200)}if(J.trackClicks!==!1)V.addEventListener(\"click\",(x)=>{let B=x.target;if(!B)return;let G=B.closest(\"[data-analytics]\");if(!G)return;if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:\"click:\"+G.getAttribute(\"data-analytics\"),data:\"\"})},!0);if(J.trackErrors!==!1)X.addEventListener(\"error\",(x)=>{if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:\"error:js_error\",data:JSON.stringify({message:x.message||\"Unknown\",filename:x.filename||\"\",lineno:x.lineno||0})})}),X.addEventListener(\"unhandledrejection\",(x)=>{if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:\"error:unhandled_rejection\",data:JSON.stringify({message:x.reason instanceof Error?x.reason.message:String(x.reason)})})});if(V.readyState===\"complete\")U();else X.addEventListener(\"load\",U);X.agentuityAnalytics={track(x,B){if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:x,data:A(B)})},identify(x,B){if(Q=x,B){M={};for(let[G,W]of Object.entries(B))M[G]=String(W)}},flush:()=>L(!0)}})();})();\n";
4
4
 
5
5
  export function validateBeaconScript() {
6
6
  if (!BEACON_SCRIPT || BEACON_SCRIPT.length === 0) {
package/dist/beacon.js CHANGED
@@ -1,2 +1,2 @@
1
- /* @agentuity/frontend v0.1.10 */
1
+ /* @agentuity/frontend v0.1.11 */
2
2
  (()=>{function A(X){if(X===void 0||X===null)return"";try{let V=new WeakSet;return JSON.stringify(X,(Y,Z)=>{if(typeof Z==="object"&&Z!==null){if(V.has(Z))return"[Circular]";V.add(Z)}return Z})}catch(V){let Y=V instanceof Error?V.message:String(V);return console.warn("[Agentuity Analytics] Failed to stringify properties:",Y),`[unserializable: ${Y}]`}}(function(){let X=window,V=document,Y=X.__AGENTUITY_ANALYTICS__;if(!Y||!Y.enabled)return;let Z=X;if(Y.isDevmode)console.debug("[Agentuity Analytics] Script loaded, init flag:",Z.__AGENTUITY_BEACON_INIT__,"path:",location.pathname);if(Z.__AGENTUITY_BEACON_INIT__){if(Y.isDevmode)console.debug("[Agentuity Analytics] Already initialized, skipping");return}Z.__AGENTUITY_BEACON_INIT__=!0;let J=Y,K=null,z=!1,C=Date.now(),Q="",M={},q={id:"",timestamp:0,timezone_offset:0,url:"",path:"",referrer:"",title:"",screen_width:0,screen_height:0,viewport_width:0,viewport_height:0,device_pixel_ratio:1,user_agent:"",language:"",scroll_depth:0,time_on_page:0,scroll_events:[],custom_events:[]};function O(){return crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function T(){let x=new URLSearchParams(location.search),B={};return["utm_source","utm_medium","utm_campaign","utm_term","utm_content"].forEach((G)=>{let W=x.get(G);if(W)B[G]=W}),B}function F(x){if(!x)return"";try{let B=new URL(x);return B.origin+B.pathname}catch{return x.split("?")[0]}}function U(){q.id=O(),q.timestamp=Date.now(),q.timezone_offset=new Date().getTimezoneOffset(),q.url=F(location.href),q.path=location.pathname,q.referrer=F(V.referrer),q.title=V.title||"",q.screen_width=screen.width||0,q.screen_height=screen.height||0,q.viewport_width=innerWidth||0,q.viewport_height=innerHeight||0,q.device_pixel_ratio=devicePixelRatio||1,q.user_agent=navigator.userAgent||"",q.language=navigator.language||"";let x=T();for(let B in x)q[B]=x[B];if(q.scroll_events=[],q.custom_events=[],q.scroll_depth=0,z=!1,C=Date.now(),typeof performance<"u"&&performance.getEntriesByType){let B=performance.getEntriesByType("navigation")[0];if(B)if(q.dom_ready=Math.round(B.domContentLoadedEventEnd-B.startTime),q.ttfb=Math.round(B.responseStart-B.requestStart),B.loadEventEnd>0)q.load_time=Math.round(B.loadEventEnd-B.startTime);else setTimeout(()=>{let G=performance.getEntriesByType("navigation")[0];if(G&&G.loadEventEnd>0)q.load_time=Math.round(G.loadEventEnd-G.startTime)},0)}if(J.isDevmode)console.debug("[Agentuity Analytics] Session started (full init):",q.id)}function j(){if(q.id=O(),q.timestamp=Date.now(),q.scroll_events=[],q.custom_events=[],q.scroll_depth=0,q.time_on_page=0,z=!1,C=Date.now(),J.isDevmode)console.debug("[Agentuity Analytics] Session started (soft reset):",q.id)}fetch("https://agentuity.sh/location").then((x)=>x.json()).then((x)=>{K=x;try{sessionStorage.setItem("agentuity_geo",JSON.stringify(x))}catch{}}).catch(()=>{try{let x=sessionStorage.getItem("agentuity_geo");if(x)K=JSON.parse(x)}catch{}});try{let x=sessionStorage.getItem("agentuity_geo");if(x)K=JSON.parse(x)}catch{}function N(){return X.__AGENTUITY_SESSION__}function L(x=!1){if(z&&!x){if(J.isDevmode)console.debug("[Agentuity Analytics] send() skipped - already sent");return}if(J.sampleRate!==void 0&&J.sampleRate<1&&Math.random()>J.sampleRate)return;if(z=!0,q.time_on_page=Date.now()-C,K){if(q.country=K.country||"",K.country_latitude)q.country_latitude=parseFloat(String(K.country_latitude));if(K.country_longitude)q.country_longitude=parseFloat(String(K.country_longitude));if(q.region=K.region||"",K.region_latitude)q.region_latitude=parseFloat(String(K.region_latitude));if(K.region_longitude)q.region_longitude=parseFloat(String(K.region_longitude));if(q.city=K.city||"",K.city_latitude)q.city_latitude=parseFloat(String(K.city_latitude));if(K.city_longitude)q.city_longitude=parseFloat(String(K.city_longitude));if(q.timezone=K.timezone||"",K.latitude)q.latitude=parseFloat(String(K.latitude));if(K.longitude)q.longitude=parseFloat(String(K.longitude))}if(q.cls)q.cls=Math.round(q.cls*1000)/1000;let B=N(),G=localStorage.getItem("agentuity_visitor_id")||"vid_"+O();try{localStorage.setItem("agentuity_visitor_id",G)}catch{}let W={org_id:J.orgId,project_id:J.projectId,thread_id:B?.threadId||"",visitor_id:G,user_id:Q,user_traits:M,is_devmode:J.isDevmode,pageview:q};try{sessionStorage.removeItem("agentuity_pending_pageview")}catch{}if(J.isDevmode){console.debug("[Agentuity Analytics]",JSON.stringify(W,null,2));return}let _=JSON.stringify(W);if(navigator.sendBeacon)navigator.sendBeacon("/_agentuity/webanalytics/collect",_);else fetch("/_agentuity/webanalytics/collect",{method:"POST",body:_,keepalive:!0}).catch(()=>{})}if(V.addEventListener("visibilitychange",()=>{if(J.isDevmode)console.debug("[Agentuity Analytics] visibilitychange:",V.visibilityState,"sent:",z);if(V.visibilityState==="hidden")L();else if(V.visibilityState==="visible")j()}),X.addEventListener("pagehide",()=>{if(J.isDevmode){console.debug("[Agentuity Analytics] pagehide event");try{sessionStorage.setItem("agentuity_last_event",`pagehide:${Date.now()}:${q.path}`)}catch{}}L()}),X.addEventListener("beforeunload",()=>{if(J.isDevmode){console.debug("[Agentuity Analytics] beforeunload event");try{sessionStorage.setItem("agentuity_last_event",`beforeunload:${Date.now()}:${q.path}`)}catch{}}L()}),J.isDevmode)try{let x=sessionStorage.getItem("agentuity_last_event");if(x)console.debug("[Agentuity Analytics] Previous page event:",x),sessionStorage.removeItem("agentuity_last_event")}catch{}try{let x=sessionStorage.getItem("agentuity_pending_pageview");if(x){sessionStorage.removeItem("agentuity_pending_pageview");let B=JSON.parse(x);if(B.pageview?.path!==location.pathname)if(J.isDevmode)console.debug("[Agentuity Analytics] Sending unsent data from previous page:",B.pageview?.path),console.debug("[Agentuity Analytics]",JSON.stringify(B,null,2));else{let G=JSON.stringify(B);if(navigator.sendBeacon)navigator.sendBeacon("/_agentuity/webanalytics/collect",G)}}}catch{}function H(){try{q.time_on_page=Date.now()-C;let x=N(),B=localStorage.getItem("agentuity_visitor_id")||"vid_"+O(),G={org_id:J.orgId,project_id:J.projectId,thread_id:x?.threadId||"",visitor_id:B,user_id:Q,user_traits:M,is_devmode:J.isDevmode,pageview:{...q}};sessionStorage.setItem("agentuity_pending_pageview",JSON.stringify(G))}catch{}}if(setInterval(H,2000),V.addEventListener("click",H,{passive:!0}),V.addEventListener("scroll",H,{passive:!0,once:!0}),J.isDevmode)console.debug("[Agentuity Analytics] Beacon initialized, visibility:",V.visibilityState);if(J.trackScroll!==!1){let B=function(){let G=X.scrollY||V.documentElement.scrollTop,W=V.documentElement.scrollHeight-V.documentElement.clientHeight;return W<=0?100:Math.min(100,Math.round(G/W*100))};var D=B;let x=new Set;X.addEventListener("scroll",()=>{let G=B();if(G>q.scroll_depth)q.scroll_depth=G;[25,50,75,100].forEach((W)=>{if(G>=W&&!x.has(W))x.add(W),q.scroll_events.push({depth:W,timestamp:Date.now()-C})})},{passive:!0})}if(J.trackWebVitals!==!1&&typeof PerformanceObserver<"u"){try{let x=new PerformanceObserver((B)=>{B.getEntries().forEach((G)=>{if(G.name==="first-contentful-paint")q.fcp=Math.round(G.startTime),x.disconnect()})});x.observe({type:"paint",buffered:!0})}catch{}try{new PerformanceObserver((x)=>{let B=x.getEntries();if(B.length)q.lcp=Math.round(B[B.length-1].startTime)}).observe({type:"largest-contentful-paint",buffered:!0})}catch{}try{new PerformanceObserver((x)=>{x.getEntries().forEach((B)=>{let G=B;if(!G.hadRecentInput&&G.value)q.cls=(q.cls||0)+G.value})}).observe({type:"layout-shift",buffered:!0})}catch{}try{new PerformanceObserver((x)=>{x.getEntries().forEach((B)=>{let G=B;if(G.duration&&G.duration>(q.inp||0))q.inp=Math.round(G.duration)})}).observe({type:"event",buffered:!0})}catch{}}if(J.trackSPANavigation!==!1){let _=function(){let $=location.pathname+location.search;if($!==G){if(J.isDevmode)console.debug("[Agentuity Analytics] SPA navigation:",G,"->",$);L(!0),G=$,W=location.href,U()}};var R=_;let{pushState:x,replaceState:B}=history,G=location.pathname+location.search,W=location.href;if(J.isDevmode)console.debug("[Agentuity Analytics] SPA tracking enabled, initial path:",G);history.pushState=function(...$){x.apply(this,$),setTimeout(_,0)},history.replaceState=function(...$){B.apply(this,$),setTimeout(_,0)},X.addEventListener("popstate",_),setInterval(()=>{if(location.href!==W)W=location.href,_()},200)}if(J.trackClicks!==!1)V.addEventListener("click",(x)=>{let B=x.target;if(!B)return;let G=B.closest("[data-analytics]");if(!G)return;if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:"click:"+G.getAttribute("data-analytics"),data:""})},!0);if(J.trackErrors!==!1)X.addEventListener("error",(x)=>{if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:"error:js_error",data:JSON.stringify({message:x.message||"Unknown",filename:x.filename||"",lineno:x.lineno||0})})}),X.addEventListener("unhandledrejection",(x)=>{if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:"error:unhandled_rejection",data:JSON.stringify({message:x.reason instanceof Error?x.reason.message:String(x.reason)})})});if(V.readyState==="complete")U();else X.addEventListener("load",U);X.agentuityAnalytics={track(x,B){if(q.custom_events.length<1000)q.custom_events.push({timestamp:Date.now(),name:x,data:A(B)})},identify(x,B){if(Q=x,B){M={};for(let[G,W]of Object.entries(B))M[G]=String(W)}},flush:()=>L(!0)}})();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentuity/frontend",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Agentuity employees and contributors",
6
6
  "type": "module",
@@ -26,10 +26,10 @@
26
26
  "prepublishOnly": "bun run clean && bun run build"
27
27
  },
28
28
  "dependencies": {
29
- "@agentuity/core": "0.1.10"
29
+ "@agentuity/core": "0.1.11"
30
30
  },
31
31
  "devDependencies": {
32
- "@agentuity/test-utils": "0.1.10",
32
+ "@agentuity/test-utils": "0.1.11",
33
33
  "@types/bun": "latest",
34
34
  "bun-types": "latest",
35
35
  "typescript": "^5.9.0"