quanta.tools
Version:
Quanta.js: JS SDK for Quanta Tools
3 lines (2 loc) • 23.6 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};var e=function(){return e=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},e.apply(this,arguments)};function n(t,e,n,r){return new(n||(n=Promise))((function(i,s){function o(t){try{c(r.next(t))}catch(t){s(t)}}function a(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(o,a)}c((r=r.apply(t,e||[])).next())}))}function r(t,e){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function i(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 s(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,s=n.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(r=s.next()).done;)o.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 o}function o(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="",c="";function u(t){return t.href.slice(t.origin.length)}var l=new(function(o){function a(){return null!==o&&o.apply(this,arguments)||this}return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}(a,o),a.prototype.init=function(){this.initializeAsync(void 0,!0).catch((function(){}))},a.prototype.sendViewEvent=function(){return n(this,void 0,void 0,(function(){var t,n,o,a,c,l,h,p,d,f,g,y,v,b,w,m,_,S,I;return r(this,(function(r){switch(r.label){case 0:return this._initialized?[3,2]:[4,this.initializeAsync()];case 1:r.sent(),r.label=2;case 2:t=new URL(window.location.href),n=t.searchParams,o={};try{for(a=i(n.entries()),c=a.next();!c.done;c=a.next())l=s(c.value,2),b=l[0],w=l[1],b.startsWith("utm_")&&(o[b.replace(/^utm_/,"")]=w,n.delete(b))}catch(t){m={error:t}}finally{try{c&&!c.done&&(_=a.return)&&_.call(a)}finally{if(m)throw m.error}}t.search=n.toString(),h=u(t),p=e({path:h},o),document.referrer&&(p.referrer=document.referrer),d=4,f=-1;try{for(g=i(Object.entries(p)),y=g.next();!y.done;y=g.next())v=s(y.value,2),b=v[0],w=v[1],d+=b.length+w.length,f+=2}catch(t){S={error:t}}finally{try{y&&!y.done&&(I=g.return)&&I.call(g)}finally{if(S)throw S.error}}return p.path=p.path.slice(0,200-d-f),[4,this.logAsync("view",p)];case 3:return r.sent(),[2]}}))}))},a.prototype.handleUrlChange=function(){return n(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return(t=u(window.location))===this._currentPath?[2]:(this._currentPath=t,this._isFirstViewEvent=!1,[4,this.maybeSendViewEvent()]);case 1:return e.sent(),[2]}}))}))},a.prototype.makeAsyncStorage=function(){var t=this;return{getItem:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){return[2,localStorage.getItem(e)]}))}))},setItem:function(e,i){return n(t,void 0,void 0,(function(){return r(this,(function(t){return[2,localStorage.setItem(e,i)]}))}))}}},a.prototype.setupUrlChangeListeners=function(){var t=this;if("undefined"!=typeof window){null===this._currentPath&&(this._currentPath=u(window.location)),window.addEventListener("popstate",(function(){t.handleUrlChange().catch(console.error)}));var e=history.pushState,n=history.replaceState,r=this;history.pushState=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];e.apply(this,t),r.handleUrlChange().catch(console.error)},history.replaceState=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];n.apply(r,t),r.handleUrlChange().catch(console.error)}}},a.prototype.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},a.prototype.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},a.prototype.isServerSide=function(){return"undefined"==typeof window},a.prototype.systemLanguageProvider=function(){return navigator.language},a.prototype.getBundleId=function(){return window.location.hostname},a.prototype.getVersion=function(){return"1.0.0"},a.prototype.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"},a.prototype.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"},a.prototype.isDebug=function(){return"localhost"===window.location.hostname||"127.0.0.1"===window.location.hostname},a}(function(){function t(){this._initialized=!1,this._initializing=0,this._initializingPromise=null,this._id="",this._appId="",this._abLetters="",this._abDict={},this._queue=[],this._isProcessing=!1,this._installDate=0,this._skipFirstViewEvent=!1,this._skipNavigationViewEvents=!1,this._skipAllViewEvents=!1,this._isFirstViewEvent=!0,this._currentPath=null,this.asyncStorage=this.makeAsyncStorage(),this.loggingEnabled=null}return t.prototype.getAppId=function(){return this._appId},t.prototype.initialize=function(t){this.initializeAsync(t).catch(console.error)},t.prototype.loadAppId=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.asyncStorage.getItem("tools.quanta.appId")];case 1:return[2,t.sent()]}}))}))},t.prototype.setAppId=function(t){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.asyncStorage.setItem("tools.quanta.appId",t)];case 1:return[2,e.sent()]}}))}))},t.prototype.initializeAsync=function(t){return n(this,arguments,void 0,(function(t,e){var n,i,s,o,a,c,u,l;return void 0===e&&(e=!1),r(this,(function(r){switch(r.label){case 0:return this._initialized?t?(this._appId=t,[4,this.setAppId(t)]):[3,2]:[3,3];case 1:r.sent(),r.label=2;case 2:return[2];case 3:if(0==this._initializing++)return[3,9];r.label=4;case 4:return this._initializingPromise?[3,6]:[4,new Promise((function(t){return setTimeout(t,100)}))];case 5:return r.sent(),[3,4];case 6:return[4,this._initializingPromise];case 7:return r.sent(),[4,this.initializeAsync(t,e)];case 8:return r.sent(),[2];case 9:n=function(){},this._initializingPromise=new Promise((function(t){n=t})),r.label=10;case 10:return r.trys.push([10,,21,22]),this.isServerSide()?(e||console.info("[Quanta] Skipping client sdk call on server."),[2]):(this.parseScriptTagAttributes(),i=this,null===(u=null!=t?t:this.getAppIdFromScriptTag())||void 0===u?[3,11]:(s=u,[3,13]));case 11:return[4,this.loadAppId()];case 12:s=r.sent(),r.label=13;case 13:return i._appId=null!==(l=s)&&void 0!==l?l:"",this._appId?[4,this.setAppId(this._appId)]:(e||this.debugWarn("No Quanta app ID provided. Analytics will not be sent."),[2]);case 14:return r.sent(),o=this,[4,this.loadOrCreateId()];case 15:return o._id=r.sent(),a=this,[4,this.loadOrCreateInstallDate()];case 16:return a._installDate=r.sent(),[4,this.asyncStorage.getItem("tools.quanta.ab")];case 17:return c=r.sent()||"",this._abLetters=this.getAbLetters(c),this._abDict=this.getAbDict(c),this.setupUrlChangeListeners(),[4,this.loadQueue()];case 18:return r.sent(),[4,this.processQueue()];case 19:return r.sent(),this.isDebug()&&this.checkClaimed().catch(console.error),this.debugLog("Quanta initialized"),this._initialized=!0,[4,this.maybeSendViewEvent()];case 20:return r.sent(),[3,22];case 21:return this._initializing--,n(),[7];case 22:return[2]}}))}))},t.prototype.maybeSendViewEvent=function(){return n(this,void 0,void 0,(function(){return r(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]}}))}))},t.prototype.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())},t.prototype.log=function(t,e){void 0===e&&(e={}),this.logWithRevenue(t,0,e)},t.prototype.logAsync=function(t){return n(this,arguments,void 0,(function(t,e){return void 0===e&&(e={}),r(this,(function(n){switch(n.label){case 0:return[4,this.logWithRevenueAsync(t,0,e)];case 1:return n.sent(),[2]}}))}))},t.prototype.logWithRevenue=function(t,e,n,r){void 0===e&&(e=0),void 0===n&&(n={}),void 0===r&&(r=new Date),this.logWithRevenueAsync(t,e,n,r).catch(console.error)},t.prototype.logWithRevenueAsync=function(t){return n(this,arguments,void 0,(function(t,e,n,s){var o,a,u,l,h,p,d,f,g,y,v;return void 0===e&&(e=0),void 0===n&&(n={}),void 0===s&&(s=new Date),r(this,(function(r){switch(r.label){case 0:if(this.isServerSide())return console.info("[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)),o="","string"==typeof n)o=this.safe(n,!0);else{a=Object.keys(n).sort();try{for(u=i(a),l=u.next();!l.done;l=u.next())h=l.value,p=this.safe(h,!1),d=this.safe(n[h],!1),o+="".concat(p).concat(c).concat(d).concat(c)}catch(t){y={error:t}}finally{try{l&&!l.done&&(v=u.return)&&v.call(u)}finally{if(y)throw y.error}}o.length>0&&(o=o.substring(0,o.length-1))}return t.length+o.length>200&&(this.debugWarn("Added arguments are too long. Event name + args should be 200 characters or less. They will be truncated."),o=o.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(o,!0),time:s,abLetters:this._abLetters})];case 1:return r.sent(),[2]}}))}))},t.prototype.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")},t.prototype.abTestAsync=function(t){return n(this,void 0,void 0,(function(){return r(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"]}}))}))},t.prototype.setId=function(t){this.setIdAsync(t).catch(console.error)},t.prototype.setIdAsync=function(t){return n(this,void 0,void 0,(function(){var e;return r(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]}}))}))},t.prototype.getId=function(){return this._id},t.prototype.loadOrCreateId=function(){return n(this,void 0,void 0,(function(){var t,e;return r(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]}}))}))},t.prototype.loadOrCreateInstallDate=function(){return n(this,void 0,void 0,(function(){var t,e;return r(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]}}))}))},t.prototype.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)},t.prototype.getOSInfoSafe=function(){return this.getOSInfo().slice(0,25)},t.prototype.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(c,"g"),"")},t.prototype.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},t.prototype.enqueueEvent=function(t){return n(this,void 0,void 0,(function(){return r(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]}}))}))},t.prototype.processQueue=function(){return n(this,void 0,void 0,(function(){var t,e,n;return r(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 r(this,(function(r){switch(r.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:r.sent(),r.label=2;case 2:return[4,n.sendEvent(n._queue[0])];case 3:return i=r.sent(),s=(Date.now()-n._queue[0].time.getTime())/36e5,i||t>=27||s>48?(n._queue.shift(),t=0,[4,n.saveQueue()]):[3,5];case 4:return r.sent(),[3,6];case 5:t++,r.label=6;case 6:return[4,new Promise((function(t){return setTimeout(t,100)}))];case 7:return r.sent(),[2]}}))},n=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]}}))}))},t.prototype.sendEvent=function(t){return n(this,void 0,void 0,(function(){var e,n,i,s,o,c,u,l;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,12,,13]),e="https://analytics-ingress.quanta.tools/ee/",n="",n+=t.appId,n+="".concat(a).concat(Math.floor(t.time.getTime()/1e3)),n+="".concat(a).concat(t.event),n+="".concat(a).concat(t.revenue),n+="".concat(a).concat(t.addedArguments),n+="".concat(a).concat(t.userData),t.abLetters&&(n+="".concat(a).concat(t.abLetters)),i={"Content-Type":"text/plain"},[4,this.asyncStorage.getItem("tools.quanta.ab.version")];case 1:return(s=r.sent())&&(i["X-AB-Version"]=s),[4,fetch(e,{method:"POST",headers:i,body:n})];case 2:if(!(o=r.sent()).ok)return[3,11];r.label=3;case 3:return r.trys.push([3,9,,10]),[4,o.text()];case 4:return(c=r.sent())?[4,this.asyncStorage.setItem("tools.quanta.ab",c)]:[3,6];case 5:r.sent(),this.setAbJson(c),r.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:r.sent(),r.label=8;case 8:return[3,10];case 9:return r.sent(),[3,10];case 10:return[2,!0];case 11:return[2,!1];case 12:return l=r.sent(),this.debugError("Failed to send event:",l),[2,!1];case 13:return[2]}}))}))},t.prototype.saveQueue=function(){return n(this,void 0,void 0,(function(){var t;return r(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]}}))}))},t.prototype.loadQueue=function(){return n(this,void 0,void 0,(function(){var t,n,i;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.asyncStorage.getItem("tools.quanta.queue.tasks")];case 1:return(t=r.sent())&&(n=JSON.parse(t),this._queue=n.map((function(t){return e(e({},t),{time:new Date(t.time)})}))),[3,3];case 2:return i=r.sent(),this.debugWarn("Failed to load queue from storage:",i),[3,3];case 3:return[2]}}))}))},t.prototype.setAbJson=function(t){this._abLetters=this.getAbLetters(t),this._abDict=this.getAbDict(t)},t.prototype.getAbLetters=function(t){var e,n;if(!t)return"";try{var r=JSON.parse(t),s="";try{for(var o=i(r),a=o.next();!a.done;a=o.next())for(var c=a.value,u="".concat(this._id,".").concat(c.name[c.name.length-1]||""),l=this.stringToNumber(u),h=0,p=0;p<c.variants.length;p++)if((h+=c.variants[p])>l){s+="ABCDEFGHIJKLMNOPQRSTUVWXYZ"[p];break}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return s}catch(t){return this.debugWarn("Failed to parse AB test JSON:",t),""}},t.prototype.getAbDict=function(t){var e,n,r={};if(!t)return r;try{for(var s=JSON.parse(t),o=this._abLetters,a=0;a<s.length&&!(a>=o.length);a++){var c=s[a];try{for(var u=(e=void 0,i(c.name)),l=u.next();!l.done;l=u.next()){r[l.value.toLowerCase()]=o.substring(a,a+1)}}catch(t){e={error:t}}finally{try{l&&!l.done&&(n=u.return)&&n.call(u)}finally{if(e)throw e.error}}}return r}catch(t){return this.debugWarn("Failed to parse AB test JSON:",t),r}},t.prototype.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)},t.prototype.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)}))},t.prototype.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,"")},t.prototype.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)},t.prototype.shouldLog=function(){return null===this.loggingEnabled?this.isDebug():this.loggingEnabled},t.prototype.enableLogging=function(){this.loggingEnabled=!0},t.prototype.disableLogging=function(){this.loggingEnabled=!1},t.prototype.debugLog=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog()&&console.info.apply(console,o([],s(t),!1))},t.prototype.debugWarn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog()&&console.warn.apply(console,o([],s(t),!1))},t.prototype.debugError=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog()&&console.error.apply(console,o([],s(t),!1))},t.prototype.checkClaimed=function(){return n(this,void 0,void 0,(function(){var t;return r(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.info("%c\n :@@@ +@@+ @@@ \n @@ @: @@ @ @ @@ \n @@ @@ @@ @@ @@ @ \n @ @@ = @@ @ @ @@ = +\n @@@@:@@ @@ @@ @ @= @@ @@ @@@ @@=@@ \n :@@ @ @@ @@ @@@ @@@@ @@ @@ \n @@@@@@ @@ @@@@ @@@ @@ @@@ @@ \n @ \\@@@@ \\@@@@@ \\@@@@@ \\@@@@@ \\@@@@ \n","font-family:monospace;font-weight:600"),console.info("Welcome to Quanta! 🥳"),console.info("Your analytics are fully set up."),console.info("See your first events coming in and attach this app to your Quanta account at"),console.info("https://quanta.tools/setup/".concat(this._appId)),console.info(""),console.info("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]}}))}))},t}()));exports.Quanta=l,exports.default=l;
//# sourceMappingURL=index.cjs.js.map