@amplitude/experiment-js-client
Version:
Amplitude Experiment Javascript Client SDK
2 lines • 77.7 kB
JavaScript
/* @amplitude/experiment-js-client v1.19.0 - For license info see https://app.unpkg.com/@amplitude/experiment-js-client@1.19.0/files/LICENSE */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Experiment={})}(this,(function(e){"use strict";var t=function(){function e(e){this.amplitudeInstance=e}return e.prototype.getUser=function(){var e,t,r,i,n,o,a,s,u,l;return{device_id:null===(t=null===(e=this.amplitudeInstance)||void 0===e?void 0:e.options)||void 0===t?void 0:t.deviceId,user_id:null===(i=null===(r=this.amplitudeInstance)||void 0===r?void 0:r.options)||void 0===i?void 0:i.userId,version:null===(o=null===(n=this.amplitudeInstance)||void 0===n?void 0:n.options)||void 0===o?void 0:o.versionName,language:null===(s=null===(a=this.amplitudeInstance)||void 0===a?void 0:a.options)||void 0===s?void 0:s.language,platform:null===(l=null===(u=this.amplitudeInstance)||void 0===u?void 0:u.options)||void 0===l?void 0:l.platform,os:this.getOs(),device_model:this.getDeviceModel()}},e.prototype.getOs=function(){var e,t,r,i,n,o;return[null===(r=null===(t=null===(e=this.amplitudeInstance)||void 0===e?void 0:e._ua)||void 0===t?void 0:t.browser)||void 0===r?void 0:r.name,null===(o=null===(n=null===(i=this.amplitudeInstance)||void 0===i?void 0:i._ua)||void 0===n?void 0:n.browser)||void 0===o?void 0:o.major].filter((function(e){return null!=e})).join(" ")},e.prototype.getDeviceModel=function(){var e,t,r;return null===(r=null===(t=null===(e=this.amplitudeInstance)||void 0===e?void 0:e._ua)||void 0===t?void 0:t.os)||void 0===r?void 0:r.name},e}(),r=function(){function e(e){this.amplitudeInstance=e}return e.prototype.track=function(e){this.amplitudeInstance.logEvent(e.name,e.properties)},e.prototype.setUserProperty=function(e){var t,r;this.amplitudeInstance.setUserProperties(((t={})[e.userProperty]=null===(r=e.variant)||void 0===r?void 0:r.value,t))},e.prototype.unsetUserProperty=function(e){var t;this.amplitudeInstance._logEvent("$identify",null,null,{$unset:(t={},t[e.userProperty]="-",t)})},e}(),i=function(){return i=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},i.apply(this,arguments)};function n(e,t,r,i){return new(r||(r=Promise))((function(n,o){function a(e){try{u(i.next(e))}catch(e){o(e)}}function s(e){try{u(i.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((i=i.apply(e,t||[])).next())}))}function o(e,t){var r,i,n,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),o;)try{if(r=1,i&&(n=2&s[0]?i.return:s[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,s[1])).done)return n;switch(i=0,n&&(s=[2&s[0],n.value]),s[0]){case 0:case 1:n=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!n||s[1]>n[0]&&s[1]<n[3])){o.label=s[1];break}if(6===s[0]&&o.label<n[1]){o.label=n[1],n=s;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(s);break}n[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{r=n=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function a(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],i=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var i,n,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return a}function u(e,t,r){if(r||2===arguments.length)for(var i,n=0,o=t.length;n<o;n++)!i&&n in t||(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return e.concat(i||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var l=function(e,t){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},l(e,t)};function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var f=function(){return f=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},f.apply(this,arguments)};function h(e,t,r,i){return new(r||(r=Promise))((function(n,o){function a(e){try{u(i.next(e))}catch(e){o(e)}}function s(e){try{u(i.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((i=i.apply(e,t||[])).next())}))}function d(e,t){var r,i,n,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),o;)try{if(r=1,i&&(n=2&s[0]?i.return:s[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,s[1])).done)return n;switch(i=0,n&&(s=[2&s[0],n.value]),s[0]){case 0:case 1:n=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!n||s[1]>n[0]&&s[1]<n[3])){o.label=s[1];break}if(6===s[0]&&o.label<n[1]){o.label=n[1],n=s;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(s);break}n[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{r=n=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function p(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],i=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function v(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var i,n,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return a}function y(e,t,r){if(r||2===arguments.length)for(var i,n=0,o=t.length;n<o;n++)!i&&n in t||(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return e.concat(i||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var g="is",b="is not",m="contains",w="does not contain",x="less",S="less or equal",k="greater",I="greater or equal",P="version less",E="version less or equal",A="version greater",C="version greater or equal",_="set is",O="set is not",T="set contains",U="set does not contain",L="set contains any",V="set does not contain any",M="regex match",j="regex does not match",N=-862048943,F=461845907,q=function(e,t){void 0===t&&(t=0);for(var r=function(e){for(var t=[],r=0,i=0;i<e.length;i++){var n=e.charCodeAt(i);n<128?t[r++]=n:n<2048?(t[r++]=n>>6|192,t[r++]=63&n|128):55296==(64512&n)&&i+1<e.length&&56320==(64512&e.charCodeAt(i+1))?(n=65536+((1023&n)<<10)+(1023&e.charCodeAt(++i)),t[r++]=n>>18|240,t[r++]=n>>12&63|128,t[r++]=n>>6&63|128,t[r++]=63&n|128):(t[r++]=n>>12|224,t[r++]=n>>6&63|128,t[r++]=63&n|128)}return Uint8Array.from(t)}(e),i=r.length,n=i>>2,o=t,a=0;a<n;a++){var s=z(r,a<<2);o=R(s,o)}var u=n<<2,l=0;switch(i-u){case 3:l^=r[u+2]<<16,l^=r[u+1]<<8,l^=r[u],l=Math.imul(l,N),l=K(l,15),o^=l=Math.imul(l,F);break;case 2:l^=r[u+1]<<8,l^=r[u],l=Math.imul(l,N),l=K(l,15),o^=l=Math.imul(l,F);break;case 1:l^=r[u],l=Math.imul(l,N),l=K(l,15),o^=l=Math.imul(l,F)}return D(o^=i)>>>0},R=function(e,t){var r=e,i=t;return r=Math.imul(r,N),r=K(r,15),r=Math.imul(r,F),i=K(i^=r,13),(i=Math.imul(i,5))+-430675100|0},D=function(e){var t=e;return t^=t>>>16,t=Math.imul(t,-2048144789),t^=t>>>13,t=Math.imul(t,-1028477387),t^=t>>>16},K=function(e,t,r){return void 0===r&&(r=32),t>r&&(t%=r),(e<<t|(e&4294967295<<r-t>>>0)>>>0>>>r-t>>>0)>>>0},z=function(e,t){void 0===t&&(t=0);var r=e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3];return B(r)},B=function(e){return(-16777216&e)>>>24|(16711680&e)>>>8|(65280&e)<<8|(255&e)<<24},W=function(e,t){var r,i;if(t&&0!==t.length){try{for(var n=p(t),o=n.next();!o.done;o=n.next()){var a=o.value;if(!a||!e||"object"!=typeof e)return;e=e[a]}}catch(e){r={error:e}}finally{try{o&&!o.done&&(i=n.return)&&i.call(n)}finally{if(r)throw r.error}}return null==e?void 0:e}},J="^".concat("(\\d+)\\.(\\d+)","(\\.").concat("(\\d+)").concat("(-(([-\\w]+\\.?)*))?",")?$"),Q=function(){function e(e,t,r,i){void 0===i&&(i=void 0),this.major=e,this.minor=t,this.patch=r,this.preRelease=i}return e.parse=function(t){if(t){var r=new RegExp(J).exec(t);if(r){var i=Number(r[1]),n=Number(r[2]);if(!isNaN(i)&&!isNaN(n))return new e(i,n,Number(r[4])||0,r[5]||void 0)}}},e.prototype.compareTo=function(e){return this.major>e.major?1:this.major<e.major?-1:this.minor>e.minor?1:this.minor<e.minor?-1:this.patch>e.patch?1:this.patch<e.patch||this.preRelease&&!e.preRelease?-1:!this.preRelease&&e.preRelease?1:this.preRelease&&e.preRelease?this.preRelease>e.preRelease?1:this.preRelease<e.preRelease?-1:0:0},e}(),$=function(){function e(){}return e.prototype.evaluate=function(e,t){var r,i,n={},o={context:e,result:n};try{for(var a=p(t),s=a.next();!s.done;s=a.next()){var u=s.value,l=this.evaluateFlag(o,u);l&&(n[u.key]=l)}}catch(e){r={error:e}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return n},e.prototype.evaluateFlag=function(e,t){var r,i,n;try{for(var o=p(t.segments),a=o.next();!a.done;a=o.next()){var s=a.value;if(n=this.evaluateSegment(e,t,s)){var u=f(f(f({},t.metadata),s.metadata),n.metadata);n=f(f({},n),{metadata:u});break}}}catch(e){r={error:e}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return n},e.prototype.evaluateSegment=function(e,t,r){var i;return r.conditions?this.evaluateConditions(e,r.conditions)&&void 0!==(i=this.bucket(e,r))?t.variants[i]:void 0:void 0!==(i=this.bucket(e,r))?t.variants[i]:void 0},e.prototype.evaluateConditions=function(e,t){var r,i,n,o;try{for(var a=p(t),s=a.next();!s.done;s=a.next()){var u=s.value,l=!0;try{for(var c=(n=void 0,p(u)),f=c.next();!f.done;f=c.next()){var h=f.value;if(!(l=this.matchCondition(e,h)))break}}catch(e){n={error:e}}finally{try{f&&!f.done&&(o=c.return)&&o.call(c)}finally{if(n)throw n.error}}if(l)return!0}}catch(e){r={error:e}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return!1},e.prototype.matchCondition=function(e,t){var r=W(e,t.selector);if(null==r)return this.matchNull(t.op,t.values);if(this.isSetOperator(t.op)){var i=this.coerceStringArray(r);return!!i&&this.matchSet(i,t.op,t.values)}var n=this.coerceString(r);return void 0!==n&&this.matchString(n,t.op,t.values)},e.prototype.getHash=function(e){return q(e)},e.prototype.bucket=function(e,t){var r,i,n,o;if(!t.bucket)return t.variant;var a=this.coerceString(W(e,t.bucket.selector));if(!a||0===a.length)return t.variant;var s="".concat(t.bucket.salt,"/").concat(a),u=this.getHash(s),l=u%100,c=Math.floor(u/100);try{for(var f=p(t.bucket.allocations),h=f.next();!h.done;h=f.next()){var d=h.value,v=d.range[0],y=d.range[1];if(l>=v&&l<y)try{for(var g=(n=void 0,p(d.distributions)),b=g.next();!b.done;b=g.next()){var m=b.value,w=m.range[0],x=m.range[1];if(c>=w&&c<x)return m.variant}}catch(e){n={error:e}}finally{try{b&&!b.done&&(o=g.return)&&o.call(g)}finally{if(n)throw n.error}}}}catch(e){r={error:e}}finally{try{h&&!h.done&&(i=f.return)&&i.call(f)}finally{if(r)throw r.error}}return t.variant},e.prototype.matchNull=function(e,t){var r=this.containsNone(t);switch(e){case g:case m:case x:case S:case k:case I:case P:case E:case A:case C:case _:case T:case L:return r;case b:case w:case U:case V:return!r;default:return!1}},e.prototype.matchSet=function(e,t,r){switch(t){case _:return this.setEquals(e,r);case O:return!this.setEquals(e,r);case T:return this.matchesSetContainsAll(e,r);case U:return!this.matchesSetContainsAll(e,r);case L:return this.matchesSetContainsAny(e,r);case V:return!this.matchesSetContainsAny(e,r);default:return!1}},e.prototype.matchString=function(e,t,r){var i=this;switch(t){case g:return this.matchesIs(e,r);case b:return!this.matchesIs(e,r);case m:return this.matchesContains(e,r);case w:return!this.matchesContains(e,r);case x:case S:case k:case I:return this.matchesComparable(e,t,r,(function(e){return i.parseNumber(e)}),this.comparator);case P:case E:case A:case C:return this.matchesComparable(e,t,r,(function(e){return Q.parse(e)}),this.versionComparator);case M:return this.matchesRegex(e,r);case j:return!this.matchesRegex(e,r);default:return!1}},e.prototype.matchesIs=function(e,t){if(this.containsBooleans(t)){var r=e.toLowerCase();if("true"===r||"false"===r)return t.some((function(e){return e.toLowerCase()===r}))}return t.some((function(t){return e===t}))},e.prototype.matchesContains=function(e,t){var r,i;try{for(var n=p(t),o=n.next();!o.done;o=n.next()){var a=o.value;if(e.toLowerCase().includes(a.toLowerCase()))return!0}}catch(e){r={error:e}}finally{try{o&&!o.done&&(i=n.return)&&i.call(n)}finally{if(r)throw r.error}}return!1},e.prototype.matchesComparable=function(e,t,r,i,n){var o=this,a=i(e),s=r.map((function(e){return i(e)})).filter((function(e){return void 0!==e}));return void 0===a||0===s.length?r.some((function(r){return o.comparator(e,t,r)})):s.some((function(e){return n(a,t,e)}))},e.prototype.comparator=function(e,t,r){switch(t){case x:case P:return e<r;case S:case E:return e<=r;case k:case A:return e>r;case I:case C:return e>=r;default:return!1}},e.prototype.versionComparator=function(e,t,r){var i=e.compareTo(r);switch(t){case x:case P:return i<0;case S:case E:return i<=0;case k:case A:return i>0;case I:case C:return i>=0;default:return!1}},e.prototype.matchesRegex=function(e,t){return t.some((function(t){return Boolean(new RegExp(t).exec(e))}))},e.prototype.containsNone=function(e){return e.some((function(e){return"(none)"===e}))},e.prototype.containsBooleans=function(e){return e.some((function(e){switch(e.toLowerCase()){case"true":case"false":return!0;default:return!1}}))},e.prototype.parseNumber=function(e){var t;return null!==(t=Number(e))&&void 0!==t?t:void 0},e.prototype.coerceString=function(e){if(null!=e)return"object"==typeof e?JSON.stringify(e):String(e)},e.prototype.coerceStringArray=function(e){var t=this;if(Array.isArray(e))return e.map((function(e){return t.coerceString(e)})).filter(Boolean);var r=String(e);try{var i=JSON.parse(r);return Array.isArray(i)?e.map((function(e){return t.coerceString(e)})).filter(Boolean):(n=this.coerceString(r))?[n]:void 0}catch(e){var n;return(n=this.coerceString(r))?[n]:void 0}},e.prototype.isSetOperator=function(e){switch(e){case _:case O:case T:case U:case L:case V:return!0;default:return!1}},e.prototype.setEquals=function(e,t){var r=new Set(e),i=new Set(t);return r.size===i.size&&y([],v(i),!1).every((function(e){return r.has(e)}))},e.prototype.matchesSetContainsAll=function(e,t){var r,i;if(e.length<t.length)return!1;try{for(var n=p(t),o=n.next();!o.done;o=n.next()){var a=o.value;if(!this.matchesIs(a,e))return!1}}catch(e){r={error:e}}finally{try{o&&!o.done&&(i=n.return)&&i.call(n)}finally{if(r)throw r.error}}return!0},e.prototype.matchesSetContainsAny=function(e,t){var r,i;try{for(var n=p(t),o=n.next();!o.done;o=n.next()){var a=o.value;if(this.matchesIs(a,e))return!0}}catch(e){r={error:e}}finally{try{o&&!o.done&&(i=n.return)&&i.call(n)}finally{if(r)throw r.error}}return!1},e}(),X=function(e,t,r){var i,n;void 0===r&&(r=[]);var o=t[e];if(o){if(!o.dependencies||0===o.dependencies.length)return delete t[o.key],[o];r.push(o.key);var a=[],s=function(e){if(r.some((function(t){return t===e})))throw Error("Detected a cycle between flags ".concat(r));var i=X(e,t,r);i&&a.push.apply(a,y([],v(i),!1))};try{for(var u=p(o.dependencies),l=u.next();!l.done;l=u.next()){s(l.value)}}catch(e){i={error:e}}finally{try{l&&!l.done&&(n=u.return)&&n.call(u)}finally{if(i)throw i.error}}return a.push(o),r.pop(),delete t[o.key],a}};const Z="function"==typeof Buffer,H=("function"==typeof TextDecoder&&new TextDecoder,"function"==typeof TextEncoder?new TextEncoder:void 0),G=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),Y=(e=>{let t={};return e.forEach(((e,r)=>t[e]=r)),t})(G),ee=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,te=String.fromCharCode.bind(String),re=("function"==typeof Uint8Array.from&&Uint8Array.from.bind(Uint8Array),e=>e.replace(/=/g,"").replace(/[+\/]/g,(e=>"+"==e?"-":"_"))),ie=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),ne=e=>{let t,r,i,n,o="";const a=e.length%3;for(let a=0;a<e.length;){if((r=e.charCodeAt(a++))>255||(i=e.charCodeAt(a++))>255||(n=e.charCodeAt(a++))>255)throw new TypeError("invalid character found");t=r<<16|i<<8|n,o+=G[t>>18&63]+G[t>>12&63]+G[t>>6&63]+G[63&t]}return a?o.slice(0,a-3)+"===".substring(a):o},oe="function"==typeof btoa?e=>btoa(e):Z?e=>Buffer.from(e,"binary").toString("base64"):ne,ae=Z?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let r=0,i=e.length;r<i;r+=4096)t.push(te.apply(null,e.subarray(r,r+4096)));return oe(t.join(""))},se=e=>{if(e.length<2)return(t=e.charCodeAt(0))<128?e:t<2048?te(192|t>>>6)+te(128|63&t):te(224|t>>>12&15)+te(128|t>>>6&63)+te(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return te(240|t>>>18&7)+te(128|t>>>12&63)+te(128|t>>>6&63)+te(128|63&t)},ue=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,le=e=>e.replace(ue,se),ce=Z?e=>Buffer.from(e,"utf8").toString("base64"):H?e=>ae(H.encode(e)):e=>oe(le(e)),fe=(e,t=!1)=>t?re(ce(e)):ce(e),he=e=>fe(e,!0),de=e=>{if(e=e.replace(/\s+/g,""),!ee.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let t,r,i,n="";for(let o=0;o<e.length;)t=Y[e.charAt(o++)]<<18|Y[e.charAt(o++)]<<12|(r=Y[e.charAt(o++)])<<6|(i=Y[e.charAt(o++)]),n+=64===r?te(t>>16&255):64===i?te(t>>16&255,t>>8&255):te(t>>16&255,t>>8&255,255&t);return n},pe=he;var ve=function(e){function t(r,i){var n=e.call(this,i)||this;return n.statusCode=r,Object.setPrototypeOf(n,t.prototype),n}return c(t,e),t}(Error),ye=function(e){function t(r){var i=e.call(this,r)||this;return Object.setPrototypeOf(i,t.prototype),i}return c(t,e),t}(Error),ge=function(){function e(e,t,r){this.deploymentKey=e,this.serverUrl=t,this.httpClient=r}return e.prototype.getVariants=function(e,t){return h(this,void 0,void 0,(function(){var r,i,n,o;return d(this,(function(a){switch(a.label){case 0:return r=pe(JSON.stringify(e)),i={Authorization:"Api-Key ".concat(this.deploymentKey),"X-Amp-Exp-User":r},(null==t?void 0:t.flagKeys)&&(i["X-Amp-Exp-Flag-Keys"]=pe(JSON.stringify(t.flagKeys))),(null==t?void 0:t.trackingOption)&&(i["X-Amp-Exp-Track"]=t.trackingOption),n=new URL("".concat(this.serverUrl,"/sdk/v2/vardata?v=0")),(null==t?void 0:t.evaluationMode)&&n.searchParams.append("eval_mode",null==t?void 0:t.evaluationMode),(null==t?void 0:t.deliveryMethod)&&n.searchParams.append("delivery_method",null==t?void 0:t.deliveryMethod),[4,this.httpClient.request({requestUrl:n.toString(),method:"GET",headers:i,timeoutMillis:null==t?void 0:t.timeoutMillis})];case 1:if(200!=(o=a.sent()).status)throw new ve(o.status,"Fetch error response: status=".concat(o.status));return[2,JSON.parse(o.body)]}}))}))},e}(),be=function(){function e(e,t,r){this.deploymentKey=e,this.serverUrl=t,this.httpClient=r}return e.prototype.getFlags=function(e){return h(this,void 0,void 0,(function(){var t,r;return d(this,(function(i){switch(i.label){case 0:return t={Authorization:"Api-Key ".concat(this.deploymentKey)},(null==e?void 0:e.libraryName)&&(null==e?void 0:e.libraryVersion)&&(t["X-Amp-Exp-Library"]="".concat(e.libraryName,"/").concat(e.libraryVersion)),(null==e?void 0:e.user)&&(t["X-Amp-Exp-User"]=pe(JSON.stringify(e.user))),[4,this.httpClient.request({requestUrl:"".concat(this.serverUrl,"/sdk/v2/flags")+((null==e?void 0:e.deliveryMethod)?"?delivery_method=".concat(e.deliveryMethod):""),method:"GET",headers:t,timeoutMillis:null==e?void 0:e.timeoutMillis})];case 1:if(200!=(r=i.sent()).status)throw Error("Flags error response: status=".concat(r.status));return[2,JSON.parse(r.body).reduce((function(e,t){return e[t.key]=t,e}),{})]}}))}))},e}(),me="undefined"!=typeof globalThis?globalThis:global||self,we=function(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0},xe=function(){function e(e,t){this.poller=void 0,this.action=e,this.ms=t}return e.prototype.start=function(){this.poller||(this.poller=me.setInterval(this.action,this.ms),this.action())},e.prototype.stop=function(){this.poller&&(me.clearInterval(this.poller),this.poller=void 0)},e}(),Se=function(e,t){var r,i;void 0===t&&(t=!1);var n=ke(e,t),o=void 0,u=me.document.cookie.split("; ");try{for(var l=a(u),c=l.next();!c.done;c=l.next()){var f=s(c.value.split("=",2),2),h=f[0],d=f[1];h===n&&(o=decodeURIComponent(d))}}catch(e){r={error:e}}finally{try{c&&!c.done&&(i=l.return)&&i.call(l)}finally{if(r)throw r.error}}if(o)try{if(t){var p=atob(o);return JSON.parse(decodeURIComponent(p))}var v=o.split("."),y=void 0;return v.length>=2&&v[1]&&(y=atob(v[1])),{deviceId:v[0],userId:y}}catch(e){return}},ke=function(e,t){if(t){if((null==e?void 0:e.length)<10)return;return"AMP_".concat(e.substring(0,10))}if(!((null==e?void 0:e.length)<6))return"amp_".concat(e.substring(0,6))},Ie=function(){function e(e,t,r){this.type="integration",this.apiKey=e,this.identityStore=t.identityStore,this.eventBridge=t.eventBridge,this.contextProvider=t.applicationContextProvider,this.timeoutMillis=r,this.loadPersistedState(),r<=0&&(this.setup=void 0)}return e.prototype.setup=function(e,t){return n(this,void 0,void 0,(function(){return o(this,(function(r){return(null==e?void 0:e.automaticFetchOnAmplitudeIdentityChange)&&this.identityStore.addIdentityListener((function(){null==t||t.fetch()})),[2,this.waitForConnectorIdentity(this.timeoutMillis)]}))}))},e.prototype.getUser=function(){var e=this.identityStore.getIdentity();return{user_id:e.userId,device_id:e.deviceId,user_properties:e.userProperties,version:this.contextProvider.versionName}},e.prototype.track=function(e){return!!this.eventBridge.receiver&&(this.eventBridge.logEvent({eventType:e.eventType,eventProperties:e.eventProperties}),!0)},e.prototype.loadPersistedState=function(){if(!this.apiKey||this.apiKey.startsWith("client-"))return!1;var e=Se(this.apiKey,!0);return(e||(e=Se(this.apiKey,!1))||(e=function(e){var t=ke(e,!0);try{var r=me.localStorage.getItem(t);if(!r)return;var i=JSON.parse(r);if("object"!=typeof i)return;return i}catch(e){return}}(this.apiKey))||!!(e=function(e){var t=ke(e,!0);try{var r=me.sessionStorage.getItem(t);if(!r)return;var i=JSON.parse(r);if("object"!=typeof i)return;return i}catch(e){return}}(this.apiKey)))&&(this.commitIdentityToConnector(e),!0)},e.prototype.commitIdentityToConnector=function(e){var t=this.identityStore.editIdentity();t.setDeviceId(e.deviceId),e.userId&&t.setUserId(e.userId),t.commit()},e.prototype.waitForConnectorIdentity=function(e){return n(this,void 0,void 0,(function(){var t,r=this;return o(this,(function(i){return(t=this.identityStore.getIdentity()).userId||t.deviceId?[2]:[2,Promise.race([new Promise((function(e){var t=function(){e(),r.identityStore.removeIdentityListener(t)};r.identityStore.addIdentityListener(t)})),new Promise((function(t,r){me.setTimeout(r,e,"Timed out waiting for Amplitude Analytics SDK to initialize.")}))])]}))}))},e}(),Pe=function(){function e(){}return e.prototype.getApplicationContext=function(){return{versionName:this.versionName,language:Ee(),platform:"Web",os:void 0,deviceModel:void 0}},e}(),Ee=function(){return"undefined"!=typeof navigator&&(navigator.languages&&navigator.languages[0]||navigator.language)||""},Ae=function(){function e(){this.queue=[]}return e.prototype.logEvent=function(e){this.receiver?this.receiver(e):this.queue.length<512&&this.queue.push(e)},e.prototype.setEventReceiver=function(e){this.receiver=e,this.queue.length>0&&(this.queue.forEach((function(t){e(t)})),this.queue=[])},e}(),Ce=function(){return Ce=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},Ce.apply(this,arguments)};function _e(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],i=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Oe(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var i,n,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return a}"function"==typeof SuppressedError&&SuppressedError;var Te=function(e,t){var r,i,n=typeof e;if(n!==typeof t)return!1;try{for(var o=_e(["string","number","boolean","undefined"]),a=o.next();!a.done;a=o.next()){if(a.value===n)return e===t}}catch(e){r={error:e}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}if(null==e&&null==t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;var s=Array.isArray(e),u=Array.isArray(t);if(s!==u)return!1;if(!s||!u){var l=Object.keys(e).sort(),c=Object.keys(t).sort();if(!Te(l,c))return!1;var f=!0;return Object.keys(e).forEach((function(r){Te(e[r],t[r])||(f=!1)})),f}for(var h=0;h<e.length;h++)if(!Te(e[h],t[h]))return!1;return!0};Object.entries||(Object.entries=function(e){for(var t=Object.keys(e),r=t.length,i=new Array(r);r--;)i[r]=[t[r],e[t[r]]];return i});var Ue=function(){function e(){this.identity={userProperties:{}},this.listeners=new Set}return e.prototype.editIdentity=function(){var e=this,t=Ce({},this.identity.userProperties),r=Ce(Ce({},this.identity),{userProperties:t});return{setUserId:function(e){return r.userId=e,this},setDeviceId:function(e){return r.deviceId=e,this},setUserProperties:function(e){return r.userProperties=e,this},setOptOut:function(e){return r.optOut=e,this},updateUserProperties:function(e){var t,i,n,o,a,s,u=r.userProperties||{};try{for(var l=_e(Object.entries(e)),c=l.next();!c.done;c=l.next()){var f=Oe(c.value,2),h=f[0],d=f[1];switch(h){case"$set":try{for(var p=(n=void 0,_e(Object.entries(d))),v=p.next();!v.done;v=p.next()){var y=Oe(v.value,2),g=y[0],b=y[1];u[g]=b}}catch(e){n={error:e}}finally{try{v&&!v.done&&(o=p.return)&&o.call(p)}finally{if(n)throw n.error}}break;case"$unset":try{for(var m=(a=void 0,_e(Object.keys(d))),w=m.next();!w.done;w=m.next()){delete u[g=w.value]}}catch(e){a={error:e}}finally{try{w&&!w.done&&(s=m.return)&&s.call(m)}finally{if(a)throw a.error}}break;case"$clearAll":u={}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(i=l.return)&&i.call(l)}finally{if(t)throw t.error}}return r.userProperties=u,this},commit:function(){return e.setIdentity(r),this}}},e.prototype.getIdentity=function(){return Ce({},this.identity)},e.prototype.setIdentity=function(e){var t=Ce({},this.identity);this.identity=Ce({},e),Te(t,this.identity)||this.listeners.forEach((function(t){t(e)}))},e.prototype.addIdentityListener=function(e){this.listeners.add(e)},e.prototype.removeIdentityListener=function(e){this.listeners.delete(e)},e}(),Le="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self,Ve=function(){function e(){this.identityStore=new Ue,this.eventBridge=new Ae,this.applicationContextProvider=new Pe}return e.getInstance=function(t){return Le.analyticsConnectorInstances||(Le.analyticsConnectorInstances={}),Le.analyticsConnectorInstances[t]||(Le.analyticsConnectorInstances[t]=new e),Le.analyticsConnectorInstances[t]},e}();var Me,je,Ne,Fe=me.fetch||function(e,t){return t=t||{},new Promise((function(r,i){var n=new XMLHttpRequest,o=[],a=[],s={},u=function(){return{ok:2==(n.status/100|0),statusText:n.statusText,status:n.status,url:n.responseURL,text:function(){return Promise.resolve(n.responseText)},json:function(){return Promise.resolve(JSON.parse(n.responseText))},blob:function(){return Promise.resolve(new Blob([n.response]))},clone:u,headers:{keys:function(){return o},entries:function(){return a},get:function(e){return s[e.toLowerCase()]},has:function(e){return e.toLowerCase()in s}}}};for(var l in n.open(t.method||"get",e,!0),n.onload=function(){n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,r){o.push(t=t.toLowerCase()),a.push([t,r]),s[t]=s[t]?s[t]+","+r:r})),r(u())},n.onerror=i,n.withCredentials="include"==t.credentials,t.headers)n.setRequestHeader(l,t.headers[l]);n.send(t.body||null)}))},qe=function(){function e(e){this.client=e}return e.prototype.request=function(e){return n(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,this.client.request(e.requestUrl,e.method,e.headers,null,e.timeoutMillis)];case 1:return[2,t.sent()]}}))}))},e}(),Re={request:function(e,t,r,i,a){return function(e,t){return null==t||t<=0?e:new Promise((function(r,i){me.setTimeout((function(){i(new ye("Request timeout after "+t+" milliseconds"))}),t),e.then(r,i)}))}(n(void 0,void 0,void 0,(function(){var n,a;return o(this,(function(o){switch(o.label){case 0:return[4,Fe(e,{method:t,headers:r,body:i})];case 1:return n=o.sent(),a={status:n.status},[4,n.text()];case 2:return a.body=o.sent(),[2,a]}}))})),a)}};e.LogLevel=void 0,(Me=e.LogLevel||(e.LogLevel={}))[Me.Disable=0]="Disable",Me[Me.Error=1]="Error",Me[Me.Warn=2]="Warn",Me[Me.Info=3]="Info",Me[Me.Debug=4]="Debug",Me[Me.Verbose=5]="Verbose",e.Source=void 0,(je=e.Source||(e.Source={})).LocalStorage="localStorage",je.InitialVariants="initialVariants",function(e){e.LocalStorage="storage",e.InitialVariants="initial",e.SecondaryLocalStorage="secondary-storage",e.SecondaryInitialVariants="secondary-initial",e.FallbackInline="fallback-inline",e.FallbackConfig="fallback-config",e.LocalEvaluation="local-evaluation"}(Ne||(Ne={}));var De=function(e){return!e||e===Ne.FallbackInline||e===Ne.FallbackConfig||e===Ne.SecondaryInitialVariants},Ke={debug:!1,logLevel:e.LogLevel.Error,loggerProvider:null,instanceName:"$default_instance",fallbackVariant:{},initialVariants:{},initialFlags:void 0,source:e.Source.LocalStorage,serverUrl:"https://api.lab.amplitude.com",flagsServerUrl:"https://flag.lab.amplitude.com",serverZone:"US",fetchTimeoutMillis:1e4,retryFetchOnFailure:!0,throwOnError:!1,automaticExposureTracking:!0,pollOnStart:!0,flagConfigPollingIntervalMillis:3e5,fetchOnStart:!0,automaticFetchOnAmplitudeIdentityChange:!1,userProvider:null,analyticsProvider:null,exposureTrackingProvider:null,httpClient:Re},ze="1.19.0",Be=function(){function e(e,t){var r,i=this;this.isReady=new Promise((function(e){i.resolve=e})),this.config=e,this.client=t;var n=null!==(r=e.instanceName)&&void 0!==r?r:Ke.instanceName;this.queue=new Je(n),this.cache=new We(n)}return e.prototype.ready=function(){return this.integration?this.isReady:Promise.resolve()},e.prototype.setIntegration=function(e){var t=this;this.integration&&this.integration.teardown&&this.integration.teardown(),this.integration=e,e.setup?this.integration.setup(this.config,this.client).then((function(){t.queue.setTracker(t.integration.track.bind(e)),t.resolve()}),(function(){t.queue.setTracker(t.integration.track.bind(e)),t.resolve()})):(this.queue.setTracker(this.integration.track.bind(e)),this.resolve())},e.prototype.getUser=function(){return this.integration?this.integration.getUser():{}},e.prototype.track=function(e){if(this.cache.shouldTrack(e)){var t=this.getExposureEvent(e);this.queue.push(t)}},e.prototype.getExposureEvent=function(e){var t,r,i,n={eventType:"$exposure",eventProperties:e};return(null===(t=e.metadata)||void 0===t?void 0:t.exposureEvent)?n={eventType:null===(r=e.metadata)||void 0===r?void 0:r.exposureEvent,eventProperties:e}:"web"===(null===(i=e.metadata)||void 0===i?void 0:i.deliveryMethod)&&(n={eventType:"$impression",eventProperties:e}),n},e}(),We=function(){function e(e){this.isSessionStorageAvailable=Qe(),this.inMemoryCache={},this.storageKey="EXP_sent_v2_".concat(e),this.isSessionStorageAvailable&&me.sessionStorage.removeItem("EXP_sent_".concat(e))}return e.prototype.shouldTrack=function(e){var t;if("web"===(null===(t=e.metadata)||void 0===t?void 0:t.deliveryMethod))return!0;this.loadCache();var r=this.inMemoryCache[e.flag_key],i=!1;return r&&r.variant===e.variant||(i=!0,this.inMemoryCache[e.flag_key]=e),this.storeCache(),i},e.prototype.loadCache=function(){if(this.isSessionStorageAvailable){var e=me.sessionStorage.getItem(this.storageKey);this.inMemoryCache=e?JSON.parse(e):{}}},e.prototype.storeCache=function(){this.isSessionStorageAvailable&&me.sessionStorage.setItem(this.storageKey,JSON.stringify(this.inMemoryCache))},e}(),Je=function(){function e(e,t){void 0===t&&(t=512),this.isLocalStorageAvailable=function(){var e=we();if(e)try{var t="EXP_test";return e.localStorage.setItem(t,t),e.localStorage.removeItem(t),!0}catch(e){return!1}return!1}(),this.inMemoryQueue=[],this.storageKey="EXP_unsent_".concat(e),this.maxQueueSize=t}return e.prototype.push=function(e){this.loadQueue(),this.inMemoryQueue.push(e),this.flush(),this.storeQueue()},e.prototype.setTracker=function(e){var t=this;this.tracker=e,this.poller=me.setInterval((function(){t.loadFlushStore()}),1e3),this.loadFlushStore()},e.prototype.flush=function(){var e,t;if(this.tracker&&0!==this.inMemoryQueue.length){try{for(var r=a(this.inMemoryQueue),i=r.next();!i.done;i=r.next()){var n=i.value;try{if(!this.tracker(n))return}catch(e){return}}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}this.inMemoryQueue=[],this.poller&&(me.clearInterval(this.poller),this.poller=void 0)}},e.prototype.loadQueue=function(){if(this.isLocalStorageAvailable){var e=me.localStorage.getItem(this.storageKey);this.inMemoryQueue=e?JSON.parse(e):[]}},e.prototype.storeQueue=function(){this.isLocalStorageAvailable&&(this.inMemoryQueue.length>this.maxQueueSize&&(this.inMemoryQueue=this.inMemoryQueue.slice(this.inMemoryQueue.length-this.maxQueueSize)),me.localStorage.setItem(this.storageKey,JSON.stringify(this.inMemoryQueue)))},e.prototype.loadFlushStore=function(){this.loadQueue(),this.flush(),this.storeQueue()},e}(),Qe=function(){var e=we();if(e)try{var t="EXP_test";return e.sessionStorage.setItem(t,t),e.sessionStorage.removeItem(t),!0}catch(e){return!1}return!1},$e=function(){function t(t,r){void 0===r&&(r=e.LogLevel.Error),this.logger=t,this.logLevel=r}return t.prototype.error=function(t){for(var r,i=[],n=1;n<arguments.length;n++)i[n-1]=arguments[n];this.logLevel>=e.LogLevel.Error&&(r=this.logger).error.apply(r,u([t],s(i),!1))},t.prototype.warn=function(t){for(var r,i=[],n=1;n<arguments.length;n++)i[n-1]=arguments[n];this.logLevel>=e.LogLevel.Warn&&(r=this.logger).warn.apply(r,u([t],s(i),!1))},t.prototype.info=function(t){for(var r,i=[],n=1;n<arguments.length;n++)i[n-1]=arguments[n];this.logLevel>=e.LogLevel.Info&&(r=this.logger).info.apply(r,u([t],s(i),!1))},t.prototype.debug=function(t){for(var r,i=[],n=1;n<arguments.length;n++)i[n-1]=arguments[n];this.logLevel>=e.LogLevel.Debug&&(r=this.logger).debug.apply(r,u([t],s(i),!1))},t.prototype.verbose=function(t){for(var r,i=[],n=1;n<arguments.length;n++)i[n-1]=arguments[n];this.logLevel>=e.LogLevel.Verbose&&(r=this.logger).verbose.apply(r,u([t],s(i),!1))},t}(),Xe=function(){function e(){}return e.prototype.error=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];console.error.apply(console,u([e],s(t),!1))},e.prototype.warn=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];console.warn.apply(console,u([e],s(t),!1))},e.prototype.info=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];console.info.apply(console,u([e],s(t),!1))},e.prototype.debug=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];console.debug.apply(console,u([e],s(t),!1))},e.prototype.verbose=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];console.debug.apply(console,u([e],s(t),!1))},e}(),Ze=function(){function e(){this.globalScope=we()}return e.prototype.get=function(e){var t;return null===(t=this.globalScope)||void 0===t?void 0:t.localStorage.getItem(e)},e.prototype.put=function(e,t){var r;null===(r=this.globalScope)||void 0===r||r.localStorage.setItem(e,t)},e.prototype.delete=function(e){var t;null===(t=this.globalScope)||void 0===t||t.localStorage.removeItem(e)},e}(),He=function(){function e(e,t,r){this.cache={},this.namespace=e,this.storage=t,this.transformer=r}return e.prototype.get=function(e){return this.cache[e]},e.prototype.getAll=function(){return i({},this.cache)},e.prototype.put=function(e,t){this.cache[e]=t},e.prototype.putAll=function(e){var t,r;try{for(var i=a(Object.keys(e)),n=i.next();!n.done;n=i.next()){var o=n.value;this.cache[o]=e[o]}}catch(e){t={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}},e.prototype.remove=function(e){delete this.cache[e]},e.prototype.clear=function(){this.cache={}},e.prototype.load=function(){var e,t,r,i=this.storage.get(this.namespace);try{r=JSON.parse(i)||{}}catch(e){return}var n={};try{for(var o=a(Object.keys(r)),s=o.next();!s.done;s=o.next()){var u=s.value;try{var l=void 0;(l=this.transformer?this.transformer(r[u]):r[u])&&(n[u]=l)}catch(e){}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}this.clear(),this.putAll(n)},e.prototype.store=function(e){void 0===e&&(e=this.cache),this.storage.put(this.namespace,JSON.stringify(e))},e}(),Ge=function(e){if("string"==typeof e)return{key:e,value:e};if("object"==typeof e){var t=e.key,r=e.value,i=e.payload,n=e.metadata,o=e.expKey;n&&n.experimentKey?o=n.experimentKey:o&&((n=n||{}).experimentKey=o);var a={};return t?a.key=t:r&&(a.key=r),r&&(a.value=r),n&&(a.metadata=n),i&&(a.payload=i),o&&(a.expKey=o),a}},Ye=function(){function e(){this.globalScope=we()}return e.prototype.get=function(e){var t;return null===(t=this.globalScope)||void 0===t?void 0:t.sessionStorage.getItem(e)},e.prototype.put=function(e,t){var r;null===(r=this.globalScope)||void 0===r||r.sessionStorage.setItem(e,t)},e.prototype.delete=function(e){var t;null===(t=this.globalScope)||void 0===t||t.sessionStorage.removeItem(e)},e}(),et=function(e){return null==e},tt=function(e){return!!et(e)||e&&0===Object.keys(e).length},rt=function(e){var t;return"local"===(null===(t=null==e?void 0:e.metadata)||void 0===t?void 0:t.evaluationMode)},it=function(){function e(e,t,r,i){this.started=!1,this.done=!1,this.attempts=e,this.min=t,this.max=r,this.scalar=i}return e.prototype.start=function(e){return n(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:if(this.started)throw Error("Backoff already started");return this.started=!0,[4,this.backoff(e,0,this.min)];case 1:return t.sent(),[2]}}))}))},e.prototype.cancel=function(){this.done=!0,clearTimeout(this.timeoutHandle)},e.prototype.backoff=function(e,t,r){return n(this,void 0,void 0,(function(){var i=this;return o(this,(function(a){return this.done||(this.timeoutHandle=me.setTimeout((function(){return n(i,void 0,void 0,(function(){var i,n;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,e()];case 1:return o.sent(),[3,3];case 2:return o.sent(),(i=t+1)<this.attempts&&(n=Math.min(r*this.scalar,this.max),this.backoff(e,i,n)),[3,3];case 3:return[2]}}))}))}),r)),[2]}))}))},e}(),nt=function(e){return null==e?{}:"string"==typeof e?{key:e,value:e}:e},ot=function(e){if(!e)return{};var t=void 0;e.metadata&&(t=e.metadata.experimentKey);var r={};return e.key&&(r.key=e.key),e.value&&(r.value=e.value),e.payload&&(r.payload=e.payload),t&&(r.expKey=t),e.metadata&&(r.metadata=e.metadata),r},at=function(){function e(e){this.setProperties={},this.unsetProperties={},this.analyticsProvider=e}return e.prototype.track=function(e){this.setProperties[e.key]!=e.variant.value&&(this.setProperties[e.key]=e.variant.value,delete this.unsetProperties[e.key],this.analyticsProvider.track(e))},e.prototype.setUserProperty=function(e){this.setProperties[e.key]!=e.variant.value&&this.analyticsProvider.setUserProperty(e)},e.prototype.unsetUserProperty=function(e){this.unsetProperties[e.key]||(this.unsetProperties[e.key]="unset",delete this.setProperties[e.key],this.analyticsProvider.unsetUserProperty(e))},e}(),st=function(){function e(e){this.tracked={},this.identity={},this.exposureTrackingProvider=e}return e.prototype.track=function(e,t){var r={userId:null==t?void 0:t.user_id,deviceId:null==t?void 0:t.device_id};this.identityEquals(this.identity,r)||(this.tracked={}),this.identity=r;var i=e.flag_key in this.tracked,n=this.tracked[e.flag_key];i&&n===e.variant||(this.tracked[e.flag_key]=e.variant,this.exposureTrackingProvider.track(e))},e.prototype.identityEquals=function(e,t){return e.userId===t.userId&&e.deviceId===t.deviceId},e}(),ut=function(){function t(e,r){var n,o,u,l,c=this;this.engine=new $,this.isRunning=!1,this.apiKey=e,r=function(e){var t,r;if(!e||"object"!=typeof e)return{};var i={};try{for(var n=a(Object.entries(e)),o=n.next();!o.done;o=n.next()){var u=s(o.value,2),l=u[0],c=u[1];et(c)||(i[l]=c)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(t)throw t.error}}return i}(r),this.config=i(i(i({},Ke),r),{serverUrl:(null==r?void 0:r.serverUrl)||("eu"===(null===(n=null==r?void 0:r.serverZone)||void 0===n?void 0:n.toLowerCase())?"https://api.lab.eu.amplitude.com":Ke.serverUrl),flagsServerUrl:(null==r?void 0:r.flagsServerUrl)||("eu"===(null===(o=null==r?void 0:r.serverZone)||void 0===o?void 0:o.toLowerCase())?"https://flag.lab.eu.amplitude.com":Ke.flagsServerUrl),flagConfigPollingIntervalMillis:r.flagConfigPollingIntervalMillis<6e4?6e4:null!==(u=r.flagConfigPollingIntervalMillis)&&void 0!==u?u:Ke.flagConfigPollingIntervalMillis}),this.logger=new $e(this.config.loggerProvider||new Xe,t.getLogLevel(r));var f=null===(l=this.config)||void 0===l?void 0:l.internalInstanceNameSuffix;if(this.isWebExperiment="web"===f,this.poller=new xe((function(){return c.doFlags()}),this.config.flagConfigPollingIntervalMillis),this.config.initialVariants)for(var h in this.config.initialVariants)this.config.initialVariants[h]=Ge(this.config.initialVariants[h]);this.config.userProvider&&(this.userProvider=this.config.userProvider),this.config.analyticsProvider&&(this.analyticsProvider=new at(this.config.analyticsProvider)),this.config.exposureTrackingProvider&&(this.userSessionExposureTracker=new st(this.config.exposureTrackingProvider)),this.integrationManager=new Be(this.config,this);var d,p=new qe(this.config.httpClient||Re);this.flagApi=new be(this.apiKey,this.config.flagsServerUrl,p),this.evaluationApi=new ge(this.apiKey,this.config.serverUrl,p);var v=f?"".concat(this.config.instanceName,"-").concat(f):this.config.instanceName;d=this.isWebExperiment?new Ye:new Ze,this.variants=function(e,t,r){var i=e.substring(e.length-6),n="amp-exp-".concat(t,"-").concat(i);return new He(n,r,Ge)}(this.apiKey,v,d),this.flags=function(e,t,r){void 0===r&&(r=new Ze);var i=e.substring(e.length-6),n="amp-exp-".concat(t,"-").concat(i,"-flags");return new He(n,r)}(this.apiKey,v,d);try{this.flags.load(),this.variants.load()}catch(e){}this.mergeInitialFlagsWithStorage()}return t.prototype.start=function(e){return n(this,void 0,void 0,(function(){var t,r,i;return o(this,(function(n){switch(n.label){case 0:if(this.isRunning)return[2];this.isRunning=!0,this.setUser(e),n.label=1;case 1:return n.trys.push([1,6,,7]),t=this.doFlags(),null===(i=this.config.fetchOnStart)||void 0===i||i?[4,Promise.all([this.fetch(e),t])]:[3,3];case 2:return n.sent(),[3,5];case 3:return[4,t];case 4:n.sent(),n.label=5;case 5:return[3,7];case 6:if(r=n.sent(),this.config.throwOnError)throw r;return[3,7];case 7:return this.config.pollOnStart&&this.poller.start(),[2]}}))}))},t.prototype.stop=function(){this.isRunning&&(this.poller.stop(),this.isRunning=!1)},t.prototype.fetch=function(){return n(this,arguments,void 0,(function(e,t){var r;return void 0===e&&(e=this.user),o(this,(function(i){switch(i.label){case 0:this.setUser(e||{}),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.fetchInternal(e,this.config.fetchTimeoutMillis,this.config.retryFetchOnFailure,t)];case 2:return i.sent(),[3,4];case 3:if(r=i.sent(),this.config.throwOnError)throw r;return r instanceof ye?this.logger.debug(r):this.logger.error(r),[3,4];case 4:return[2,this]}}))}))},t.prototype.variant=function(e,t){var r,i;if(!this.apiKey)return{value:void 0};var n=this.variantAndSource(e,t);return this.config.automaticExposureTracking&&this.exposureInternal(e,n),this.logger.debug("[Experiment] variant for ".concat(e," is ").concat((null===(r=n.variant)||void 0===r?void 0:r.key)||(null===(i=n.variant)||void 0===i?void 0:i.value))),n.variant||{}},t.prototype.exposure=function(e){var t=this.variantAndSource(e);this.exposureInternal(e,t)},t.prototype.all=function(){if(!this.apiKey)return{};var e=this.evaluate();for(var t in e){var r=this.flags.get(t);rt(r)||delete e[t]}return i(i(i({},this.secondaryVariants()),this.sourceVariants()),e)},t.prototype.clear=function(){this.variants.clear();try{this.variants.store()}catch(e){}},t.prototype.getUser=function(){var e;if(!this.user)return this.user;if(null===(e=this.user)||void 0===e?void 0:e.user_properties){var t=i({},this.user.user_properties);return i(i({},this.user),{user_properties:t})}return i({},this.user)},t.prototype.setUser=function(e){var t;if(e)if(null===(t=this.user)||void 0===t?void 0:t.user_properties){var r=i({},e.user_properties);this.user=i(i({},e),{user_properties:r})}else this.user=i({},e);else this.user=null},t.prototype.getUserProvider=function(){return this.userProvider},t.prototype.setUserProvider=function(e){return this.userProvider=e,this},t.prototype.mergeInitialFlagsWithStorage=function(){var e=this;this.config.initialFlags&&JSON.parse(this.config.initialFlags).forEach((function(t){e.flags.get(t.key)||e.flags.put(t.key,t)}))},t.prototype.evaluate=function(e){var t,r,i=this.addContext(this.user),n=function(e,t){var r,i,n=f({},e),o=[],a=t||Object.keys(n);try{for(var s=p(a),u=s.next();!u.done;u=s.next()){var l=u.value,c=X(l,n);c&&o.push.apply(o,y([],v(c),!1))}}catch(e){r={error:e}}finally{try{u&&!u.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return o}(this.flags.getAll(),e),o=function(e){var t,r,i,n;if(!e)return{};var o={user:e},s=we();s&&(o.page={url:s.location.href});var u={};if(!e.groups)return o;try{for(var l=a(Object.keys(e.groups)),c=l.next();!c.done;c=l.next()){var f=c.value,h=e.groups[f];if(h.length>0&&h[0]){var d=h[0],p={group_name:d},v=null===(n=null===(i=e.group_properties)||void 0===i?void 0:i[f])||void 0===n?void 0:n[d];v&&Object.keys(v).length>0&&(p.group_properties=v),u[f]=p}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}return Object.keys(u).length>0&&(o.groups=u),delete o.user.groups,delete o.user.group_properties,o}(i),s=this.engine.evaluate(o,n),u={};try{for(var l=a(Object.keys(s)),c=l.next();!c.done;c=l.next()){var h=c.value;u[h]=ot(s[h])}}catch(e){t={error:e}}finally{try{c&&!c.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}return u},t.prototype.variantAndSource=function(t,r){var i={};this.config.source===e.Source.LocalStorage?i=this.localStorageVariantAndSource(t,r):this.config.source===e.Source.InitialVariants&&(i=this.initialVariantsVariantAndSource(t,r));var n=this.flags.get(t);return(rt(n)||!i.variant&&n)&&(i=this.localEvaluationVariantAndSource(t,n,r)),i},t.prototype.localEvaluationVariantAndSource=function(e,t,r){var i,n={},o=this.evaluate([t.key])[e],a=Ne.LocalEvaluation,s=null===(i=null==o?void 0:o.metadata)||void 0===i?void 0:i.default;if(!et(o)&&!s)return{variant:nt(o),source:a,hasDefaultVariant:!1};if(s&&(n={variant:nt(o),source:a,hasDefaultVariant:!0}),!et(r))return{variant:nt(r),source:Ne.FallbackInline,hasDefaultVariant:n.hasDefaultVariant};var u=this.config.initialVariants[e];if(!et(u))return{variant:nt(u),source:Ne.SecondaryInitialVariants,hasDefaultVariant:n.hasDefaultVariant};var l=nt(this.config.fallbackVariant),c={variant:l,source:Ne.FallbackConfig,hasDefaultVariant:n.hasDefaultVariant};return tt(l)?n:c},t.prototype.localStorageVariantAndSource=function(e,t){var r,i={},n=this.variants.get(e),o=null===(r=null==n?void 0:n.metadata)||void 0===r?void 0:r.default;if(!et(n)&&!o)return{variant:nt(n),source:Ne.LocalStorage,hasDefaultVariant:!1};if(o&&(i={variant:nt(n),source:Ne.LocalStorage,hasDefaultVariant:!0}),!et(t))return{variant:nt(t),source:Ne.FallbackInline,hasDefaultVariant:i.hasDefaultVariant};var a=this.config.initialVariants[e];if(!et(a))return{variant:nt(a),source:Ne.SecondaryInitialVariants,hasDefaultVariant:i.hasDefaultVariant};var s=nt(this.config.fallbackVa