UNPKG

@amplitude/analytics-browser

Version:
1 lines 196 kB
!function(){"use strict";var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n,r,i=function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},i.apply(this,arguments)};function o(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}function s(e,t,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{a(r.next(e))}catch(e){o(e)}}function u(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,u)}a((r=r.apply(e,t||[])).next())})}function u(e,t){var n,r,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=u(0),s.throw=u(1),s.return=u(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(u){return function(a){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,u[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}function a(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function c(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function l(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}function d(e){return this instanceof d?(this.v=e,this):new d(e)}function f(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,i=n.apply(e,t||[]),o=[];return r=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",function(e){return function(t){return Promise.resolve(t).then(e,c)}}),r[Symbol.asyncIterator]=function(){return this},r;function s(e,t){i[e]&&(r[e]=function(t){return new Promise(function(n,r){o.push([e,t,n,r])>1||u(e,t)})},t&&(r[e]=t(r[e])))}function u(e,t){try{!function(e){e.value instanceof d?Promise.resolve(e.value.v).then(a,c):l(o[0][2],e)}(i[e](t))}catch(e){l(o[0][3],e)}}function a(e){u("next",e)}function c(e){u("throw",e)}function l(e,t){e(t),o.shift(),o.length&&u(o[0][0],o[0][1])}}function p(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=a(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise(function(r,i){(function(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)})(r,i,(t=e[n](t)).done,t.value)})}}}"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"}(n||(n={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(r||(r={}));var h,v="AMP",g="".concat(v,"_unsent"),y="$default_instance",m="https://api2.amplitude.com/2/httpapi",b="dclid",w="fbclid",S="gbraid",E="gclid",T="ko_click_id",_="li_fat_id",k="msclkid",I="rdt_cid",P="ttclid",x="twclid",A="wbraid",O={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},C=["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"],R=["authorization","cookie","set-cookie"],D=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var n=e[t];if(!L(t,n))return!1}return!0},L=function(e,t){var n,r;if("string"!=typeof e)return!1;if(Array.isArray(t)){var i=!0;try{for(var o=a(t),s=o.next();!s.done;s=o.next()){var u=s.value;if(Array.isArray(u))return!1;if("object"==typeof u)i=i&&D(u);else if(!["number","string"].includes(typeof u))return!1;if(!i)return!1}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}else{if(null==t)return!1;if("object"==typeof t)return D(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},N=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return i({},this._properties)},e.prototype.set=function(e,t){return this._safeSet(h.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(h.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(h.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(h.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(h.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(h.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(h.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(h.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(h.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[h.CLEAR_ALL]="-",this},e.prototype._safeSet=function(e,t,n){if(this._validate(e,t,n)){var r=this._properties[e];return void 0===r&&(r={},this._properties[e]=r),r[t]=n,this._propertySet.add(t),!0}return!1},e.prototype._validate=function(e,t,n){return void 0===this._properties[h.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===h.ADD?"number"==typeof n:e===h.UNSET||e===h.REMOVE||L(t,n)))},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"}(h||(h={}));var j,q=[h.CLEAR_ALL,h.UNSET,h.SET,h.SET_ONCE,h.ADD,h.APPEND,h.PREPEND,h.PREINSERT,h.POSTINSERT,h.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"}(j||(j={}));var U,M=function(e,t,n){return void 0===t&&(t=0),void 0===n&&(n=j.Unknown),{event:e,code:t,message:n}},F=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},B=l([],c(Array(256).keys()),!1).map(function(e){return e.toString(16).padStart(2,"0")}),H=function(e){var t,n=F();if(!(null===(t=null==n?void 0:n.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,H)}(e);var r=n.crypto.getRandomValues(new Uint8Array(16));return r[6]=15&r[6]|64,r[8]=63&r[8]|128,l([],c(r.entries()),!1).map(function(e){var t=c(e,2),n=t[0],r=t[1];return[4,6,8,10].includes(n)?"-".concat(B[r]):B[r]}).join("")},V=function(){function e(e){this.client=e,this.queue=[],this.applying=!1,this.plugins=[]}return e.prototype.register=function(e,t){var n,r;return s(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=H(),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!==(n=e.type)&&void 0!==n?n:"enrichment",[4,null===(r=e.setup)||void 0===r?void 0:r.call(e,t,this.client)]);case 1:return i.sent(),this.plugins.push(e),[2]}})})},e.prototype.deregister=function(e,t){var n;return s(this,void 0,void 0,function(){var r,i;return u(this,function(o){switch(o.label){case 0:return r=this.plugins.findIndex(function(t){return t.name===e}),-1===r?(t.loggerProvider.warn("Plugin with name ".concat(e," does not exist, skipping deregistration")),[2]):(i=this.plugins[r],this.plugins.splice(r,1),[4,null===(n=i.teardown)||void 0===n?void 0:n.call(i)]);case 1:return o.sent(),[2]}})})},e.prototype.reset=function(e){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(n){t.queue.push([e,n]),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 s(this,void 0,void 0,function(){var t,n,r,o,s,l,d,f,p,h,v,g,y,m,b,w,S,E,T,_;return u(this,function(u){switch(u.label){case 0:if(!e)return[2];t=c(e,1),n=t[0],r=c(e,2),o=r[1],this.loggerProvider.log("Timeline.apply: Initial event",n),s=this.plugins.filter(function(e){return"before"===e.type}),u.label=1;case 1:u.trys.push([1,6,7,8]),l=a(s),d=l.next(),u.label=2;case 2:return d.done?[3,5]:(g=d.value).execute?[4,g.execute(i({},n))]:[3,4];case 3:if(null===(y=u.sent()))return this.loggerProvider.log("Timeline.apply: Event filtered out by before plugin '".concat(String(g.name),"', event: ").concat(JSON.stringify(n))),o({event:n,code:0,message:""}),[2];n=y,this.loggerProvider.log("Timeline.apply: Event after before plugin '".concat(String(g.name),"', event: ").concat(JSON.stringify(n))),u.label=4;case 4:return d=l.next(),[3,2];case 5:return[3,8];case 6:return f=u.sent(),S={error:f},[3,8];case 7:try{d&&!d.done&&(E=l.return)&&E.call(l)}finally{if(S)throw S.error}return[7];case 8:p=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]),h=a(p),v=h.next(),u.label=10;case 10:return v.done?[3,13]:(g=v.value).execute?[4,g.execute(i({},n))]:[3,12];case 11:if(null===(y=u.sent()))return this.loggerProvider.log("Timeline.apply: Event filtered out by enrichment plugin '".concat(String(g.name),"', event: ").concat(JSON.stringify(n))),o({event:n,code:0,message:""}),[2];n=y,this.loggerProvider.log("Timeline.apply: Event after enrichment plugin '".concat(String(g.name),"', event: ").concat(JSON.stringify(n))),u.label=12;case 12:return v=h.next(),[3,10];case 13:return[3,16];case 14:return m=u.sent(),T={error:m},[3,16];case 15:try{v&&!v.done&&(_=h.return)&&_.call(h)}finally{if(T)throw T.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(n))),w=b.map(function(e){var t=i({},n);return e.execute(t).catch(function(e){return M(t,0,String(e))})}),Promise.all(w).then(function(e){var t=c(e,1)[0]||M(n,100,"Event not tracked, no destination plugins on the instance");o(t)}),[2]}})})},e.prototype.flush=function(){return s(this,void 0,void 0,function(){var e,t,n,r=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 r.apply(e)}))];case 1:return i.sent(),t=this.plugins.filter(function(e){return"destination"===e.type}),n=t.map(function(e){return e.flush&&e.flush()}),[4,Promise.all(n)];case 2:return i.sent(),[2]}})})},e.prototype.onIdentityChanged=function(e){this.plugins.forEach(function(t){var n;null===(n=t.onIdentityChanged)||void 0===n||n.call(t,e)})},e.prototype.onSessionIdChanged=function(e){this.plugins.forEach(function(t){var n;null===(n=t.onSessionIdChanged)||void 0===n||n.call(t,e)})},e.prototype.onOptOutChanged=function(e){this.plugins.forEach(function(t){var n;null===(n=t.onOptOutChanged)||void 0===n||n.call(t,e)})},e}(),z=function(e,t){return i(i({},t),{event_type:r.IDENTIFY,user_properties:e.getUserProperties()})},J=function(e){return{promise:e||Promise.resolve()}},W=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 V(this),this.name=e}return e.prototype._init=function(e){return s(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 s(this,void 0,void 0,function(){var t,n,r,i,o,s,c,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]),n=a(t),r=n.next(),u.label=2;case 2:return r.done?[3,7]:(i=r.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 r=n.next(),[3,2];case 7:return[3,10];case 8:return s=u.sent(),c={error:s},[3,10];case 9:try{r&&!r.done&&(l=n.return)&&l.call(n)}finally{if(c)throw c.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,n){var r=function(e,t,n){return i(i(i({},"string"==typeof e?{event_type:e}:e),n),t&&{event_properties:t})}(e,t,n);return J(this.dispatch(r))},e.prototype.identify=function(e,t){var n=z(e,t);return J(this.dispatch(n))},e.prototype.groupIdentify=function(e,t,n,o){var s=function(e,t,n,o){var s;return i(i({},o),{event_type:r.GROUP_IDENTIFY,group_properties:n.getUserProperties(),groups:(s={},s[e]=t,s)})}(e,t,n,o);return J(this.dispatch(s))},e.prototype.setGroup=function(e,t,n){var o=function(e,t,n){var o,s=new N;return s.set(e,t),i(i({},n),{event_type:r.IDENTIFY,user_properties:s.getUserProperties(),groups:(o={},o[e]=t,o)})}(e,t,n);return J(this.dispatch(o))},e.prototype.revenue=function(e,t){var n=function(e,t){return i(i({},t),{event_type:r.REVENUE,event_properties:e.getEventProperties()})}(e,t);return J(this.dispatch(n))},e.prototype.add=function(e){return this.isReady?this._addPlugin(e):(this.q.push(this._addPlugin.bind(this,e)),J())},e.prototype._addPlugin=function(e){return J(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)),J())},e.prototype._removePlugin=function(e){return J(this.timeline.deregister(e,this.config))},e.prototype.dispatchWithCallback=function(e,t){if(!this.isReady)return t(M(e,0,"Client not initialized"));this.process(e).then(t)},e.prototype.dispatch=function(e){return s(this,void 0,void 0,function(){var t=this;return u(this,function(n){return this.isReady?[2,this.process(e)]:[2,new Promise(function(n){t.dispatchQ.push(t.dispatchWithCallback.bind(t,e,n))})]})})},e.prototype.getOperationAppliedUserProperties=function(e){var t={};if(void 0===e)return t;var r={};return Object.keys(e).forEach(function(t){Object.values(n).includes(t)||(r[t]=e[t])}),q.forEach(function(r){if(Object.keys(e).includes(r)){var i=e[r];switch(r){case n.CLEAR_ALL:Object.keys(t).forEach(function(e){delete t[e]});break;case n.UNSET:Object.keys(i).forEach(function(e){delete t[e]});break;case n.SET:Object.assign(t,i)}}}),Object.assign(t,r),t},e.prototype.process=function(e){return s(this,void 0,void 0,function(){var t,n,i,o;return u(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),this.config.optOut?[2,M(e,0,"Event skipped due to optOut config")]:(e.event_type===r.IDENTIFY&&(t=this.getOperationAppliedUserProperties(e.user_properties),this.timeline.onIdentityChanged({userProperties:t})),[4,this.timeline.push(e)]);case 1:return 200===(o=s.sent()).code?this.config.loggerProvider.log(o.message):100===o.code?this.config.loggerProvider.warn(o.message):this.config.loggerProvider.error(o.message),[2,o];case 2:return n=s.sent(),i=String(n),this.config.loggerProvider.error(i),[2,o=M(e,0,i)];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.timeline.onOptOutChanged(e),this.config.optOut=Boolean(e))},e.prototype.flush=function(){return J(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}(),$=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 D(e)&&(this.properties=e),this},e.prototype.getEventProperties=function(){var e=this.properties?i({},this.properties):{};return e[U.REVENUE_PRODUCT_ID]=this.productId,e[U.REVENUE_QUANTITY]=this.quantity,e[U.REVENUE_PRICE]=this.price,e[U.REVENUE_TYPE]=this.revenueType,e[U.REVENUE_CURRENCY]=this.currency,e[U.REVENUE]=this.revenue,e[U.RECEIPT]=this.receipt,e[U.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"}(U||(U={}));var K;!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"}(K||(K={}));var Y="Amplitude Logger ",G=function(){function e(){this.logLevel=K.None}return e.prototype.disable=function(){this.logLevel=K.None},e.prototype.enable=function(e){void 0===e&&(e=K.Warn),this.logLevel=e},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<K.Verbose||console.log("".concat(Y,"[Log]: ").concat(e.join(" ")))},e.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<K.Warn||console.warn("".concat(Y,"[Warn]: ").concat(e.join(" ")))},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<K.Error||console.error("".concat(Y,"[Error]: ").concat(e.join(" ")))},e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<K.Debug||console.log("".concat(Y,"[Debug]: ").concat(e.join(" ")))},e}(),Q=function(){return{flushMaxRetries:12,flushQueueSize:200,flushIntervalMillis:1e4,instanceName:y,logLevel:K.Warn,loggerProvider:new G,offline:!1,optOut:!1,serverUrl:m,serverZone:"US",useBatch:!1}},X=function(){function e(e){var t,n,r,i;this._optOut=!1;var o=Q();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!==(n=e.logLevel)&&void 0!==n?n: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!==(r=e.optOut)&&void 0!==r?r: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=ee(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}(),Z=function(e,t){return"EU"===e?t?"https://api.eu.amplitude.com/batch":"https://api.eu.amplitude.com/2/httpapi":t?"https://api2.amplitude.com/batch":m},ee=function(e,t,n){if(void 0===e&&(e=""),void 0===t&&(t=Q().serverZone),void 0===n&&(n=Q().useBatch),e)return{serverUrl:e,serverZone:void 0};var r=["US","EU"].includes(t)?t:Q().serverZone;return{serverZone:r,serverUrl:Z(r,n)}},te=function(){function e(){this.sdk={metrics:{histogram:{}}}}return e.prototype.recordHistogram=function(e,t){this.sdk.metrics.histogram[e]=t},e}();function ne(e){return e>=200&&e<300}var re=function(e){return void 0===e&&(e=0),((new Error).stack||"").split("\n").slice(2+e).map(function(e){return e.trim()})},ie=function(e){return function(){var t=i({},e.config);return{logger:t.loggerProvider,logLevel:t.logLevel}}},oe=function(e,t){var n,r;t=(t=t.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"");try{for(var i=a(t.split(".")),o=i.next();!o.done;o=i.next()){var s=o.value;if(!(s in e))return;e=e[s]}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return e},se=function(e,t){return function(){var n,r,i={};try{for(var o=a(t),s=o.next();!s.done;s=o.next()){var u=s.value;i[u]=oe(e,u)}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return i}},ue=function(e,t,n,r,i){return void 0===i&&(i=null),function(){for(var o=[],s=0;s<arguments.length;s++)o[s]=arguments[s];var u=n(),a=u.logger,c=u.logLevel;if(c&&c<K.Debug||!c||!a)return e.apply(i,o);var l={type:"invoke public method",name:t,args:o,stacktrace:re(1),time:{start:(new Date).toISOString()},states:{}};r&&l.states&&(l.states.before=r());var d=e.apply(i,o);return d&&d.promise?d.promise.then(function(){r&&l.states&&(l.states.after=r()),l.time&&(l.time.end=(new Date).toISOString()),a.debug(JSON.stringify(l,null,2))}):(r&&l.states&&(l.states.after=r()),l.time&&(l.time.end=(new Date).toISOString()),a.debug(JSON.stringify(l,null,2))),d}};function ae(e){var t="";try{"body"in e&&(t=JSON.stringify(e.body,null,2))}catch(e){}return t}var ce=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 s(this,void 0,void 0,function(){var n,r=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(n=i.sent())&&n.length>0&&Promise.all(n.map(function(e){return r.execute(e)})).catch(),[2,Promise.resolve(void 0)]}})})},e.prototype.execute=function(e){var t=this;return e.insert_id||(e.insert_id=H()),new Promise(function(n){var r={event:e,attempts:0,callback:function(e){return n(e)},timeout:0};t.queue.push(r),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),s(this,void 0,void 0,function(){var t,n,r=this;return u(this,function(i){switch(i.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=[],n=[],this.queue.forEach(function(e){return 0===e.timeout?t.push(e):n.push(e)}),o=t,a=this.config.flushQueueSize,c=Math.max(a,1),[4,o.reduce(function(e,t,n){var r=Math.floor(n/c);return e[r]||(e[r]=[]),e[r].push(t),e},[]).reduce(function(t,n){return s(r,void 0,void 0,function(){return u(this,function(r){switch(r.label){case 0:return[4,t];case 1:return r.sent(),[4,this.send(n,e)];case 2:return[2,r.sent()]}})})},Promise.resolve())]);case 1:return i.sent(),this.flushId=null,this.scheduleEvents(this.queue),[2]}var o,a,c})})},e.prototype.send=function(e,t){return void 0===t&&(t=!0),s(this,void 0,void 0,function(){var n,r,i,s,a;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,o(t,["extra"])}),options:{min_id_length:this.config.minIdLength},client_upload_time:(new Date).toISOString(),request_metadata:this.config.requestMetadata},this.config.requestMetadata=new te,u.label=1;case 1:return u.trys.push([1,3,,4]),r=ee(this.config.serverUrl,this.config.serverZone,this.config.useBatch).serverUrl,[4,this.config.transportProvider.send(r,n)];case 2:return null===(i=u.sent())?(this.fulfillRequest(e,0,"Unexpected error occurred"),[2]):t?(this.handleResponse(i,e),[3,4]):("body"in i?this.fulfillRequest(e,i.statusCode,"".concat(i.status,": ").concat(ae(i))):this.fulfillRequest(e,i.statusCode,i.status),[2]);case 3:return s=u.sent(),a=(c=s)instanceof Error?c.message:String(c),this.config.loggerProvider.error(a),this.handleResponse({status:j.Failed,statusCode:0},e),[3,4];case 4:return[2]}var c})})},e.prototype.handleResponse=function(e,t){var n=e.status;switch(n){case j.Success:this.handleSuccessResponse(e,t);break;case j.Invalid:this.handleInvalidResponse(e,t);break;case j.PayloadTooLarge:this.handlePayloadTooLargeResponse(e,t);break;case j.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 n=this;if(e.body.missingField||e.body.error.startsWith("Invalid API key"))this.fulfillRequest(t,e.statusCode,e.body.error);else{var r=l(l(l(l([],c(Object.values(e.body.eventsWithInvalidFields)),!1),c(Object.values(e.body.eventsWithMissingFields)),!1),c(Object.values(e.body.eventsWithInvalidIdLengths)),!1),c(e.body.silencedEvents),!1).flat(),i=new Set(r),o=t.filter(function(t,r){if(!i.has(r))return!0;n.fulfillRequest([t],e.statusCode,e.body.error)});o.length>0&&this.config.loggerProvider.warn(ae(e));var s=this.removeEventsExceedFlushMaxRetries(o);this.scheduleEvents(s)}},e.prototype.handlePayloadTooLargeResponse=function(e,t){if(1!==t.length){this.config.loggerProvider.warn(ae(e)),this.config.flushQueueSize/=2;var n=this.removeEventsExceedFlushMaxRetries(t);this.scheduleEvents(n)}else this.fulfillRequest(t,e.statusCode,e.body.error)},e.prototype.handleRateLimitResponse=function(e,t){var n=this,r=Object.keys(e.body.exceededDailyQuotaUsers),i=Object.keys(e.body.exceededDailyQuotaDevices),o=e.body.throttledEvents,s=new Set(r),u=new Set(i),a=new Set(o),c=t.filter(function(t,r){if(!(t.event.user_id&&s.has(t.event.user_id)||t.event.device_id&&u.has(t.event.device_id)))return a.has(r)&&(t.timeout=n.throttleTimeout),!0;n.fulfillRequest([t],e.statusCode,e.body.error)});c.length>0&&this.config.loggerProvider.warn(ae(e));var l=this.removeEventsExceedFlushMaxRetries(c);this.scheduleEvents(l)},e.prototype.handleOtherResponse=function(e){var t=this,n=e.map(function(e){return e.timeout=e.attempts*t.retryTimeout,e}),r=this.removeEventsExceedFlushMaxRetries(n);this.scheduleEvents(r)},e.prototype.fulfillRequest=function(e,t,n){var r,i,o;ne(t)?null===(o=this.diagnosticsClient)||void 0===o||o.increment("analytics.events.sent",e.length):(null===(r=this.diagnosticsClient)||void 0===r||r.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:n,stack_trace:re()})),this.removeEvents(e),e.forEach(function(e){return e.callback(M(e.event,t,n))})},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}(),le=function(){function e(){}return e.prototype.getApplicationContext=function(){return{versionName:this.versionName,language:de(),platform:"Web",os:void 0,deviceModel:void 0}},e}(),de=function(){return"undefined"!=typeof navigator&&(navigator.languages&&navigator.languages[0]||navigator.language)||""},fe=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}(),pe=function(){return pe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},pe.apply(this,arguments)};function he(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function ve(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}"function"==typeof SuppressedError&&SuppressedError;var ge=function(e,t){var n,r,i=typeof e;if(i!==typeof t)return!1;try{for(var o=he(["string","number","boolean","undefined"]),s=o.next();!s.done;s=o.next()){if(s.value===i)return e===t}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}if(null==e&&null==t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;var u=Array.isArray(e),a=Array.isArray(t);if(u!==a)return!1;if(!u||!a){var c=Object.keys(e).sort(),l=Object.keys(t).sort();if(!ge(c,l))return!1;var d=!0;return Object.keys(e).forEach(function(n){ge(e[n],t[n])||(d=!1)}),d}for(var f=0;f<e.length;f++)if(!ge(e[f],t[f]))return!1;return!0};Object.entries||(Object.entries=function(e){for(var t=Object.keys(e),n=t.length,r=new Array(n);n--;)r[n]=[t[n],e[t[n]]];return r});var ye,me=function(){function e(){this.identity={userProperties:{}},this.listeners=new Set}return e.prototype.editIdentity=function(){var e=this,t=pe({},this.identity.userProperties),n=pe(pe({},this.identity),{userProperties:t});return{setUserId:function(e){return n.userId=e,this},setDeviceId:function(e){return n.deviceId=e,this},setUserProperties:function(e){return n.userProperties=e,this},setOptOut:function(e){return n.optOut=e,this},updateUserProperties:function(e){var t,r,i,o,s,u,a=n.userProperties||{};try{for(var c=he(Object.entries(e)),l=c.next();!l.done;l=c.next()){var d=ve(l.value,2),f=d[0],p=d[1];switch(f){case"$set":try{for(var h=(i=void 0,he(Object.entries(p))),v=h.next();!v.done;v=h.next()){var g=ve(v.value,2),y=g[0],m=g[1];a[y]=m}}catch(e){i={error:e}}finally{try{v&&!v.done&&(o=h.return)&&o.call(h)}finally{if(i)throw i.error}}break;case"$unset":try{for(var b=(s=void 0,he(Object.keys(p))),w=b.next();!w.done;w=b.next()){delete a[y=w.value]}}catch(e){s={error:e}}finally{try{w&&!w.done&&(u=b.return)&&u.call(b)}finally{if(s)throw s.error}}break;case"$clearAll":a={}}}}catch(e){t={error:e}}finally{try{l&&!l.done&&(r=c.return)&&r.call(c)}finally{if(t)throw t.error}}return n.userProperties=a,this},commit:function(){return e.setIdentity(n),this}}},e.prototype.getIdentity=function(){return pe({},this.identity)},e.prototype.setIdentity=function(e){var t=pe({},this.identity);this.identity=pe({},e),ge(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}(),be="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self,we=function(){function e(){this.identityStore=new me,this.eventBridge=new fe,this.applicationContextProvider=new le}return e.getInstance=function(t){return be.analyticsConnectorInstances||(be.analyticsConnectorInstances={}),be.analyticsConnectorInstances[t]||(be.analyticsConnectorInstances[t]=new e),be.analyticsConnectorInstances[t]},e}(),Se=function(e){return void 0===e&&(e=y),we.getInstance(e)},Ee=function(){function e(){this.name="identity",this.type="before",this.identityStore=Se().identityStore}return e.prototype.execute=function(e){return s(this,void 0,void 0,function(){var t;return u(this,function(n){return(t=e.user_properties)&&this.identityStore.editIdentity().updateUserProperties(t).commit(),[2,e]})})},e.prototype.setup=function(e){return s(this,void 0,void 0,function(){return u(this,function(t){return e.instanceName&&(this.identityStore=Se(e.instanceName).identityStore),[2]})})},e}(),Te=function(e,t){return void 0===t&&(t=Date.now()),Date.now()-t>e},_e=function(e,t,n){return void 0===t&&(t=""),void 0===n&&(n=10),[v,t,e.substring(0,n)].filter(Boolean).join("_")},ke=function(){var e,t,n,r;if("undefined"==typeof navigator)return"";var i=navigator.userLanguage;return null!==(r=null!==(n=null!==(t=null===(e=navigator.languages)||void 0===e?void 0:e[0])&&void 0!==t?t:navigator.language)&&void 0!==n?n:i)&&void 0!==r?r:""},Ie=function(){var e,t=F();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 n=t.split("=",2),r=Pe(n[0]),i=Pe(n[1]);return i?(e[r]=i,e):e},{}):{}},Pe=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},xe=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 n=e;try{n=decodeURI(e)}catch(e){null==t||t.error("Malformed URI sequence: ",e)}return n},Oe=function(e,t){var n=function(e){var t=0;if(0===e.length)return t;for(var n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t}(e.toString());return 31*Math.abs(n)%1e5/1e5<t},Ce=function(){function e(){this.memoryStorage=new Map}return e.prototype.isEnabled=function(){return s(this,void 0,void 0,function(){return u(this,function(e){return[2,!0]})})},e.prototype.get=function(e){return s(this,void 0,void 0,function(){return u(this,function(t){return[2,this.memoryStorage.get(e)]})})},e.prototype.getRaw=function(e){return s(this,void 0,void 0,function(){var t;return u(this,function(n){switch(n.label){case 0:return[4,this.get(e)];case 1:return[2,(t=n.sent())?JSON.stringify(t):void 0]}})})},e.prototype.set=function(e,t){return s(this,void 0,void 0,function(){return u(this,function(n){return this.memoryStorage.set(e,t),[2]})})},e.prototype.remove=function(e){return s(this,void 0,void 0,function(){return u(this,function(t){return this.memoryStorage.delete(e),[2]})})},e.prototype.reset=function(){return s(this,void 0,void 0,function(){return u(this,function(e){return this.memoryStorage.clear(),[2]})})},e}(),Re=function(){function e(e){this.options=i({},e)}return e.prototype.isEnabled=function(){return s(this,void 0,void 0,function(){var t,n;return u(this,function(r){switch(r.label){case 0:if(!F())return[2,!1];e.testValue=String(Date.now()),t=new e(this.options),n="AMP_TEST",r.label=1;case 1:return r.trys.push([1,4,5,7]),[4,t.set(n,e.testValue)];case 2:return r.sent(),[4,t.get(n)];case 3:return[2,r.sent()===e.testValue];case 4:return r.sent(),[2,!1];case 5:return[4,t.remove(n)];case 6:return r.sent(),[7];case 7:return[2]}})})},e.prototype.get=function(e){var t;return s(this,void 0,void 0,function(){var n,r;return u(this,function(i){switch(i.label){case 0:return[4,this.getRaw(e)];case 1:if(!(n=i.sent()))return[2,void 0];try{return void 0===(r=null!==(t=De(n))&&void 0!==t?t:Le(n))?(console.error("Amplitude Logger [Error]: Failed to decode cookie value for key: ".concat(e,", value: ").concat(n)),[2,void 0]):[2,JSON.parse(r)]}catch(t){return console.error("Amplitude Logger [Error]: Failed to parse cookie value for key: ".concat(e,", value: ").concat(n)),[2,void 0]}return[2]}})})},e.prototype.getRaw=function(e){var t,n;return s(this,void 0,void 0,function(){var r,i,o;return u(this,function(s){return r=F(),i=null!==(n=null===(t=null==r?void 0:r.document)||void 0===t?void 0:t.cookie.split("; "))&&void 0!==n?n:[],o=i.find(function(t){return 0===t.indexOf(e+"=")}),o?[2,o.substring(e.length+1)]:[2,void 0]})})},e.prototype.set=function(e,t){var n;return s(this,void 0,void 0,function(){var r,i,o,s,a,c,l;return u(this,function(u){try{r=null!==(n=this.options.expirationDays)&&void 0!==n?n:0,o=void 0,(i=null!==t?r:-1)&&((s=new Date).setTime(s.getTime()+24*i*60*60*1e3),o=s),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)),(c=F())&&(c.document.cookie=a)}catch(t){l=t instanceof Error?t.message:String(t),console.error("Amplitude Logger [Error]: Failed to set cookie for key: ".concat(e,". Error: ").concat(l))}return[2]})})},e.prototype.remove=function(e){return s(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 s(this,void 0,void 0,function(){return u(this,function(e){return[2]})})},e}(),De=function(e){try{return decodeURIComponent(atob(e))}catch(e){return}},Le=function(e){try{return decodeURIComponent(atob(decodeURIComponent(e)))}catch(e){return}},Ne=function(e,t,n){return void 0===t&&(t=""),void 0===n&&(n=10),[v,t,e.substring(0,n)].filter(Boolean).join("_")},je=function(){function e(e){this.storage=e}return e.prototype.isEnabled=function(){return s(this,void 0,void 0,function(){var t,n,r;return u(this,function(i){switch(i.label){case 0:if(!this.storage)return[2,!1];t=String(Date.now()),n=new e(this.storage),r="AMP_TEST",i.label=1;case 1:return i.trys.push([1,4,5,7]),[4,n.set(r,t)];case 2:return i.sent(),[4,n.get(r)];case 3:return[2,i.sent()===t];case 4:return i.sent(),[2,!1];case 5:return[4,n.remove(r)];case 6:return i.sent(),[7];case 7:return[2]}})})},e.prototype.get=function(e){return s(this,void 0,void 0,function(){var t;return u(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getRaw(e)];case 1:return(t=n.sent())?[2,JSON.parse(t)]:[2,void 0];case 2:return n.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 s(this,void 0,void 0,function(){return u(this,function(n){return[2,(null===(t=this.storage)||void 0===t?void 0:t.getItem(e))||void 0]})})},e.prototype.set=function(e,t){var n;return s(this,void 0,void 0,function(){return u(this,function(r){try{null===(n=this.storage)||void 0===n||n.setItem(e,JSON.stringify(t))}catch(e){}return[2]})})},e.prototype.remove=function(e){var t;return s(this,void 0,void 0,function(){return u(this,function(n){try{null===(t=this.storage)||void 0===t||t.removeItem(e)}catch(e){}return[2]})})},e.prototype.reset=function(){var e;return s(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}(),qe="tags",Ue="counters",Me="histograms",Fe="events",Be="internal",He="last_flush_timestamp",Ve=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=F())||void 0===e?void 0:e.indexedDB)},e.prototype.getDB=function(){return s(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,n){var r=indexedDB.open(e.dbName,1);r.onerror=function(){e.dbPromise=null,n(new Error("Failed to open IndexedDB"))},r.onsuccess=function(){var n=r.result;n.onclose=function(){e.dbPromise=null,e.logger.debug("DiagnosticsStorage: DB connection closed.")},n.onerror=function(t){e.logger.debug("DiagnosticsStorage: A global database error occurred.",t),n.close()},t(n)},r.onupgradeneeded=function(t){var n=t.target.result;e.createTables(n)}})},e.prototype.createTables=function(e){(e.objectStoreNames.contains(qe)||e.createObjectStore(qe,{keyPath:"key"}),e.objectStoreNames.contains(Ue)||e.createObjectStore(Ue,{keyPath:"key"}),e.objectStoreNames.contains(Me)||e.createObjectStore(Me,{keyPath:"key"}),e.objectStoreNames.contains(Fe))||e.createObjectStore(Fe,{keyPath:"id",autoIncrement:!0}).createIndex("time_idx","time",{unique:!1});e.objectStoreNames.contains(Be)||e.createObjectStore(Be,{keyPath:"key"})},e.prototype.setTags=function(e){return s(this,void 0,void 0,function(){var t,n,r,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(),n=t.transaction([qe],"readwrite"),r=n.objectStore(qe),[2,new Promise(function(t){var i=Object.entries(e);n.oncomplete=function(){t()},n.onabort=function(e){o.logger.debug("DiagnosticsStorage: Failed to set tags",e),t()},i.forEach(function(e){var t=c(e,2),n=t[0],i=t[1];r.put({key:n,value:i}).onerror=function(e){o.logger.debug("DiagnosticsStorage: Failed to set tag",n,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 s(this,void 0,void 0,function(){var t,n,r,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(),n=t.transaction([Ue],"readwrite"),r=n.objectStore(Ue),[2,new Promise(function(t){var i=Object.entries(e);n.oncomplete=function(){t()},n.onabort=function(e){o.logger.debug("DiagnosticsStorage: Failed to increment counters",e),t()},i.forEach(function(e){var t=c(e,2),n=t[0],i=t[1],s=r.get(n);s.onsuccess=function(){var e=s.result,t=e?e.value:0;r.put({key:n,value:t+i}).onerror=function(e){o.logger.debug("DiagnosticsStorage: Failed to update counter",n,e)}},s.onerror=function(e){o.logger.debug("DiagnosticsStorage: Failed to read existing counter",n,e)}})})];case 2:return i=s.sent(),this.logger.debug("DiagnosticsStorage: Failed to increment counters",i),[3,3];case 3:return[2]}})})},e.prototype.setHistogramStats=function(e){return s(this,void 0,void 0,function(){var t,n,r,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(),n=t.transaction([Me],"readwrite"),r=n.objectStore(Me),[2,new Promise(function(t){var i=Object.entries(e);n.oncomplete=function(){t()},n.onabort=function(e){o.logger.debug("DiagnosticsStorage: Failed to set histogram stats",e),t()},i.forEach(function(e){var t=c(e,2),n=t[0],i=t[1],s=r.get(n);s.onsuccess=function(){var e,t=s.result;e=t?{key:n,count:t.count+i.count,min:Math.min(t.min,i.min),max:Math.max(t.max,i.max),sum:t.sum+i.sum}:{key:n,count:i.count,min:i.min,max:i.max,sum:i.sum},r.put(e).onerror=function(e){o.logger.debug("DiagnosticsStorage: Failed to set histogram stats",n,e)}},s.onerror=function(e){o.logger.debug("DiagnosticsStorage: Failed to read existing histogram stats",n,e)}})})];case 2:return i=s.sent(),this.logger.debug("DiagnosticsStorage: Failed to set histogram stats",i),[3,3];case 3:return[2]}})})},e.prototype.addEventRecords=function(e){return s(this,void 0,void 0,function(){var t,n,r,i,o=this;return u(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),0===e.length?[2]:[4,this.getDB()];case 1:return t=s.sent(),n=t.transaction([Fe],"readwrite"),r=n.objectStore(Fe),[2,new Promise(function(t){n.oncomplete=function(){t()},n.onabort=function(e){o.logger.debug("DiagnosticsStorage: Failed to add event records",e),t()};var i=r.count();i.onsuccess=function(){var t=i.result,n=Math.max(0,10-t);n<e.length&&o.logger.debug("DiagnosticsStorage: Only added ".concat(n," of ").concat(e.length," events due to storage limit")),e.slice(0,n).forEach(function(e){r.add(e).onerror=function(e){o.logger.debug("DiagnosticsStorage: Failed to add event record",e)}})},i.onerror=function(e){o.logger.debug("DiagnosticsStorage: Failed to count existing events",e)}})];case 2:return i=s.sent(),this.logger.debug("DiagnosticsStorage: Failed to add event records",i),[3,3];case 3:return[2]}})})},e.prototype.setInternal=function(e,t){return s(this,void 0,void 0,function(){var n,r,i,o;return u(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this.getDB()];case 1:return n=s.sent(),r=n.transaction([Be],"readwrite"),i=r.objectStore(Be),[2,new Promise(function(n,o){r.onabort=function(){return o(new Error("Failed to set internal value"))};var s=i.put({key:e,value:t});s.onsuccess=function(){return n()},s.onerror=function(){return o(new Error("Failed to set internal value"))}})];case 2:return o=s.sent(),this.logger.debug("DiagnosticsStorage: Failed to set internal value",o),[3,3];case 3:return[2]}})})},e.prototype.getInternal=function(e){return s(this,void 0,void 0,function(){var t,n,r,i;return u(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.getDB()];case 1:return t=o.sent(),n=t.transaction([Be],"readonly"),r=n.objectStore(Be),[2,new Promise(function(t,i){n.onabort=function(){return i(new Error("Failed to get internal value"))};var o=r.get(e);o.onsuccess=function(){return t(o.result)},o.onerror=function(){return i(new Error("Failed to get internal value"))}})];case 2:return i=o.sent(),this.logger.debug("DiagnosticsStorage: Failed to get internal value",i),[2,void 0];case 3:return[2]}})})},e.prototype.getLastFlushTimestamp=function(){return s(this,void 0,void 0,function(){var e,t;return u(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getInternal(He)];case 1:return[2,(e=n.sent())?parseInt(e.value,10):void 0];case 2:return t=n.sent(),this.logger.d