This commit is contained in:
1
examples/simple-js/aptabase.min.js
vendored
Normal file
1
examples/simple-js/aptabase.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var aptabase=(()=>{var d=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var s=(e,n)=>d(e,"name",{value:n,configurable:!0});var E=(e,n)=>{for(var t in n)d(e,t,{get:n[t],enumerable:!0})},N=(e,n,t,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of A(n))!D.call(e,r)&&r!==t&&d(e,r,{get:()=>n[r],enumerable:!(a=S(n,r))||a.enumerable});return e};var O=e=>N(d({},"__esModule",{value:!0}),e);var _={};E(_,{init:()=>y,trackEvent:()=>I});var o,i,V=typeof window<"u"&&typeof window.fetch<"u",x=typeof chrome<"u"&&!!chrome.runtime?.id,u=b(),c=new Date,f={US:"https://us.aptabase.com",EU:"https://eu.aptabase.com",DEV:"https://localhost:3000",SH:""};function g(e){let n=new Date,t=n.getTime()-c.getTime();return Math.floor(t/1e3)>e&&(u=b()),c=n,u}s(g,"inMemorySessionId");function b(){let e=Math.floor(Date.now()/1e3).toString(),n=Math.floor(Math.random()*1e8).toString().padStart(8,"0");return e+n}s(b,"newSessionId");function m(e){let n=e.split("-");return n.length!==3||f[n[1]]===void 0?(console.warn(`The Aptabase App Key "${e}" is invalid. Tracking will be disabled.`),!1):!0}s(m,"validateAppKey");function v(e,n){let t=e.split("-")[1];if(t==="SH"){if(!n?.host){console.warn("Host parameter must be defined when using Self-Hosted App Key. Tracking will be disabled.");return}return`${n.host}/api/v0/event`}return`${n?.host??f[t]}/api/v0/event`}s(v,"getApiUrl");async function w(e){if(!V&&!x){console.warn(`Aptabase: trackEvent requires a browser environment. Event "${e.eventName}" will be discarded.`);return}if(!e.appKey){console.warn(`Aptabase: init must be called before trackEvent. Event "${e.eventName}" will be discarded.`);return}try{let n=await fetch(e.apiUrl,{method:"POST",headers:{"Content-Type":"application/json","App-Key":e.appKey},credentials:"omit",body:JSON.stringify({timestamp:new Date().toISOString(),sessionId:e.sessionId,eventName:e.eventName,systemProps:{locale:e.locale??U(),isDebug:e.isDebug??T(),appVersion:e.appVersion??"",sdkVersion:e.sdkVersion},props:e.props})});if(n.status>=300){let t=await n.text();console.warn(`Failed to send event "${e.eventName}": ${n.status} ${t}`)}}catch(n){console.warn(`Failed to send event "${e.eventName}"`),console.warn(n)}}s(w,"sendEvent");function U(){if(o)return o;if(!(typeof navigator>"u"))return navigator.languages.length>0?o=navigator.languages[0]:o=navigator.language,o}s(U,"getBrowserLocale");function T(){return i!==void 0?i:typeof location>"u"?(i=!1,i):(i=location.hostname==="localhost",i)}s(T,"getIsDebug");var $=1*60*60,k="aptabase-web@0.4.3",h="",p,l;function y(e,n){m(e)&&(p=n?.apiUrl??v(e,n),h=e,l=n)}s(y,"init");async function I(e,n){if(!p)return;let t=g($);await w({apiUrl:p,sessionId:t,appKey:h,isDebug:l?.isDebug,appVersion:l?.appVersion,sdkVersion:k,eventName:e,props:n})}s(I,"trackEvent");typeof window<"u"&&(window.aptabase={init:y,trackEvent:I});return O(_);})();
|
||||
Reference in New Issue
Block a user