UNPKG

@amplitude/unified

Version:

Official Amplitude SDK for Web analytics, experiment, session replay, and more.

1 lines 693 kB
!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).amplitude={})}(this,function(e){"use strict";function t(e,t){return t.forEach(function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach(function(r){if("default"!==r&&!(r in e)){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})}})}),Object.freeze(e)}var r=function(e,t){return r=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])},r(e,t)};function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var i,o,s=function(){return s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},s.apply(this,arguments)};function a(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function l(e,t,r,n){return new(r||(r=Promise))(function(i,o){function s(e){try{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,a)}l((n=n.apply(e,t||[])).next())})}function u(e,t){var r,n,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}}function c(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function h(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}function d(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(i||(i={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(o||(o={}));var f,p="AMP",g="".concat(p,"_unsent"),v="$default_instance",m="https://api2.amplitude.com/2/httpapi",y="https://api.eu.amplitude.com/2/httpapi",b="https://api2.amplitude.com/batch",w="https://api.eu.amplitude.com/batch",S="dclid",k="fbclid",x="gbraid",C="gclid",E="ko_click_id",O="li_fat_id",I="msclkid",P="rdt_cid",T="ttclid",R="twclid",A="wbraid",M={utm_campaign:void 0,utm_content:void 0,utm_id:void 0,utm_medium:void 0,utm_source:void 0,utm_term:void 0,referrer:void 0,referring_domain:void 0,dclid:void 0,gbraid:void 0,gclid:void 0,fbclid:void 0,ko_click_id:void 0,li_fat_id:void 0,msclkid:void 0,rdt_cid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},_=["access-control-allow-origin","access-control-allow-credentials","access-control-expose-headers","access-control-max-age","access-control-allow-methods","access-control-allow-headers","accept-patch","accept-ranges","age","allow","alt-svc","cache-control","connection","content-disposition","content-encoding","content-language","content-length","content-location","content-md5","content-range","content-type","date","delta-base","etag","expires","im","last-modified","link","location","permanent","p3p","pragma","proxy-authenticate","public-key-pins","retry-after","server","status","strict-transport-security","trailer","transfer-encoding","tk","upgrade","vary","via","warning","www-authenticate","x-b3-traceid","x-frame-options"],N=["authorization","cookie","set-cookie"],L=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!D(t,r))return!1}return!0},D=function(e,t){var r,n;if("string"!=typeof e)return!1;if(Array.isArray(t)){var i=!0;try{for(var o=c(t),s=o.next();!s.done;s=o.next()){var a=s.value;if(Array.isArray(a))return!1;if("object"==typeof a)i=i&&L(a);else if(!["number","string"].includes(typeof a))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return L(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},U=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return s({},this._properties)},e.prototype.set=function(e,t){return this._safeSet(f.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(f.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(f.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(f.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(f.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(f.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(f.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(f.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(f.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[f.CLEAR_ALL]="-",this},e.prototype._safeSet=function(e,t,r){if(this._validate(e,t,r)){var n=this._properties[e];return void 0===n&&(n={},this._properties[e]=n),n[t]=r,this._propertySet.add(t),!0}return!1},e.prototype._validate=function(e,t,r){return void 0===this._properties[f.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===f.ADD?"number"==typeof r:e===f.UNSET||e===f.REMOVE||D(t,r)))},e}();!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(f||(f={}));var F,j=[f.CLEAR_ALL,f.UNSET,f.SET,f.SET_ONCE,f.ADD,f.APPEND,f.PREPEND,f.PREINSERT,f.POSTINSERT,f.REMOVE];!function(e){e.Unknown="unknown",e.Skipped="skipped",e.Success="success",e.RateLimit="rate_limit",e.PayloadTooLarge="payload_too_large",e.Invalid="invalid",e.Failed="failed",e.Timeout="Timeout",e.SystemError="SystemError"}(F||(F={}));var B,q=function(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=F.Unknown),{event:e,code:t,message:r}},z=function(){var e="ampIntegrationContext";return"undefined"!=typeof globalThis&&void 0!==globalThis[e]?globalThis[e]:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0},W=d([],h(Array(256).keys()),!1).map(function(e){return e.toString(16).padStart(2,"0")}),V=function(e){var t,r=z();if(!(null===(t=null==r?void 0:r.crypto)||void 0===t?void 0:t.getRandomValues))return function(e){return e?(e^16*Math.random()>>e/4).toString(16):(String(1e7)+String(-1e3)+String(-4e3)+String(-8e3)+String(-1e11)).replace(/[018]/g,V)}(e);var n=r.crypto.getRandomValues(new Uint8Array(16));return n[6]=15&n[6]|64,n[8]=63&n[8]|128,d([],h(n.entries()),!1).map(function(e){var t=h(e,2),r=t[0],n=t[1];return[4,6,8,10].includes(r)?"-".concat(W[n]):W[n]}).join("")},$=function(){function e(e){this.client=e,this.queue=[],this.applying=!1,this.plugins=[],this._optOutListeners=[]}return e.prototype.register=function(e,t){var r,n;return l(this,void 0,void 0,function(){return u(this,function(i){switch(i.label){case 0:return this.plugins.some(function(t){return t.name===e.name})?(this.loggerProvider.warn("Plugin with name ".concat(e.name," already exists, skipping registration")),[2]):(void 0===e.name&&(e.name=V(),this.loggerProvider.warn("Plugin name is undefined. \n Generating a random UUID for plugin name: ".concat(e.name,". \n Set a name for the plugin to prevent it from being added multiple times."))),e.type=null!==(r=e.type)&&void 0!==r?r:"enrichment",[4,null===(n=e.setup)||void 0===n?void 0:n.call(e,t,this.client)]);case 1:return i.sent(),this.plugins.push(e),[2]}})})},e.prototype.deregister=function(e,t){var r;return l(this,void 0,void 0,function(){var n,i;return u(this,function(o){switch(o.label){case 0:return n=this.plugins.findIndex(function(t){return t.name===e}),-1===n?(t.loggerProvider.warn("Plugin with name ".concat(e," does not exist, skipping deregistration")),[2]):(i=this.plugins[n],this.plugins.splice(n,1),[4,null===(r=i.teardown)||void 0===r?void 0:r.call(i)]);case 1:return o.sent(),[2]}})})},e.prototype.reset=function(e){this._clearOptOutListeners(),this.applying=!1,this.plugins.map(function(e){var t;return null===(t=e.teardown)||void 0===t?void 0:t.call(e)}),this.plugins=[],this.client=e},e.prototype.push=function(e){var t=this;return new Promise(function(r){t.queue.push([e,r]),t.scheduleApply(0)})},e.prototype.scheduleApply=function(e){var t=this;this.applying||(this.applying=!0,setTimeout(function(){t.apply(t.queue.shift()).then(function(){t.applying=!1,t.queue.length>0&&t.scheduleApply(0)})},e))},e.prototype.apply=function(e){return l(this,void 0,void 0,function(){var t,r,n,i,o,a,l,d,f,p,g,v,m,y,b,w,S,k,x,C;return u(this,function(u){switch(u.label){case 0:if(!e)return[2];t=h(e,1),r=t[0],n=h(e,2),i=n[1],this.loggerProvider.log("Timeline.apply: Initial event",r),o=this.plugins.filter(function(e){return"before"===e.type}),u.label=1;case 1:u.trys.push([1,6,7,8]),a=c(o),l=a.next(),u.label=2;case 2:return l.done?[3,5]:(v=l.value).execute?[4,v.execute(s({},r))]:[3,4];case 3:if(null===(m=u.sent()))return this.loggerProvider.log("Timeline.apply: Event filtered out by before plugin '".concat(String(v.name),"', event: ").concat(JSON.stringify(r))),i({event:r,code:0,message:""}),[2];r=m,this.loggerProvider.log("Timeline.apply: Event after before plugin '".concat(String(v.name),"', event: ").concat(JSON.stringify(r))),u.label=4;case 4:return l=a.next(),[3,2];case 5:return[3,8];case 6:return d=u.sent(),S={error:d},[3,8];case 7:try{l&&!l.done&&(k=a.return)&&k.call(a)}finally{if(S)throw S.error}return[7];case 8:f=this.plugins.filter(function(e){return"enrichment"===e.type||void 0===e.type}),u.label=9;case 9:u.trys.push([9,14,15,16]),p=c(f),g=p.next(),u.label=10;case 10:return g.done?[3,13]:(v=g.value).execute?[4,v.execute(s({},r))]:[3,12];case 11:if(null===(m=u.sent()))return this.loggerProvider.log("Timeline.apply: Event filtered out by enrichment plugin '".concat(String(v.name),"', event: ").concat(JSON.stringify(r))),i({event:r,code:0,message:""}),[2];r=m,this.loggerProvider.log("Timeline.apply: Event after enrichment plugin '".concat(String(v.name),"', event: ").concat(JSON.stringify(r))),u.label=12;case 12:return g=p.next(),[3,10];case 13:return[3,16];case 14:return y=u.sent(),x={error:y},[3,16];case 15:try{g&&!g.done&&(C=p.return)&&C.call(p)}finally{if(x)throw x.error}return[7];case 16:return b=this.plugins.filter(function(e){return"destination"===e.type}),this.loggerProvider.log("Timeline.apply: Final event before destinations, event: ".concat(JSON.stringify(r))),w=b.map(function(e){var t=s({},r);return e.execute(t).catch(function(e){return q(t,0,String(e))})}),Promise.all(w).then(function(e){var t=h(e,1)[0]||q(r,100,"Event not tracked, no destination plugins on the instance");i(t)}),[2]}})})},e.prototype.flush=function(){return l(this,void 0,void 0,function(){var e,t,r,n=this;return u(this,function(i){switch(i.label){case 0:return e=this.queue,this.queue=[],[4,Promise.all(e.map(function(e){return n.apply(e)}))];case 1:return i.sent(),t=this.plugins.filter(function(e){return"destination"===e.type}),r=t.map(function(e){return e.flush&&e.flush()}),[4,Promise.all(r)];case 2:return i.sent(),[2]}})})},e.prototype.addOptOutListener=function(e){this._optOutListeners.push(e)},e.prototype._clearOptOutListeners=function(){this._optOutListeners=[]},e.prototype.onIdentityChanged=function(e){this.plugins.forEach(function(t){var r;null===(r=t.onIdentityChanged)||void 0===r||r.call(t,e)})},e.prototype.onSessionIdChanged=function(e){this.plugins.forEach(function(t){var r;null===(r=t.onSessionIdChanged)||void 0===r||r.call(t,e)})},e.prototype.onOptOutChanged=function(e){this.plugins.forEach(function(t){var r;null===(r=t.onOptOutChanged)||void 0===r||r.call(t,e)}),this._callOptOutListeners(e)},e.prototype._callOptOutListeners=function(e){return l(this,void 0,void 0,function(){var t,r,n,i,o,s,a;return u(this,function(l){switch(l.label){case 0:l.trys.push([0,7,8,9]),t=c(this._optOutListeners),r=t.next(),l.label=1;case 1:if(r.done)return[3,6];n=r.value,l.label=2;case 2:return l.trys.push([2,4,,5]),[4,n(e)];case 3:return l.sent(),[3,5];case 4:return i=l.sent(),this.loggerProvider.error("Error calling optOut listener",i),[3,5];case 5:return r=t.next(),[3,1];case 6:return[3,9];case 7:return o=l.sent(),s={error:o},[3,9];case 8:try{r&&!r.done&&(a=t.return)&&a.call(t)}finally{if(s)throw s.error}return[7];case 9:return[2]}})})},e.prototype.onReset=function(){this.plugins.forEach(function(e){var t;null===(t=e.onReset)||void 0===t||t.call(e)})},e}(),H=function(e,t){return s(s({},t),{event_type:o.IDENTIFY,user_properties:e.getUserProperties()})},K=function(e){return{promise:e||Promise.resolve()}},J=function(){function e(e){void 0===e&&(e="$default"),this.initializing=!1,this.isReady=!1,this.q=[],this.dispatchQ=[],this.logEvent=this.track.bind(this),this.timeline=new $(this),this.name=e}return e.prototype._init=function(e){return l(this,void 0,void 0,function(){return u(this,function(t){switch(t.label){case 0:return this.config=e,this.timeline.reset(this),this.timeline.loggerProvider=this.config.loggerProvider,[4,this.runQueuedFunctions("q")];case 1:return t.sent(),this.isReady=!0,[2]}})})},e.prototype.runQueuedFunctions=function(e){return l(this,void 0,void 0,function(){var t,r,n,i,o,s,a,l;return u(this,function(u){switch(u.label){case 0:t=this[e],this[e]=[],u.label=1;case 1:u.trys.push([1,8,9,10]),r=c(t),n=r.next(),u.label=2;case 2:return n.done?[3,7]:(i=n.value,(o=i())&&"promise"in o?[4,o.promise]:[3,4]);case 3:return u.sent(),[3,6];case 4:return[4,o];case 5:u.sent(),u.label=6;case 6:return n=r.next(),[3,2];case 7:return[3,10];case 8:return s=u.sent(),a={error:s},[3,10];case 9:try{n&&!n.done&&(l=r.return)&&l.call(r)}finally{if(a)throw a.error}return[7];case 10:return this[e].length?[4,this.runQueuedFunctions(e)]:[3,12];case 11:u.sent(),u.label=12;case 12:return[2]}})})},e.prototype.track=function(e,t,r){var n=function(e,t,r){return s(s(s({},"string"==typeof e?{event_type:e}:e),r),t&&{event_properties:t})}(e,t,r);return this.userProperties=this.getOperationAppliedUserProperties(n.user_properties),K(this.dispatch(n))},e.prototype.identify=function(e,t){var r=H(e,t);return this.userProperties=this.getOperationAppliedUserProperties(r.user_properties),K(this.dispatch(r))},e.prototype.groupIdentify=function(e,t,r,n){var i=function(e,t,r,n){var i;return s(s({},n),{event_type:o.GROUP_IDENTIFY,group_properties:r.getUserProperties(),groups:(i={},i[e]=t,i)})}(e,t,r,n);return K(this.dispatch(i))},e.prototype.setGroup=function(e,t,r){var n=function(e,t,r){var n,i=new U;return i.set(e,t),s(s({},r),{event_type:o.IDENTIFY,user_properties:i.getUserProperties(),groups:(n={},n[e]=t,n)})}(e,t,r);return this.userProperties=this.getOperationAppliedUserProperties(n.user_properties),K(this.dispatch(n))},e.prototype.revenue=function(e,t){var r=function(e,t){return s(s({},t),{event_type:o.REVENUE,event_properties:e.getEventProperties()})}(e,t);return K(this.dispatch(r))},e.prototype.add=function(e){return this.isReady?this._addPlugin(e):(this.q.push(this._addPlugin.bind(this,e)),K())},e.prototype._addPlugin=function(e){return K(this.timeline.register(e,this.config))},e.prototype.remove=function(e){return this.isReady?this._removePlugin(e):(this.q.push(this._removePlugin.bind(this,e)),K())},e.prototype._removePlugin=function(e){return K(this.timeline.deregister(e,this.config))},e.prototype.dispatchWithCallback=function(e,t){if(!this.isReady)return t(q(e,0,"Client not initialized"));this.process(e).then(t)},e.prototype.dispatch=function(e){return l(this,void 0,void 0,function(){var t=this;return u(this,function(r){return this.isReady?[2,this.process(e)]:[2,new Promise(function(r){t.dispatchQ.push(t.dispatchWithCallback.bind(t,e,r))})]})})},e.prototype.getOperationAppliedUserProperties=function(e){var t,r=null!==(t=this.userProperties)&&void 0!==t?t:{},n=s({},r);if(void 0===e)return n;var o={};return Object.keys(e).forEach(function(t){Object.values(i).includes(t)||(o[t]=e[t])}),j.forEach(function(t){if(Object.keys(e).includes(t)){var r=e[t];switch(t){case i.CLEAR_ALL:Object.keys(n).forEach(function(e){delete n[e]});break;case i.UNSET:Object.keys(r).forEach(function(e){delete n[e]});break;case i.SET:Object.assign(n,r)}}}),Object.assign(n,o),n},e.prototype.process=function(e){return l(this,void 0,void 0,function(){var t,r,n;return u(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),this.config.optOut?[2,q(e,0,"Event skipped due to optOut config")]:(e.event_type===o.IDENTIFY&&this.timeline.onIdentityChanged({userProperties:this.userProperties}),[4,this.timeline.push(e)]);case 1:return 200===(n=i.sent()).code?this.config.loggerProvider.log(n.message):100===n.code?this.config.loggerProvider.warn(n.message):this.config.loggerProvider.error(n.message),[2,n];case 2:return t=i.sent(),r=String(t),this.config.loggerProvider.error(r),[2,n=q(e,0,r)];case 3:return[2]}})})},e.prototype.setOptOut=function(e){this.isReady?this._setOptOut(e):this.q.push(this._setOptOut.bind(this,Boolean(e)))},e.prototype._setOptOut=function(e){this.config.optOut!==e&&(this.config.optOut=Boolean(e),this.timeline.onOptOutChanged(e))},e.prototype.flush=function(){return K(this.timeline.flush())},e.prototype.plugin=function(e){var t=this.timeline.plugins.find(function(t){return t.name===e});if(void 0!==t)return t;this.config.loggerProvider.debug("Cannot find plugin with name ".concat(e))},e.prototype.plugins=function(e){return this.timeline.plugins.filter(function(t){return t instanceof e})},e}(),G=function(){function e(){this.productId="",this.quantity=1,this.price=0}return e.prototype.setProductId=function(e){return this.productId=e,this},e.prototype.setQuantity=function(e){return e>0&&(this.quantity=e),this},e.prototype.setPrice=function(e){return this.price=e,this},e.prototype.setRevenueType=function(e){return this.revenueType=e,this},e.prototype.setCurrency=function(e){return this.currency=e,this},e.prototype.setRevenue=function(e){return this.revenue=e,this},e.prototype.setReceipt=function(e){return this.receipt=e,this},e.prototype.setReceiptSig=function(e){return this.receiptSig=e,this},e.prototype.setEventProperties=function(e){return L(e)&&(this.properties=e),this},e.prototype.getEventProperties=function(){var e=this.properties?s({},this.properties):{};return e[B.REVENUE_PRODUCT_ID]=this.productId,e[B.REVENUE_QUANTITY]=this.quantity,e[B.REVENUE_PRICE]=this.price,e[B.REVENUE_TYPE]=this.revenueType,e[B.REVENUE_CURRENCY]=this.currency,e[B.REVENUE]=this.revenue,e[B.RECEIPT]=this.receipt,e[B.RECEIPT_SIG]=this.receiptSig,e},e}();!function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE_CURRENCY="$currency",e.REVENUE="$revenue",e.RECEIPT="$receipt",e.RECEIPT_SIG="$receiptSig"}(B||(B={}));var Y;!function(e){e[e.None=0]="None",e[e.Error=1]="Error",e[e.Warn=2]="Warn",e[e.Verbose=3]="Verbose",e[e.Debug=4]="Debug"}(Y||(Y={}));var X="Amplitude Logger ",Q=function(){function e(){this.logLevel=Y.None}return e.prototype.disable=function(){this.logLevel=Y.None},e.prototype.enable=function(e){void 0===e&&(e=Y.Warn),this.logLevel=e},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<Y.Verbose||console.log("".concat(X,"[Log]: ").concat(e.join(" ")))},e.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<Y.Warn||console.warn("".concat(X,"[Warn]: ").concat(e.join(" ")))},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<Y.Error||console.error("".concat(X,"[Error]: ").concat(e.join(" ")))},e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<Y.Debug||console.log("".concat(X,"[Debug]: ").concat(e.join(" ")))},e}(),Z=function(){return{flushMaxRetries:12,flushQueueSize:200,flushIntervalMillis:1e4,instanceName:v,logLevel:Y.Warn,loggerProvider:new Q,offline:!1,optOut:!1,serverUrl:m,serverZone:"US",useBatch:!1}},ee=function(){function e(e){var t,r,n,i;this._optOut=!1;var o=Z();this.apiKey=e.apiKey,this.flushIntervalMillis=null!==(t=e.flushIntervalMillis)&&void 0!==t?t:o.flushIntervalMillis,this.flushMaxRetries=e.flushMaxRetries||o.flushMaxRetries,this.flushQueueSize=e.flushQueueSize||o.flushQueueSize,this.instanceName=e.instanceName||o.instanceName,this.loggerProvider=e.loggerProvider||o.loggerProvider,this.logLevel=null!==(r=e.logLevel)&&void 0!==r?r:o.logLevel,this.minIdLength=e.minIdLength,this.plan=e.plan,this.ingestionMetadata=e.ingestionMetadata,this.offline=void 0!==e.offline?e.offline:o.offline,this.optOut=null!==(n=e.optOut)&&void 0!==n?n:o.optOut,this.serverUrl=e.serverUrl,this.serverZone=e.serverZone||o.serverZone,this.storageProvider=e.storageProvider,this.transportProvider=e.transportProvider,this.useBatch=null!==(i=e.useBatch)&&void 0!==i?i:o.useBatch,this.loggerProvider.enable(this.logLevel);var s=re(e.serverUrl,e.serverZone,e.useBatch);this.serverZone=s.serverZone,this.serverUrl=s.serverUrl}return Object.defineProperty(e.prototype,"optOut",{get:function(){return this._optOut},set:function(e){this._optOut=e},enumerable:!1,configurable:!0}),e}(),te=function(e,t){return"EU"===e?t?w:y:t?b:m},re=function(e,t,r){if(void 0===e&&(e=""),void 0===t&&(t=Z().serverZone),void 0===r&&(r=Z().useBatch),e)return{serverUrl:e,serverZone:void 0};var n=["US","EU"].includes(t)?t:Z().serverZone;return{serverZone:n,serverUrl:te(n,r)}},ne=function(){function e(){this.sdk={metrics:{histogram:{}}}}return e.prototype.recordHistogram=function(e,t){this.sdk.metrics.histogram[e]=t},e}();function ie(e){return e>=200&&e<300}var oe=function(e){return void 0===e&&(e=0),((new Error).stack||"").split("\n").slice(2+e).map(function(e){return e.trim()})},se=function(e){return function(){var t=s({},e.config);return{logger:t.loggerProvider,logLevel:t.logLevel}}},ae=function(e,t){var r,n;t=(t=t.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"");try{for(var i=c(t.split(".")),o=i.next();!o.done;o=i.next()){var s=o.value;if(!(s in e))return;e=e[s]}}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return e},le=function(e,t){return function(){var r,n,i={};try{for(var o=c(t),s=o.next();!s.done;s=o.next()){var a=s.value;i[a]=ae(e,a)}}catch(e){r={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return i}},ue=function(e,t,r,n,i){return void 0===i&&(i=null),function(){for(var o=[],s=0;s<arguments.length;s++)o[s]=arguments[s];var a=r(),l=a.logger,u=a.logLevel;if(u&&u<Y.Debug||!u||!l)return e.apply(i,o);var c={type:"invoke public method",name:t,args:o,stacktrace:oe(1),time:{start:(new Date).toISOString()},states:{}};n&&c.states&&(c.states.before=n());var h=e.apply(i,o);return h&&h.promise?h.promise.then(function(){n&&c.states&&(c.states.after=n()),c.time&&(c.time.end=(new Date).toISOString()),l.debug(JSON.stringify(c,null,2))}):(n&&c.states&&(c.states.after=n()),c.time&&(c.time.end=(new Date).toISOString()),l.debug(JSON.stringify(c,null,2))),h}},ce=new Set([m,y,b,w]);function he(e){var t="";try{"body"in e&&(t=JSON.stringify(e.body,null,2))}catch(e){}return t}var de=function(){function e(e){this.name="amplitude",this.type="destination",this.retryTimeout=1e3,this.throttleTimeout=3e4,this.storageKey="",this.scheduleId=null,this.scheduledTimeout=0,this.flushId=null,this.queue=[],this.diagnosticsClient=null==e?void 0:e.diagnosticsClient}return e.prototype.setup=function(e){var t;return l(this,void 0,void 0,function(){var r,n=this;return u(this,function(i){switch(i.label){case 0:return this.config=e,this.storageKey="".concat(g,"_").concat(this.config.apiKey.substring(0,10)),[4,null===(t=this.config.storageProvider)||void 0===t?void 0:t.get(this.storageKey)];case 1:return(r=i.sent())&&r.length>0&&Promise.all(r.map(function(e){return n.execute(e)})).catch(),[2,Promise.resolve(void 0)]}})})},e.prototype.execute=function(e){var t=this;return e.insert_id||(e.insert_id=V()),new Promise(function(r){var n={event:e,attempts:0,callback:function(e){return r(e)},timeout:0};t.queue.push(n),t.schedule(t.config.flushIntervalMillis),t.saveEvents()})},e.prototype.removeEventsExceedFlushMaxRetries=function(e){var t=this;return e.filter(function(e){return e.attempts+=1,e.attempts<t.config.flushMaxRetries||(t.fulfillRequest([e],500,"Event rejected due to exceeded retry count"),!1)})},e.prototype.scheduleEvents=function(e){var t=this;e.forEach(function(e){t.schedule(0===e.timeout?t.config.flushIntervalMillis:e.timeout)})},e.prototype.schedule=function(e){var t=this;if(!this.config.offline)return null===this.scheduleId||this.scheduleId&&e>this.scheduledTimeout?(this.scheduleId&&clearTimeout(this.scheduleId),this.scheduledTimeout=e,void(this.scheduleId=setTimeout(function(){t.queue=t.queue.map(function(e){return e.timeout=0,e}),t.flush(!0)},e))):void 0},e.prototype.resetSchedule=function(){this.scheduleId=null,this.scheduledTimeout=0},e.prototype.flush=function(e){return void 0===e&&(e=!1),l(this,void 0,void 0,function(){var t,r,n,i=this;return u(this,function(o){switch(o.label){case 0:return this.config.offline?(this.resetSchedule(),this.config.loggerProvider.debug("Skipping flush while offline."),[2]):this.flushId?(this.resetSchedule(),this.config.loggerProvider.debug("Skipping flush because previous flush has not resolved."),[2]):(this.flushId=this.scheduleId,this.resetSchedule(),t=[],r=[],this.queue.forEach(function(e){return 0===e.timeout?t.push(e):r.push(e)}),s=t,a=this.config.flushQueueSize,c=Math.max(a,1),n=s.reduce(function(e,t,r){var n=Math.floor(r/c);return e[n]||(e[n]=[]),e[n].push(t),e},[]),[4,n.reduce(function(t,r){return l(i,void 0,void 0,function(){return u(this,function(n){switch(n.label){case 0:return[4,t];case 1:return n.sent(),[4,this.send(r,e)];case 2:return[2,n.sent()]}})})},Promise.resolve())]);case 1:return o.sent(),this.flushId=null,this.scheduleEvents(this.queue),[2]}var s,a,c})})},e.prototype.send=function(e,t){var r;return void 0===t&&(t=!0),l(this,void 0,void 0,function(){var n,i,o,s,l,c;return u(this,function(u){switch(u.label){case 0:if(!this.config.apiKey)return[2,this.fulfillRequest(e,400,"Event rejected due to missing API key")];n={api_key:this.config.apiKey,events:e.map(function(e){var t=e.event;return t.extra,a(t,["extra"])}),options:{min_id_length:this.config.minIdLength},client_upload_time:(new Date).toISOString(),request_metadata:this.config.requestMetadata},this.config.requestMetadata=new ne,u.label=1;case 1:return u.trys.push([1,3,,4]),i=re(this.config.serverUrl,this.config.serverZone,this.config.useBatch).serverUrl,o=function(e,t){return void 0===t&&(t=!1),!!ce.has(e)||t}(i,this.config.enableRequestBodyCompression),[4,this.config.transportProvider.send(i,n,this.config._enableRequestBodyCompressionExperimental&&o)];case 2:return null===(s=u.sent())?(this.fulfillRequest(e,0,"Unexpected error occurred"),[2]):t?(this.handleResponse(s,e),[3,4]):("body"in s?this.fulfillRequest(e,s.statusCode,"".concat(s.status,": ").concat(he(s))):this.fulfillRequest(e,s.statusCode,s.status),[2]);case 3:return l=u.sent(),c=(h=l)instanceof Error?h.message:String(h),this.config.loggerProvider.error(c),null===(r=this.diagnosticsClient)||void 0===r||r.recordEvent("analytics.events.unsuccessful.from.catch.error",{events:e.map(function(e){return e.event.event_type}),message:c,stack_trace:oe()}),this.handleResponse({status:F.Failed,statusCode:0},e),[3,4];case 4:return[2]}var h})})},e.prototype.handleResponse=function(e,t){var r;ie(e.statusCode)||null===(r=this.diagnosticsClient)||void 0===r||r.recordEvent("analytics.events.unsuccessful",{events:t.map(function(e){return e.event.event_type}),code:e.statusCode,status:e.status,body:he(e),stack_trace:oe()});var n=e.status;switch(n){case F.Success:this.handleSuccessResponse(e,t);break;case F.Invalid:this.handleInvalidResponse(e,t);break;case F.PayloadTooLarge:this.handlePayloadTooLargeResponse(e,t);break;case F.RateLimit:this.handleRateLimitResponse(e,t);break;default:this.config.loggerProvider.warn("{code: 0, error: \"Status '".concat(n,"' provided for ").concat(t.length,' events"}')),this.handleOtherResponse(t)}},e.prototype.handleSuccessResponse=function(e,t){this.fulfillRequest(t,e.statusCode,"Event tracked successfully")},e.prototype.handleInvalidResponse=function(e,t){var r=this;if(e.body.missingField||e.body.error.startsWith("Invalid API key"))this.fulfillRequest(t,e.statusCode,e.body.error);else{var n=d(d(d(d([],h(Object.values(e.body.eventsWithInvalidFields)),!1),h(Object.values(e.body.eventsWithMissingFields)),!1),h(Object.values(e.body.eventsWithInvalidIdLengths)),!1),h(e.body.silencedEvents),!1).flat(),i=new Set(n),o=t.filter(function(t,n){if(!i.has(n))return!0;r.fulfillRequest([t],e.statusCode,e.body.error)});o.length>0&&this.config.loggerProvider.warn(he(e));var s=this.removeEventsExceedFlushMaxRetries(o);this.scheduleEvents(s)}},e.prototype.handlePayloadTooLargeResponse=function(e,t){if(1!==t.length){this.config.loggerProvider.warn(he(e)),this.config.flushQueueSize/=2;var r=this.removeEventsExceedFlushMaxRetries(t);this.scheduleEvents(r)}else this.fulfillRequest(t,e.statusCode,e.body.error)},e.prototype.handleRateLimitResponse=function(e,t){var r=this,n=Object.keys(e.body.exceededDailyQuotaUsers),i=Object.keys(e.body.exceededDailyQuotaDevices),o=e.body.throttledEvents,s=new Set(n),a=new Set(i),l=new Set(o),u=t.filter(function(t,n){if(!(t.event.user_id&&s.has(t.event.user_id)||t.event.device_id&&a.has(t.event.device_id)))return l.has(n)&&(t.timeout=r.throttleTimeout),!0;r.fulfillRequest([t],e.statusCode,e.body.error)});u.length>0&&this.config.loggerProvider.warn(he(e));var c=this.removeEventsExceedFlushMaxRetries(u);this.scheduleEvents(c)},e.prototype.handleOtherResponse=function(e){var t=this,r=e.map(function(e){return e.timeout=e.attempts*t.retryTimeout,e}),n=this.removeEventsExceedFlushMaxRetries(r);this.scheduleEvents(n)},e.prototype.fulfillRequest=function(e,t,r){var n,i,o;ie(t)?null===(o=this.diagnosticsClient)||void 0===o||o.increment("analytics.events.sent",e.length):(null===(n=this.diagnosticsClient)||void 0===n||n.increment("analytics.events.dropped",e.length),null===(i=this.diagnosticsClient)||void 0===i||i.recordEvent("analytics.events.dropped",{events:e.map(function(e){return e.event.event_type}),code:t,message:r,stack_trace:oe()})),this.removeEvents(e),e.forEach(function(e){return e.callback(q(e.event,t,r))})},e.prototype.saveEvents=function(){if(this.config.storageProvider){var e=this.queue.map(function(e){return e.event});this.config.storageProvider.set(this.storageKey,e)}},e.prototype.removeEvents=function(e){this.queue=this.queue.filter(function(t){return!e.some(function(e){return e.event.insert_id===t.event.insert_id})}),this.saveEvents()},e}(),fe=function(){function e(){}return e.prototype.getApplicationContext=function(){return{versionName:this.versionName,language:pe(),platform:"Web",os:void 0,deviceModel:void 0}},e}(),pe=function(){return"undefined"!=typeof navigator&&(navigator.languages&&navigator.languages[0]||navigator.language)||""},ge=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}(),ve=function(){return ve=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},ve.apply(this,arguments)};function me(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function ye(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}"function"==typeof SuppressedError&&SuppressedError;var be=function(e,t){var r,n,i=typeof e;if(i!==typeof t)return!1;try{for(var o=me(["string","number","boolean","undefined"]),s=o.next();!s.done;s=o.next()){if(s.value===i)return e===t}}catch(e){r={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.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 a=Array.isArray(e),l=Array.isArray(t);if(a!==l)return!1;if(!a||!l){var u=Object.keys(e).sort(),c=Object.keys(t).sort();if(!be(u,c))return!1;var h=!0;return Object.keys(e).forEach(function(r){be(e[r],t[r])||(h=!1)}),h}for(var d=0;d<e.length;d++)if(!be(e[d],t[d]))return!1;return!0};Object.entries||(Object.entries=function(e){for(var t=Object.keys(e),r=t.length,n=new Array(r);r--;)n[r]=[t[r],e[t[r]]];return n});var we=function(){function e(){this.identity={userProperties:{}},this.listeners=new Set}return e.prototype.editIdentity=function(){var e=this,t=ve({},this.identity.userProperties),r=ve(ve({},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,n,i,o,s,a,l=r.userProperties||{};try{for(var u=me(Object.entries(e)),c=u.next();!c.done;c=u.next()){var h=ye(c.value,2),d=h[0],f=h[1];switch(d){case"$set":try{for(var p=(i=void 0,me(Object.entries(f))),g=p.next();!g.done;g=p.next()){var v=ye(g.value,2),m=v[0],y=v[1];l[m]=y}}catch(e){i={error:e}}finally{try{g&&!g.done&&(o=p.return)&&o.call(p)}finally{if(i)throw i.error}}break;case"$unset":try{for(var b=(s=void 0,me(Object.keys(f))),w=b.next();!w.done;w=b.next()){delete l[m=w.value]}}catch(e){s={error:e}}finally{try{w&&!w.done&&(a=b.return)&&a.call(b)}finally{if(s)throw s.error}}break;case"$clearAll":l={}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}return r.userProperties=l,this},commit:function(){return e.setIdentity(r),this}}},e.prototype.getIdentity=function(){return ve({},this.identity)},e.prototype.setIdentity=function(e){var t=ve({},this.identity);this.identity=ve({},e),be(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}(),Se="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self,ke=function(){function e(){this.identityStore=new we,this.eventBridge=new ge,this.applicationContextProvider=new fe}return e.getInstance=function(t){return Se.analyticsConnectorInstances||(Se.analyticsConnectorInstances={}),Se.analyticsConnectorInstances[t]||(Se.analyticsConnectorInstances[t]=new e),Se.analyticsConnectorInstances[t]},e}(),xe=function(e){return void 0===e&&(e=v),ke.getInstance(e)},Ce=function(){function e(){this.name="identity",this.type="before",this.identityStore=xe().identityStore}return e.prototype.execute=function(e){return l(this,void 0,void 0,function(){var t;return u(this,function(r){return(t=e.user_properties)&&this.identityStore.editIdentity().updateUserProperties(t).commit(),[2,e]})})},e.prototype.setup=function(e){return l(this,void 0,void 0,function(){return u(this,function(t){return e.instanceName&&(this.identityStore=xe(e.instanceName).identityStore),[2]})})},e}(),Ee=function(e,t){return void 0===t&&(t=Date.now()),Date.now()-t>e},Oe=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=10),[p,t,e.substring(0,r)].filter(Boolean).join("_")},Ie=function(){var e,t,r,n;if("undefined"==typeof navigator)return"";var i=navigator.userLanguage;return null!==(n=null!==(r=null!==(t=null===(e=navigator.languages)||void 0===e?void 0:e[0])&&void 0!==t?t:navigator.language)&&void 0!==r?r:i)&&void 0!==n?n:""},Pe=function(){var e,t=z();return(null===(e=null==t?void 0:t.location)||void 0===e?void 0:e.search)?t.location.search.substring(1).split("&").filter(Boolean).reduce(function(e,t){var r=t.split("=",2),n=Te(r[0]),i=Te(r[1]);return i?(e[n]=i,e):e},{}):{}},Te=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},Re=function(e,t){return!t||!t.length||t.some(function(t){return"string"==typeof t?e===t:e.match(t)})},Ae=function(e,t){var r=e;try{r=decodeURI(e)}catch(e){null==t||t.error("Malformed URI sequence: ",e)}return r},Me=function(e){var t=0;if(0===e.length)return t;for(var r=0;r<e.length;r++){t=(t<<5)-t+e.charCodeAt(r),t|=0}return t},_e=function(e,t){var r=Me(e.toString());return 31*Math.abs(r)%1e5/1e5<t},Ne=function(){function e(){this.memoryStorage=new Map}return e.prototype.isEnabled=function(){return l(this,void 0,void 0,function(){return u(this,function(e){return[2,!0]})})},e.prototype.get=function(e){return l(this,void 0,void 0,function(){return u(this,function(t){return[2,this.memoryStorage.get(e)]})})},e.prototype.getRaw=function(e){return l(this,void 0,void 0,function(){var t;return u(this,function(r){switch(r.label){case 0:return[4,this.get(e)];case 1:return[2,(t=r.sent())?JSON.stringify(t):void 0]}})})},e.prototype.set=function(e,t){return l(this,void 0,void 0,function(){return u(this,function(r){return this.memoryStorage.set(e,t),[2]})})},e.prototype.remove=function(e){return l(this,void 0,void 0,function(){return u(this,function(t){return this.memoryStorage.delete(e),[2]})})},e.prototype.reset=function(){return l(this,void 0,void 0,function(){return u(this,function(e){return this.memoryStorage.clear(),[2]})})},e}(),Le=function(){function e(e,t){void 0===t&&(t={}),this.options=s({},e),this.config=t}return e.prototype.isEnabled=function(){return l(this,void 0,void 0,function(){var t,r,n,i,o=this;return u(this,function(a){switch(a.label){case 0:return t="AMP_TEST",r=s({},this.options),n=new e(r),i=String(Date.now()),[4,n.transaction(t,function(e){var r,n;try{e.set(i);var s=e.get()===i;return!s&&o.config.diagnosticsClient&&(null===(r=o.config.diagnosticsClient)||void 0===r||r.recordEvent("cookies.isEnabled.failure",{reason:"Test Value mismatch",testKey:t,testValue:i,sync:!0})),s}catch(e){if(o.config.diagnosticsClient){var a=e instanceof Error?e.message:String(e);null===(n=o.config.diagnosticsClient)||void 0===n||n.recordEvent("cookies.isEnabled.failure",{reason:"Cookie getter/setter failed",testKey:t,testValue:i,error:a,sync:!0})}return!1}finally{e.set(null)}})];case 1:return[2,a.sent()]}})})},e.prototype.get=function(e){return l(this,void 0,void 0,function(){var t;return u(this,function(r){switch(r.label){case 0:return[4,this.getRaw(e)];case 1:return t=r.sent(),[2,this.decodeCookieValue(e,t)]}})})},e.prototype.decodeCookieValue=function(e,t){if(t)try{var r=De(t);return void 0===r?void console.error("Amplitude Logger [Error]: Failed to decode cookie value for key: ".concat(e,", value: ").concat(t)):JSON.parse(r)}catch(r){return void console.error("Amplitude Logger [Error]: Failed to parse cookie value for key: ".concat(e,", value: ").concat(t))}},e.prototype.getSync=function(e){var t=this.getRawSync(e);return this.decodeCookieValue(e,t)},e.prototype.getRaw=function(e){var t,r;return l(this,void 0,void 0,function(){var n,i,o,s,a,l,h,d,f;return u(this,function(u){switch(u.label){case 0:n=z(),i=n,u.label=1;case 1:return u.trys.push([1,4,,5]),(o=null==i?void 0:i.cookieStore)?[4,o.getAll(e)]:[3,3];case 2:if(s=u.sent()){s.length>1&&(null===(t=this.config.diagnosticsClient)||void 0===t||t.recordEvent("cookies.duplicate",{cookies:s.map(function(e){return e.domain})}),null===(r=this.config.diagnosticsClient)||void 0===r||r.increment("cookies.duplicate.occurrence.cookieStore"));try{for(a=c(s),l=a.next();!l.done;l=a.next())if(h=l.value,Ue(h.domain,this.options.domain))return[2,h.value]}catch(e){d={error:e}}finally{try{l&&!l.done&&(f=a.return)&&f.call(a)}finally{if(d)throw d.error}}}u.label=3;case 3:return[3,5];case 4:return u.sent(),[3,5];case 5:return[2,this.getRawSync(e)]}})})},e.prototype.getRawSync=function(e){var t,r,n=this,i=z(),o=(null!==(r=null===(t=null==i?void 0:i.document)||void 0===t?void 0:t.cookie.split("; "))&&void 0!==r?r:[]).filter(function(t){return 0===t.indexOf(e+"=")}),s=void 0,a=this.config.duplicateResolverFn;if("function"==typeof a&&o.length>1&&(s=o.find(function(t){var r;try{var i=a(t.substring(e.length+1));return i||null===(r=n.config.diagnosticsClient)||void 0===r||r.increment("cookies.duplicate.occurrence.document.cookie"),i}catch(e){return!1}})),s||(s=o[0]),s)return s.substring(e.length+1)},e.prototype.set=function(e,t){return l(this,void 0,void 0,function(){return u(this,function(r){return this.setSync(e,t),[2]})})},e.prototype.setSync=function(e,t){var r;try{var n=null!==(r=this.options.expirationDays)&&void 0!==r?r:0,i=null!==t?n:-1,o=void 0;if(i){var s=new Date;s.setTime(s.getTime()+24*i*60*60*1e3),o=s}var a="".concat(e,"=").concat(btoa(encodeURIComponent(JSON.stringify(t))));o&&(a+="; expires=".concat(o.toUTCString())),a+="; path=/",this.options.domain&&(a+="; domain=".concat(this.options.domain)),this.options.secure&&(a+="; Secure"),this.options.sameSite&&(a+="; SameSite=".concat(this.options.sameSite));var l=z();l&&(l.document.cookie=a)}catch(t){var u=t instanceof Error?t.message:String(t);console.error("Amplitude Logger [Error]: Failed to set cookie for key: ".concat(e,". Error: ").concat(u))}},e.prototype.remove=function(e){return l(this,void 0,void 0,function(){return u(this,function(t){switch(t.label){case 0:return[4,this.set(e,null)];case 1:return t.sent(),[2]}})})},e.prototype.reset=function(){return l(this,void 0,void 0,function(){return u(this,function(e){return[2]})})},e.isDomainWritable=function(t){return l(this,void 0,void 0,function(){var r,n;return u(this,function(i){switch(i.label){case 0:r="AMP_TLDTEST",n=new e({domain:"."+t}),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,n.transaction(r,function(e){try{return e.set(1),e.get()}finally{e.set(null)}})];case 2:return[2,!!i.sent()];case 3:return i.sent(),[2,!1];case 4:return[2]}})})},e.prototype.transaction=function(e,t){return l(this,void 0,void 0,function(){var r,n,i=this;return u(this,function(o){switch(o.label){case 0:return r=function(){var e,t=z();return null===(e=null==t?void 0:t.navigator)||void 0===e?void 0:e.locks}(),n=function(){return t({get:function(){return i.getSync(e)},set:function(t){return i.setSync(e,t)}})},r?[4,r.request("com.amplitude:cookie-lock:".concat(e),n)]:[2,n()];case 1:return[2,o.sent()]}})})},e}(),De=function(e){var t;return null!==(t=function(e){try{return decodeURIComponent(atob(e))}catch(e){return}}(e))&&void 0!==t?t:function(e){try{return decodeURIComponent(atob(decodeURIComponent(e)))}catch(e){return}}(e)},Ue=function(e,t){if(""===e&&""===t)return!0;if(!e||!t)return!1;var r=e.startsWith(".")?e.substring(1):e,n=t.startsWith(".")?t.substring(1):t;return r.toLowerCase()===n.toLowerCase()},Fe=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=10),[p,t,e.substring(0,r)].filter(Boolean).join("_")},je=function(){function e(e){this.storage=e}return e.prototype.isEnabled=function(){return l(this,void 0,void 0,function(){var t,r,n;return u(this,function(i){switch(i.label){case 0:if(!this.storage)return[2,!1];t=String(Date.now()),r=new e(this.storage),n="AMP_TEST",i.label=1;case 1:return i.trys.push([1,4,5,7]),[4,r.set(n,t)];case 2:return i.sent(),[4,r.get(n)];case 3:return[2,i.sent()===t];case 4:return i.sent(),[2,!1];case 5:return[4,r.remove(n)];case 6:return i.sent(),[7];case 7:return[2]}})})},e.prototype.get=function(e){return l(this,void 0,void 0,function(){var t;return u(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.getRaw(e)];case 1:return(t=r.sent())?[2,JSON.parse(t)]:[2,void 0];case 2:return r.sent(),console.error("[Amplitude] Error: Could not get value from storage"),[2,void 0];case 3:return[2]}})})},e.prototype.getRaw=function(e){var t;return l(this,void 0,void 0,function(){return u(this,function(r){return[2,(null===(t=this.storage)||void 0===t?void 0:t.getItem(e))||void 0]})})},e.prototype.set=function(e,t){var r;return l(this,void 0,void 0,function(){return u(this,function(n){try{null===(r=this.storage)||void 0===r||r.setItem(e,JSON.stringify(t))}catch(e){}return[2]})})},e.prototype.remove=function(e){var t;return l(this,void 0,void 0,function(){return u(this,function(r){try{null===(t=this.storage)||void 0===t||t.removeItem(e)}catch(e){}return[2]})})},e.prototype.reset=function(){var e;return l(this,void 0,void 0,function(){return u(this,function(t){try{null===(e=this.storage)||void 0===e||e.clear()}catch(e){}return[2]})})},e}(),Be="tags",qe="counters",ze="histograms",We="events",Ve="internal",$e="last_flush_timestamp",He=function(){function e(e,t){this.dbPromise=null,this.logger=t,this.dbName="AMP_diagnostics_".concat(e.substring(0,10))}return e.isSupported=function(){var e;return void 0!==(null===(e=z())||void 0===e?void 0:e.indexedDB)},e.prototype.getDB=function(){return l(this,void 0,void 0,function(){return u(this,function(e){return this.dbPromise||(this.dbPromise=this.openDB()),[2,this.dbPromise]})})},e.prototype.openDB=function(){var e=this;return new Promise(function(t,r){var n=indexedDB.open(e.dbName,1);n.onerror=function(){e.dbPromise=null,r(new Error("Failed to open IndexedDB"))},n.onsuccess=function(){var r=n.result;r.onclose=function(){e.dbPromise=null,e.logger.debug("DiagnosticsStorage: DB connection closed.")},r.onerror=function(t){e.logger.debug("DiagnosticsStorage: A global database error occurred.",t),r.close()},t(r)},n.onupgradeneeded=function(t){var r=t.target.result;e.createTables(r)}})},e.prototype.createTables=function(e){(e.objectStoreNames.contains(Be)||e.createObjectStore(Be,{keyPath:"key"}),e.objectStoreNames.contains(qe)||e.createObjectStore(qe,{keyPath:"key"}),e.objectStoreNames.contains(ze)||e.createObjectStore(ze,{keyPath:"key"}),e.objectStoreNames.contains(We))||e.createObjectStore(We,{keyPath:"id",autoIncrement:!0}).createIndex("time_idx","time",{unique:!1});e.objectStoreNames.contains(Ve)||e.createObjectStore(Ve,{keyPath:"key"})},e.prototype.setTags=function(e){return l(this,void 0,void 0,function(){var t,r,n,i,o=this;return u(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),0===Object.entries(e).length?[2]:[4,this.getDB()];case 1:return t=s.sent(),r=t.transaction([Be],"readwrite"),n=r.objectStore(Be),[2,new Promise(function(t){var i=Object.entries(e);r.oncomplete=function(){t()},r.onabort=function(e){o.logger.debug("DiagnosticsStorage: Failed to set tags",e),t()},i.forEach(function(e){var t=h(e,2),r=t[0],i=t[1];n.put({key:r,value:i}).onerror=function(e){o.logger.debug("DiagnosticsStorage: Failed to set tag",r,i,e)}})})];case 2:return i=s.sent(),this.logger.debug("DiagnosticsStorage: Failed to set tags",i),[3,3];case 3:return[2]}})})},e.prototype.incrementCounters=function(e){return l(this,void 0,void 0,function(){var t,r,n,i,o=this;return u(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),0===Object.entries(e).length?[2]:[4,this.getDB()];case 1:return t=s.sent(),r=t.transaction([qe],"readwrite"),n=r.objectStore(qe),[2,new Promise(function(t){var i=Object.entries(e);r.oncomplete=function(){t()},r.onabort=function(e){o.logger.debug("DiagnosticsStorage: Failed to increment counters",e),t()},i.forEach(function(e){var t=h(e,2),r=t[0],i=t[1],s=n.get(r);s.onsuccess=function(){var e=s.result,t=e?e.value:0;n.put({key:r,value:t+i}).onerror=function(e){o.logger.debug("DiagnosticsStorage: Failed to update counter",r,e)}},s.onerror=function(e){o.logger.debug("DiagnosticsStorage: Failed to read exi