UNPKG

quanta.tools

Version:

Quanta.js: JS SDK for Quanta Tools

3 lines (2 loc) 22.1 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(){return t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e,n,r){return new(n||(n=Promise))((function(i,s){function a(t){try{c(r.next(t))}catch(t){s(t)}}function o(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,o)}c((r=r.apply(t,e||[])).next())}))}function n(t,e){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=o(0),a.throw=o(1),a.return=o(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function o(o){return function(c){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,o[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,s=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=s.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}return a}function s(t,e,n){if(n||2===arguments.length)for(var r,i=0,s=e.length;i<s;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var a="",o="";function c(t){return t.href.slice(t.origin.length)}var u=function(){function u(){}var l;return u.makeAsyncStorage=function(){var t=this;return{getItem:function(r){return e(t,void 0,void 0,(function(){return n(this,(function(t){return[2,localStorage.getItem(r)]}))}))},setItem:function(r,i){return e(t,void 0,void 0,(function(){return n(this,(function(t){return[2,localStorage.setItem(r,i)]}))}))}}},u.initialize=function(t){this.initializeAsync(t).catch(console.error)},u.loadAppId=function(){return e(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,this.asyncStorage.getItem("tools.quanta.appId")];case 1:return[2,t.sent()]}}))}))},u.setAppId=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this.asyncStorage.setItem("tools.quanta.appId",t)];case 1:return[2,e.sent()]}}))}))},u.initializeAsync=function(t){return e(this,void 0,void 0,(function(){var e,r,i,s,a,o,c,u;return n(this,(function(n){switch(n.label){case 0:return this._initialized?t?(this._appId=t,[4,this.setAppId(t)]):[3,2]:[3,3];case 1:n.sent(),n.label=2;case 2:return[2];case 3:return 0==this._initializing++?[3,7]:[4,new Promise((function(t){return setTimeout(t,10)}))];case 4:return n.sent(),this._initializingPromise?[4,this._initializingPromise]:[3,6];case 5:n.sent(),n.label=6;case 6:return[2];case 7:return e=function(){},this._initializingPromise=new Promise((function(t){e=t})),this.isServerSide()?(console.log("[Quanta] Skipping client sdk call on server."),[2]):(this.parseScriptTagAttributes(),r=this,null===(c=null!=t?t:this.getAppIdFromScriptTag())||void 0===c?[3,8]:(i=c,[3,10]));case 8:return[4,this.loadAppId()];case 9:i=n.sent(),n.label=10;case 10:return r._appId=null!==(u=i)&&void 0!==u?u:"",this._appId?[4,this.setAppId(this._appId)]:(this.debugWarn("No Quanta app ID provided. Analytics will not be sent."),[2]);case 11:return n.sent(),s=this,[4,this.loadOrCreateId()];case 12:return s._id=n.sent(),a=this,[4,this.loadOrCreateInstallDate()];case 13:return a._installDate=n.sent(),[4,this.asyncStorage.getItem("tools.quanta.ab")];case 14:return o=n.sent()||"",this._abLetters=this.getAbLetters(o),this._abDict=this.getAbDict(o),this.setupUrlChangeListeners(),[4,this.loadQueue()];case 15:return n.sent(),[4,this.processQueue()];case 16:return n.sent(),this.isDebug()&&this.checkClaimed().catch(console.error),this.debugLog("Quanta initialized"),this._initialized=!0,e(),[4,this.maybeSendViewEvent()];case 17:return n.sent(),[2]}}))}))},u.setupUrlChangeListeners=function(){var t=this;if("undefined"!=typeof window){null===this._currentPath&&(this._currentPath=c(window.location)),window.addEventListener("popstate",(function(){t.handleUrlChange().catch(console.error)}));var e=history.pushState,n=history.replaceState;history.pushState=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];e.apply(this,t),l.handleUrlChange().catch(console.error)},history.replaceState=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];n.apply(this,t),l.handleUrlChange().catch(console.error)}}},u.handleUrlChange=function(){return e(this,void 0,void 0,(function(){var t;return n(this,(function(e){switch(e.label){case 0:return(t=c(window.location))===this._currentPath?[2]:(this._currentPath=t,this._isFirstViewEvent=!1,[4,this.maybeSendViewEvent()]);case 1:return e.sent(),[2]}}))}))},u.maybeSendViewEvent=function(){return e(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return this._initialized?[3,2]:[4,this.initializeAsync()];case 1:t.sent(),t.label=2;case 2:return this._skipAllViewEvents?[2]:this._skipFirstViewEvent&&this._isFirstViewEvent?(this._isFirstViewEvent=!1,[2]):this._skipNavigationViewEvents&&!this._isFirstViewEvent?[2]:[4,this.sendViewEvent()];case 3:return t.sent(),[2]}}))}))},u.sendViewEvent=function(){return e(this,void 0,void 0,(function(){var e,s,a,o,u,l,h,d,f,g,p,v,b,y,w,m,_,S,I;return n(this,(function(n){switch(n.label){case 0:return this._initialized?[3,2]:[4,this.initializeAsync()];case 1:n.sent(),n.label=2;case 2:e=new URL(window.location.href),s=e.searchParams,a={};try{for(o=r(s.entries()),u=o.next();!u.done;u=o.next())l=i(u.value,2),y=l[0],w=l[1],y.startsWith("utm_")&&(a[y.replace(/^utm_/,"")]=w,s.delete(y))}catch(t){m={error:t}}finally{try{u&&!u.done&&(_=o.return)&&_.call(o)}finally{if(m)throw m.error}}e.search=s.toString(),h=c(e),d=t({path:h},a),document.referrer&&(d.referrer=document.referrer),f=4,g=-1;try{for(p=r(Object.entries(d)),v=p.next();!v.done;v=p.next())b=i(v.value,2),y=b[0],w=b[1],f+=y.length+w.length,g+=2}catch(t){S={error:t}}finally{try{v&&!v.done&&(I=p.return)&&I.call(p)}finally{if(S)throw S.error}}return d.path=d.path.slice(0,200-f-g),[4,this.logAsync("view",d)];case 3:return n.sent(),[2]}}))}))},u.parseScriptTagAttributes=function(){var t=this.getScriptTag();t&&(this._skipFirstViewEvent=t.hasAttribute("data-skip-first-view-event"),this._skipNavigationViewEvents=t.hasAttribute("data-skip-navigation-view-events"),this._skipAllViewEvents=t.hasAttribute("data-skip-all-view-events"),t.hasAttribute("data-enable-debug-logs")&&this.enableLogging())},u.getScriptTag=function(){if("undefined"==typeof window)return null;for(var t=document.getElementsByTagName("script"),e=0;e<t.length;e++)if(t[e].src.match(/^((https?:)?\/\/)?js\.quanta\.tools/))return t[e];return null},u.getAppIdFromScriptTag=function(){try{var t=this.getScriptTag();if(!t)throw new Error("Script tag not found");var e=t.src;if(!e)throw new Error("src not found");var n=e.match(/^((https?:)?\/\/)?js\.quanta\.tools\/app\/([^\/]+)\.js(\?[^\?]*)?$/i);if(n&&n[3])return n[3]}catch(t){}return this.debugError("Failed to extract Quanta app ID from script tag. Please make sure the script tag is loaded correctly:"),this.debugError('<script src="https://js.quanta.tools/app/{appId}.js"><\/script>'),null},u.log=function(t,e){void 0===e&&(e={}),this.logWithRevenue(t,0,e)},u.logAsync=function(t){return e(this,arguments,void 0,(function(t,e){return void 0===e&&(e={}),n(this,(function(n){switch(n.label){case 0:return[4,this.logWithRevenueAsync(t,0,e)];case 1:return n.sent(),[2]}}))}))},u.logWithRevenue=function(t,e,n){void 0===e&&(e=0),void 0===n&&(n={}),this.logWithRevenueAsync(t,e,n).catch(console.error)},u.isServerSide=function(){return"undefined"==typeof window},u.logWithRevenueAsync=function(t){return e(this,arguments,void 0,(function(t,e,i){var s,a,c,u,l,h,d,f,g,p,v;return void 0===e&&(e=0),void 0===i&&(i={}),n(this,(function(n){switch(n.label){case 0:if(this.isServerSide())return console.log("[Quanta] Skipping client sdk call on server."),[2];if(this._initialized||this.initialize(),t.length>200&&(this.debugWarn("Event name is too long. Event name + args should be 200 characters or less. It will be truncated."),t=t.substring(0,200)),s="","string"==typeof i)s=this.safe(i,!0);else{a=Object.keys(i).sort();try{for(c=r(a),u=c.next();!u.done;u=c.next())l=u.value,h=this.safe(l,!1),d=this.safe(i[l],!1),s+="".concat(h).concat(o).concat(d).concat(o)}catch(t){p={error:t}}finally{try{u&&!u.done&&(v=c.return)&&v.call(c)}finally{if(p)throw p.error}}s.length>0&&(s=s.substring(0,s.length-1))}return t.length+s.length>200&&(this.debugWarn("Added arguments are too long. Event name + args should be 200 characters or less. They will be truncated."),s=s.substring(0,200-t.length)),f=this.getUserData(),g=this.stringForDouble(e),[4,this.enqueueEvent({appId:this._appId,userData:f,event:this.safe(t),revenue:g,addedArguments:this.safe(s,!0),time:new Date,abLetters:this._abLetters})];case 1:return n.sent(),[2]}}))}))},u.abTest=function(t){return this._initialized?this._abDict[t.toLowerCase()]||"A":(console.error("[Quanta] Ab test called in sync method before initialization. Please make sure to call initialize() first, or use abTestAsync() instead."),this.initialize(),"A")},u.abTestAsync=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return this._initialized?[3,2]:[4,this.initializeAsync()];case 1:e.sent(),e.label=2;case 2:return[2,this._abDict[t.toLowerCase()]||"A"]}}))}))},u.setId=function(t){this.setIdAsync(t).catch(console.error)},u.setIdAsync=function(t){return e(this,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return""!==this._id?[2]:(e=t,this.isValidUUID(e)&&(e=this.shortenUuid(e)),this._id=e,[4,this.asyncStorage.setItem("tools.quanta.id",this._id)]);case 1:return n.sent(),22!==this._id.length&&this.debugWarn("The ID ".concat(this._id," does not look like a valid UUID or Quanta ID. Only use UUIDs or shortened Quanta IDs as user IDs.")),[2]}}))}))},u.getId=function(){return this._id},u.loadOrCreateId=function(){return e(this,void 0,void 0,(function(){var t,e;return n(this,(function(n){switch(n.label){case 0:return[4,this.asyncStorage.getItem("tools.quanta.id")];case 1:return(t=n.sent())?[2,t]:(e=this.shortenUuid(this.generateUuid()),[4,this.asyncStorage.setItem("tools.quanta.id",e)]);case 2:return n.sent(),[2,e]}}))}))},u.loadOrCreateInstallDate=function(){return e(this,void 0,void 0,(function(){var t,e;return n(this,(function(n){switch(n.label){case 0:return[4,this.asyncStorage.getItem("tools.quanta.install")];case 1:return(t=n.sent())?[2,parseInt(t,10)]:(e=Math.floor(Date.now()/1e3),[4,this.asyncStorage.setItem("tools.quanta.install",e.toString())]);case 2:return n.sent(),[2,e]}}))}))},u.systemLanguageProvider=function(){return navigator.language},u.getBundleId=function(){return window.location.hostname},u.getVersion=function(){return"1.0.0"},u.getUserData=function(){var t=this.getDeviceInfo(),e=this.getOSInfoSafe(),n=this.getBundleId(),r=this.isDebug()?1:0,i=this.getVersion(),s=this.systemLanguageProvider().replace("-","_"),o="";return o+="".concat(this._id),o+="".concat(a).concat(this.safe(t)),o+="".concat(a).concat(this.safe(e)),o+="".concat(a).concat(this.safe(n)),o+="".concat(a).concat(r),o+="".concat(a).concat(this.safe(i)),o+="".concat(a).concat(s),o+="".concat(a).concat(this._installDate)},u.getDeviceInfo=function(){var t,e=navigator.userAgent;return/Edg\//.test(e)?"Edge":/OPR\/|Opera\/|Opera Mini\//.test(e)?"Opera":/Vivaldi\//.test(e)?"Vivaldi":/YaBrowser\//.test(e)?"Yandex":/Brave\//.test(e)||/Chrome/.test(e)&&(null===(t=navigator.brave)||void 0===t?void 0:t.isBrave)?"Brave":/SamsungBrowser\//.test(e)?"Samsung Browser":/UCWEB\/|UCBrowser\//.test(e)?"UC Browser":/QQBrowser\//.test(e)?"QQ Browser":/Maxthon\//.test(e)?"Maxthon":/DuckDuckGo\//.test(e)?"DuckDuckGo":/Whale\//.test(e)?"Whale":/Puffin\//.test(e)?"Puffin":/Firefox\//.test(e)?"Firefox":/Chrome\//.test(e)&&!/Chromium\//.test(e)?"Chrome":/Chromium\//.test(e)?"Chromium":!/Safari\//.test(e)||/Chrome\//.test(e)||/Chromium\//.test(e)?/MSIE|Trident\//.test(e)?"Internet Explorer":/SeaMonkey\//.test(e)?"SeaMonkey":/Thunderbird\//.test(e)?"Thunderbird":/AOLShield\//.test(e)?"AOL Shield":/Coast\//.test(e)?"Coast":/Focus\//.test(e)?"Focus":/Klar\//.test(e)?"Klar":/Falkon\//.test(e)?"Falkon":/Konqueror\//.test(e)?"Konqueror":/Kindle\//.test(e)?"Kindle":"Browser":"Safari"},u.getOSInfo=function(){var t,e=navigator.userAgent;return/Windows NT 10/.test(e)?"Windows10":/Windows NT 6.3/.test(e)?"Windows8.1":/Windows NT 6.2/.test(e)?"Windows8":/Windows NT 6.1/.test(e)?"Windows7":/Mac OS X/.test(e)?(t=e.match(/Mac OS X (\d+[._]\d+[._\d]*)/))?"macOS".concat(t[1].replace(/_/g,".")):"macOS":/Android/.test(e)?(t=e.match(/Android (\d+\.\d+)/))?"Android".concat(t[1]):"Android":/iOS/.test(e)||/iPhone|iPad|iPod/.test(e)?(t=e.match(/OS (\d+_\d+)/))?"iOS".concat(t[1].replace(/_/g,".")):"iOS":/Linux/.test(e)?"Linux":"Unknown"},u.getOSInfoSafe=function(){return this.getOSInfo().slice(0,25)},u.isDebug=function(){return"localhost"===window.location.hostname||"127.0.0.1"===window.location.hostname},u.safe=function(t,e){return void 0===e&&(e=!1),e?t.replace(new RegExp(a,"g"),""):t.replace(new RegExp(a,"g"),"").replace(new RegExp(o,"g"),"")},u.stringForDouble=function(t){if(t>999999.99)return this.debugWarn("Value exceeds maximum allowed revenue of 999,999.99. Will be capped."),this.stringForDouble(999999.99);if(t<-999999.99)return this.debugWarn("Value is below minimum allowed revenue of -999,999.99. Will be capped."),this.stringForDouble(-999999.99);var e=t.toFixed(2);return e.endsWith(".00")?e.substring(0,e.length-3):e},u.enqueueEvent=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return this._queue.push(t),[4,this.saveQueue()];case 1:return e.sent(),this._isProcessing?[3,3]:[4,this.processQueue()];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},u.processQueue=function(){return e(this,void 0,void 0,(function(){var t,e,r;return n(this,(function(i){switch(i.label){case 0:if(this._isProcessing||0===this._queue.length)return[2];this._isProcessing=!0,t=0,e=function(){var e,i,s;return n(this,(function(n){switch(n.label){case 0:return t>0?(e=500*Math.pow(1.5,t-1),[4,new Promise((function(t){return setTimeout(t,e)}))]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,r.sendEvent(r._queue[0])];case 3:return i=n.sent(),s=(Date.now()-r._queue[0].time.getTime())/36e5,i||t>=27||s>48?(r._queue.shift(),t=0,[4,r.saveQueue()]):[3,5];case 4:return n.sent(),[3,6];case 5:t++,n.label=6;case 6:return[4,new Promise((function(t){return setTimeout(t,100)}))];case 7:return n.sent(),[2]}}))},r=this,i.label=1;case 1:return this._queue.length>0?[5,e()]:[3,3];case 2:return i.sent(),[3,1];case 3:return this._isProcessing=!1,[2]}}))}))},u.sendEvent=function(t){return e(this,void 0,void 0,(function(){var e,r,i,s,o,c,u,l;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,12,,13]),e="https://analytics-ingress.quanta.tools/ee/",r="",r+=t.appId,r+="".concat(a).concat(Math.floor(t.time.getTime()/1e3)),r+="".concat(a).concat(t.event),r+="".concat(a).concat(t.revenue),r+="".concat(a).concat(t.addedArguments),r+="".concat(a).concat(t.userData),t.abLetters&&(r+="".concat(a).concat(t.abLetters)),i={"Content-Type":"text/plain"},[4,this.asyncStorage.getItem("tools.quanta.ab.version")];case 1:return(s=n.sent())&&(i["X-AB-Version"]=s),[4,fetch(e,{method:"POST",headers:i,body:r})];case 2:if(!(o=n.sent()).ok)return[3,11];n.label=3;case 3:return n.trys.push([3,9,,10]),[4,o.text()];case 4:return(c=n.sent())?[4,this.asyncStorage.setItem("tools.quanta.ab",c)]:[3,6];case 5:n.sent(),this.setAbJson(c),n.label=6;case 6:return(u=o.headers.get("X-AB-Version"))?[4,this.asyncStorage.setItem("tools.quanta.ab.version",u)]:[3,8];case 7:n.sent(),n.label=8;case 8:return[3,10];case 9:return n.sent(),[3,10];case 10:return[2,!0];case 11:return[2,!1];case 12:return l=n.sent(),this.debugError("Failed to send event:",l),[2,!1];case 13:return[2]}}))}))},u.saveQueue=function(){return e(this,void 0,void 0,(function(){var t;return n(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.asyncStorage.setItem("tools.quanta.queue.tasks",JSON.stringify(this._queue))];case 1:return e.sent(),[3,3];case 2:return t=e.sent(),this.debugWarn("Failed to save queue to storage:",t),[3,3];case 3:return[2]}}))}))},u.loadQueue=function(){return e(this,void 0,void 0,(function(){var e,r,i;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.asyncStorage.getItem("tools.quanta.queue.tasks")];case 1:return(e=n.sent())&&(r=JSON.parse(e),this._queue=r.map((function(e){return t(t({},e),{time:new Date(e.time)})}))),[3,3];case 2:return i=n.sent(),this.debugWarn("Failed to load queue from storage:",i),[3,3];case 3:return[2]}}))}))},u.setAbJson=function(t){this._abLetters=this.getAbLetters(t),this._abDict=this.getAbDict(t)},u.getAbLetters=function(t){var e,n;if(!t)return"";try{var i=JSON.parse(t),s="";try{for(var a=r(i),o=a.next();!o.done;o=a.next())for(var c=o.value,u="".concat(this._id,".").concat(c.name[c.name.length-1]||""),l=this.stringToNumber(u),h=0,d=0;d<c.variants.length;d++)if((h+=c.variants[d])>l){s+="ABCDEFGHIJKLMNOPQRSTUVWXYZ"[d];break}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return s}catch(t){return this.debugWarn("Failed to parse AB test JSON:",t),""}},u.getAbDict=function(t){var e,n,i={};if(!t)return i;try{for(var s=JSON.parse(t),a=this._abLetters,o=0;o<s.length&&!(o>=a.length);o++){var c=s[o];try{for(var u=(e=void 0,r(c.name)),l=u.next();!l.done;l=u.next()){i[l.value.toLowerCase()]=a.substring(o,o+1)}}catch(t){e={error:t}}finally{try{l&&!l.done&&(n=u.return)&&n.call(u)}finally{if(e)throw e.error}}}return i}catch(t){return this.debugWarn("Failed to parse AB test JSON:",t),i}},u.stringToNumber=function(t){for(var e=0,n=0;n<t.length;n++){e=(e<<5)-e+t.charCodeAt(n),e|=0}return Math.abs(e%100)},u.generateUuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}))},u.shortenUuid=function(t){for(var e=t.replace(/-/g,""),n=new Uint8Array(16),r=0;r<16;r++)n[r]=parseInt(e.substring(2*r,2*r+2),16);return btoa(String.fromCharCode.apply(null,Array.from(n))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")},u.isValidUUID=function(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t)},u.shouldLog=function(){return null===this.loggingEnabled?this.isDebug():this.loggingEnabled},u.enableLogging=function(){this.loggingEnabled=!0},u.disableLogging=function(){this.loggingEnabled=!1},u.debugLog=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog()&&console.log.apply(console,s([],i(t),!1))},u.debugWarn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog()&&console.warn.apply(console,s([],i(t),!1))},u.debugError=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog()&&console.error.apply(console,s([],i(t),!1))},u.checkClaimed=function(){return e(this,void 0,void 0,(function(){var t;return n(this,(function(e){switch(e.label){case 0:if(!this._appId)return[2];e.label=1;case 1:return e.trys.push([1,4,,5]),[4,fetch("https://quanta.tools/api/claimed/".concat(this._appId))];case 2:return(t=e.sent()).ok?[4,t.json()]:[2];case 3:return e.sent().unClaimed?(console.log("%c\n :@@@ +@@+ @@@ \n @@ @: @@ @ @ @@ \n @@ @@ @@ @@ @@ @ \n @ @@ = @@ @ @ @@ = +\n @@@@:@@ @@ @@ @ @= @@ @@ @@@ @@=@@ \n :@@ @ @@ @@ @@@ @@@@ @@ @@ \n @@@@@@ @@ @@@@ @@@ @@ @@@ @@ \n @ \\@@@@ \\@@@@@ \\@@@@@ \\@@@@@ \\@@@@ \n","font-family:monospace;font-weight:600"),console.log("Welcome to Quanta! 🥳"),console.log("Your analytics are fully set up."),console.log("See your first events coming in and attach this app to your Quanta account at"),console.log("https://quanta.tools/setup/".concat(this._appId)),console.log(""),console.log("Once your app is attached to an account, this welcome message won't show up anymore. 🚮"),[3,5]):[2];case 4:return e.sent(),[3,5];case 5:return[2]}}))}))},l=u,u._initialized=!1,u._initializing=0,u._initializingPromise=null,u._id="",u._appId="",u._abLetters="",u._abDict={},u._queue=[],u._isProcessing=!1,u._installDate=0,u._skipFirstViewEvent=!1,u._skipNavigationViewEvents=!1,u._skipAllViewEvents=!1,u._isFirstViewEvent=!0,u._currentPath=null,u.asyncStorage=l.makeAsyncStorage(),u.loggingEnabled=null,u}();exports.Quanta=u,exports.default=u; //# sourceMappingURL=index.cjs.js.map