@amplitude/analytics-browser
Version:
Official Amplitude SDK for Web
1 lines • 182 kB
JavaScript
!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";var t=function(e,n){return t=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])},t(e,n)};function n(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r,i,o=function(){return o=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},o.apply(this,arguments)};function s(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 a(e,t,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}u((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=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(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=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],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function c(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 l(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 d(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"==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"}(r||(r={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(i||(i={}));var f,v="AMP",p="".concat(v,"_unsent"),h="$default_instance",g="https://api2.amplitude.com/2/httpapi",m="dclid",y="fbclid",b="gbraid",w="gclid",E="ko_click_id",S="li_fat_id",T="msclkid",k="rdt_cid",_="ttclid",I="twclid",P="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},A=["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"],x=["authorization","cookie","set-cookie"],C=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var n=e[t];if(!R(t,n))return!1}return!0},R=function(e,t){var n,r;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&&C(a);else if(!["number","string"].includes(typeof a))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 C(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},D=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return o({},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,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[f.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===f.ADD?"number"==typeof n:e===f.UNSET||e===f.REMOVE||R(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"}(f||(f={}));var L,N=[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"}(L||(L={}));var j,U=function(e,t,n){return void 0===t&&(t=0),void 0===n&&(n=L.Unknown),{event:e,code:t,message:n}},M=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},F=d([],l(Array(256).keys()),!1).map(function(e){return e.toString(16).padStart(2,"0")}),q=function(e){var t,n=M();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,q)}(e);var r=n.crypto.getRandomValues(new Uint8Array(16));return r[6]=15&r[6]|64,r[8]=63&r[8]|128,d([],l(r.entries()),!1).map(function(e){var t=l(e,2),n=t[0],r=t[1];return[4,6,8,10].includes(n)?"-".concat(F[r]):F[r]}).join("")},B=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 a(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=q(),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 a(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 a(this,void 0,void 0,function(){var t,n,r,i,s,a,d,f,v,p,h,g,m,y,b,w,E,S,T,k;return u(this,function(u){switch(u.label){case 0:if(!e)return[2];t=l(e,1),n=t[0],r=l(e,2),i=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]),a=c(s),d=a.next(),u.label=2;case 2:return d.done?[3,5]:(g=d.value).execute?[4,g.execute(o({},n))]:[3,4];case 3:if(null===(m=u.sent()))return this.loggerProvider.log("Timeline.apply: Event filtered out by before plugin '".concat(String(g.name),"', event: ").concat(JSON.stringify(n))),i({event:n,code:0,message:""}),[2];n=m,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=a.next(),[3,2];case 5:return[3,8];case 6:return f=u.sent(),E={error:f},[3,8];case 7:try{d&&!d.done&&(S=a.return)&&S.call(a)}finally{if(E)throw E.error}return[7];case 8:v=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(v),h=p.next(),u.label=10;case 10:return h.done?[3,13]:(g=h.value).execute?[4,g.execute(o({},n))]:[3,12];case 11:if(null===(m=u.sent()))return this.loggerProvider.log("Timeline.apply: Event filtered out by enrichment plugin '".concat(String(g.name),"', event: ").concat(JSON.stringify(n))),i({event:n,code:0,message:""}),[2];n=m,this.loggerProvider.log("Timeline.apply: Event after enrichment plugin '".concat(String(g.name),"', event: ").concat(JSON.stringify(n))),u.label=12;case 12:return h=p.next(),[3,10];case 13:return[3,16];case 14:return y=u.sent(),T={error:y},[3,16];case 15:try{h&&!h.done&&(k=p.return)&&k.call(p)}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=o({},n);return e.execute(t).catch(function(e){return U(t,0,String(e))})}),Promise.all(w).then(function(e){var t=l(e,1)[0]||U(n,100,"Event not tracked, no destination plugins on the instance");i(t)}),[2]}})})},e.prototype.flush=function(){return a(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.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 o(o({},t),{event_type:i.IDENTIFY,user_properties:e.getUserProperties()})},V=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 B(this),this.name=e}return e.prototype._init=function(e){return a(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 a(this,void 0,void 0,function(){var t,n,r,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]),n=c(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(),a={error:s},[3,10];case 9:try{r&&!r.done&&(l=n.return)&&l.call(n)}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,n){var r=function(e,t,n){return o(o(o({},"string"==typeof e?{event_type:e}:e),n),t&&{event_properties:t})}(e,t,n);return V(this.dispatch(r))},e.prototype.identify=function(e,t){var n=H(e,t);return V(this.dispatch(n))},e.prototype.groupIdentify=function(e,t,n,r){var s=function(e,t,n,r){var s;return o(o({},r),{event_type:i.GROUP_IDENTIFY,group_properties:n.getUserProperties(),groups:(s={},s[e]=t,s)})}(e,t,n,r);return V(this.dispatch(s))},e.prototype.setGroup=function(e,t,n){var r=function(e,t,n){var r,s=new D;return s.set(e,t),o(o({},n),{event_type:i.IDENTIFY,user_properties:s.getUserProperties(),groups:(r={},r[e]=t,r)})}(e,t,n);return V(this.dispatch(r))},e.prototype.revenue=function(e,t){var n=function(e,t){return o(o({},t),{event_type:i.REVENUE,event_properties:e.getEventProperties()})}(e,t);return V(this.dispatch(n))},e.prototype.add=function(e){return this.isReady?this._addPlugin(e):(this.q.push(this._addPlugin.bind(this,e)),V())},e.prototype._addPlugin=function(e){return V(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)),V())},e.prototype._removePlugin=function(e){return V(this.timeline.deregister(e,this.config))},e.prototype.dispatchWithCallback=function(e,t){if(!this.isReady)return t(U(e,0,"Client not initialized"));this.process(e).then(t)},e.prototype.dispatch=function(e){return a(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 n={};return Object.keys(e).forEach(function(t){Object.values(r).includes(t)||(n[t]=e[t])}),N.forEach(function(n){if(Object.keys(e).includes(n)){var i=e[n];switch(n){case r.CLEAR_ALL:Object.keys(t).forEach(function(e){delete t[e]});break;case r.UNSET:Object.keys(i).forEach(function(e){delete t[e]});break;case r.SET:Object.assign(t,i)}}}),Object.assign(t,n),t},e.prototype.process=function(e){return a(this,void 0,void 0,function(){var t,n,r,o;return u(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),this.config.optOut?[2,U(e,0,"Event skipped due to optOut config")]:(e.event_type===i.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(),r=String(n),this.config.loggerProvider.error(r),[2,o=U(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.timeline.onOptOutChanged(e),this.config.optOut=Boolean(e))},e.prototype.flush=function(){return V(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}(),z=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 C(e)&&(this.properties=e),this},e.prototype.getEventProperties=function(){var e=this.properties?o({},this.properties):{};return e[j.REVENUE_PRODUCT_ID]=this.productId,e[j.REVENUE_QUANTITY]=this.quantity,e[j.REVENUE_PRICE]=this.price,e[j.REVENUE_TYPE]=this.revenueType,e[j.REVENUE_CURRENCY]=this.currency,e[j.REVENUE]=this.revenue,e[j.RECEIPT]=this.receipt,e[j.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"}(j||(j={}));var $;!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"}($||($={}));var K="Amplitude Logger ",W=function(){function e(){this.logLevel=$.None}return e.prototype.disable=function(){this.logLevel=$.None},e.prototype.enable=function(e){void 0===e&&(e=$.Warn),this.logLevel=e},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<$.Verbose||console.log("".concat(K,"[Log]: ").concat(e.join(" ")))},e.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<$.Warn||console.warn("".concat(K,"[Warn]: ").concat(e.join(" ")))},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<$.Error||console.error("".concat(K,"[Error]: ").concat(e.join(" ")))},e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<$.Debug||console.log("".concat(K,"[Debug]: ").concat(e.join(" ")))},e}(),G=function(){return{flushMaxRetries:12,flushQueueSize:200,flushIntervalMillis:1e4,instanceName:h,logLevel:$.Warn,loggerProvider:new W,offline:!1,optOut:!1,serverUrl:g,serverZone:"US",useBatch:!1}},Q=function(){function e(e){var t,n,r,i;this._optOut=!1;var o=G();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=X(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}(),Y=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":g},X=function(e,t,n){if(void 0===e&&(e=""),void 0===t&&(t=G().serverZone),void 0===n&&(n=G().useBatch),e)return{serverUrl:e,serverZone:void 0};var r=["US","EU"].includes(t)?t:G().serverZone;return{serverZone:r,serverUrl:Y(r,n)}},Z=function(){function e(){this.sdk={metrics:{histogram:{}}}}return e.prototype.recordHistogram=function(e,t){this.sdk.metrics.histogram[e]=t},e}();function ee(e){return e>=200&&e<300}var te=function(e){return void 0===e&&(e=0),((new Error).stack||"").split("\n").slice(2+e).map(function(e){return e.trim()})},ne=function(e){return function(){var t=o({},e.config);return{logger:t.loggerProvider,logLevel:t.logLevel}}},re=function(e,t){var n,r;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){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return e},ie=function(e,t){return function(){var n,r,i={};try{for(var o=c(t),s=o.next();!s.done;s=o.next()){var a=s.value;i[a]=re(e,a)}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return i}},oe=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 a=n(),u=a.logger,c=a.logLevel;if(c&&c<$.Debug||!c||!u)return e.apply(i,o);var l={type:"invoke public method",name:t,args:o,stacktrace:te(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()),u.debug(JSON.stringify(l,null,2))}):(r&&l.states&&(l.states.after=r()),l.time&&(l.time.end=(new Date).toISOString()),u.debug(JSON.stringify(l,null,2))),d}};function se(e){var t="";try{"body"in e&&(t=JSON.stringify(e.body,null,2))}catch(e){}return t}var ae=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 a(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(p,"_").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=q()),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),a(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,s=this.config.flushQueueSize,c=Math.max(s,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 a(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,s,c})})},e.prototype.send=function(e,t){var n;return void 0===t&&(t=!0),a(this,void 0,void 0,function(){var r,i,o,a,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")];r={api_key:this.config.apiKey,events:e.map(function(e){var t=e.event;return t.extra,s(t,["extra"])}),options:{min_id_length:this.config.minIdLength},client_upload_time:(new Date).toISOString(),request_metadata:this.config.requestMetadata},this.config.requestMetadata=new Z,u.label=1;case 1:return u.trys.push([1,3,,4]),i=X(this.config.serverUrl,this.config.serverZone,this.config.useBatch).serverUrl,[4,this.config.transportProvider.send(i,r)];case 2:return null===(o=u.sent())?(this.fulfillRequest(e,0,"Unexpected error occurred"),[2]):t?(this.handleResponse(o,e),[3,4]):("body"in o?this.fulfillRequest(e,o.statusCode,"".concat(o.status,": ").concat(se(o))):this.fulfillRequest(e,o.statusCode,o.status),[2]);case 3:return a=u.sent(),c=(l=a)instanceof Error?l.message:String(l),this.config.loggerProvider.error(c),null===(n=this.diagnosticsClient)||void 0===n||n.recordEvent("analytics.events.unsuccessful.from.catch.error",{events:e.map(function(e){return e.event.event_type}),message:c,stack_trace:te()}),this.handleResponse({status:L.Failed,statusCode:0},e),[3,4];case 4:return[2]}var l})})},e.prototype.handleResponse=function(e,t){var n;ee(e.statusCode)||null===(n=this.diagnosticsClient)||void 0===n||n.recordEvent("analytics.events.unsuccessful",{events:t.map(function(e){return e.event.event_type}),code:e.statusCode,status:e.status,body:se(e),stack_trace:te()});var r=e.status;switch(r){case L.Success:this.handleSuccessResponse(e,t);break;case L.Invalid:this.handleInvalidResponse(e,t);break;case L.PayloadTooLarge:this.handlePayloadTooLargeResponse(e,t);break;case L.RateLimit:this.handleRateLimitResponse(e,t);break;default:this.config.loggerProvider.warn("{code: 0, error: \"Status '".concat(r,"' 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=d(d(d(d([],l(Object.values(e.body.eventsWithInvalidFields)),!1),l(Object.values(e.body.eventsWithMissingFields)),!1),l(Object.values(e.body.eventsWithInvalidIdLengths)),!1),l(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(se(e));var s=this.removeEventsExceedFlushMaxRetries(o);this.scheduleEvents(s)}},e.prototype.handlePayloadTooLargeResponse=function(e,t){if(1!==t.length){this.config.loggerProvider.warn(se(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),a=new Set(i),u=new Set(o),c=t.filter(function(t,r){if(!(t.event.user_id&&s.has(t.event.user_id)||t.event.device_id&&a.has(t.event.device_id)))return u.has(r)&&(t.timeout=n.throttleTimeout),!0;n.fulfillRequest([t],e.statusCode,e.body.error)});c.length>0&&this.config.loggerProvider.warn(se(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;ee(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:te()})),this.removeEvents(e),e.forEach(function(e){return e.callback(U(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}(),ue=function(){function e(){}return e.prototype.getApplicationContext=function(){return{versionName:this.versionName,language:ce(),platform:"Web",os:void 0,deviceModel:void 0}},e}(),ce=function(){return"undefined"!=typeof navigator&&(navigator.languages&&navigator.languages[0]||navigator.language)||""},le=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}(),de=function(){return de=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},de.apply(this,arguments)};function fe(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 pe=function(e,t){var n,r,i=typeof e;if(i!==typeof t)return!1;try{for(var o=fe(["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 a=Array.isArray(e),u=Array.isArray(t);if(a!==u)return!1;if(!a||!u){var c=Object.keys(e).sort(),l=Object.keys(t).sort();if(!pe(c,l))return!1;var d=!0;return Object.keys(e).forEach(function(n){pe(e[n],t[n])||(d=!1)}),d}for(var f=0;f<e.length;f++)if(!pe(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 he=function(){function e(){this.identity={userProperties:{}},this.listeners=new Set}return e.prototype.editIdentity=function(){var e=this,t=de({},this.identity.userProperties),n=de(de({},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,a,u=n.userProperties||{};try{for(var c=fe(Object.entries(e)),l=c.next();!l.done;l=c.next()){var d=ve(l.value,2),f=d[0],v=d[1];switch(f){case"$set":try{for(var p=(i=void 0,fe(Object.entries(v))),h=p.next();!h.done;h=p.next()){var g=ve(h.value,2),m=g[0],y=g[1];u[m]=y}}catch(e){i={error:e}}finally{try{h&&!h.done&&(o=p.return)&&o.call(p)}finally{if(i)throw i.error}}break;case"$unset":try{for(var b=(s=void 0,fe(Object.keys(v))),w=b.next();!w.done;w=b.next()){delete u[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":u={}}}}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=u,this},commit:function(){return e.setIdentity(n),this}}},e.prototype.getIdentity=function(){return de({},this.identity)},e.prototype.setIdentity=function(e){var t=de({},this.identity);this.identity=de({},e),pe(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}(),ge="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self,me=function(){function e(){this.identityStore=new he,this.eventBridge=new le,this.applicationContextProvider=new ue}return e.getInstance=function(t){return ge.analyticsConnectorInstances||(ge.analyticsConnectorInstances={}),ge.analyticsConnectorInstances[t]||(ge.analyticsConnectorInstances[t]=new e),ge.analyticsConnectorInstances[t]},e}(),ye=function(e){return void 0===e&&(e=h),me.getInstance(e)},be=function(){function e(){this.name="identity",this.type="before",this.identityStore=ye().identityStore}return e.prototype.execute=function(e){return a(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 a(this,void 0,void 0,function(){return u(this,function(t){return e.instanceName&&(this.identityStore=ye(e.instanceName).identityStore),[2]})})},e}(),we=function(e,t){return void 0===t&&(t=Date.now()),Date.now()-t>e},Ee=function(e,t,n){return void 0===t&&(t=""),void 0===n&&(n=10),[v,t,e.substring(0,n)].filter(Boolean).join("_")},Se=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:""},Te=function(){var e,t=M();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=ke(n[0]),i=ke(n[1]);return i?(e[r]=i,e):e},{}):{}},ke=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},_e=function(e,t){return!t||!t.length||t.some(function(t){return"string"==typeof t?e===t:e.match(t)})},Ie=function(e,t){var n=e;try{n=decodeURI(e)}catch(e){null==t||t.error("Malformed URI sequence: ",e)}return n},Pe=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},Oe=function(){function e(){this.memoryStorage=new Map}return e.prototype.isEnabled=function(){return a(this,void 0,void 0,function(){return u(this,function(e){return[2,!0]})})},e.prototype.get=function(e){return a(this,void 0,void 0,function(){return u(this,function(t){return[2,this.memoryStorage.get(e)]})})},e.prototype.getRaw=function(e){return a(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 a(this,void 0,void 0,function(){return u(this,function(n){return this.memoryStorage.set(e,t),[2]})})},e.prototype.remove=function(e){return a(this,void 0,void 0,function(){return u(this,function(t){return this.memoryStorage.delete(e),[2]})})},e.prototype.reset=function(){return a(this,void 0,void 0,function(){return u(this,function(e){return this.memoryStorage.clear(),[2]})})},e}(),Ae=function(){function e(e,t){void 0===t&&(t={}),this.options=o({},e),this.config=t}return e.prototype.isEnabled=function(){return a(this,void 0,void 0,function(){var t,n,r;return u(this,function(i){switch(i.label){case 0:if(!M())return[2,!1];e.testValue=String(Date.now()),t=o(o({},this.options),{expirationDays:.003}),n=new e(t),r="AMP_TEST_".concat(q().substring(0,8)),i.label=1;case 1:return i.trys.push([1,4,5,7]),[4,n.set(r,e.testValue)];case 2:return i.sent(),[4,n.get(r)];case 3:return[2,i.sent()===e.testValue];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 a(this,void 0,void 0,function(){var t,n;return u(this,function(r){switch(r.label){case 0:return[4,this.getRaw(e)];case 1:if(!(t=r.sent()))return[2,void 0];try{return void 0===(n=xe(t))?(console.error("Amplitude Logger [Error]: Failed to decode cookie value for key: ".concat(e,", value: ").concat(t)),[2,void 0]):[2,JSON.parse(n)]}catch(n){return console.error("Amplitude Logger [Error]: Failed to parse cookie value for key: ".concat(e,", value: ").concat(t)),[2,void 0]}return[2]}})})},e.prototype.getRaw=function(e){var t,n,r,i;return a(this,void 0,void 0,function(){var o,s,a,l,d,f,v,p,h,g,m,y,b=this;return u(this,function(u){switch(u.label){case 0:o=M(),s=o,u.label=1;case 1:return u.trys.push([1,4,,5]),(a=null==s?void 0:s.cookieStore)?[4,a.getAll(e)]:[3,3];case 2:if(l=u.sent()){l.length>1&&(null===(t=this.config.diagnosticsClient)||void 0===t||t.recordEvent("cookies.duplicate",{cookies:l.map(function(e){return e.domain})}),null===(n=this.config.diagnosticsClient)||void 0===n||n.increment("cookies.duplicate.occurrence.cookieStore"));try{for(d=c(l),f=d.next();!f.done;f=d.next())if(v=f.value,Ce(v.domain,this.options.domain))return[2,v.value]}catch(e){m={error:e}}finally{try{f&&!f.done&&(y=d.return)&&y.call(d)}finally{if(m)throw m.error}}}u.label=3;case 3:return[3,5];case 4:return u.sent(),[3,5];case 5:return p=(null!==(i=null===(r=null==o?void 0:o.document)||void 0===r?void 0:r.cookie.split("; "))&&void 0!==i?i:[]).filter(function(t){return 0===t.indexOf(e+"=")}),h=void 0,"function"==typeof(g=this.config.duplicateResolverFn)&&p.length>1&&(h=p.find(function(t){var n;try{var r=g(t.substring(e.length+1));return r||null===(n=b.config.diagnosticsClient)||void 0===n||n.increment("cookies.duplicate.occurrence.document.cookie"),r}catch(e){return!1}})),h||(h=p[0]),h?[2,h.substring(e.length+1)]:[2,void 0]}})})},e.prototype.set=function(e,t){var n;return a(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=M())&&(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 a(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 a(this,void 0,void 0,function(){return u(this,function(e){return[2]})})},e}(),xe=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)},Ce=function(e,t){if(!e||!t)return!1;var n=e.startsWith(".")?e.substring(1):e,r=t.startsWith(".")?t.substring(1):t;return n.toLowerCase()===r.toLowerCase()},Re=function(e,t,n){return void 0===t&&(t=""),void 0===n&&(n=10),[v,t,e.substring(0,n)].filter(Boolean).join("_")},De=function(){function e(e){this.storage=e}return e.prototype.isEnabled=function(){return a(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 a(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 a(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 a(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 a(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 a(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}(),Le="tags",Ne="counters",je="histograms",Ue="events",Me="internal",Fe="last_flush_timestamp",qe=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=M())||void 0===e?void 0:e.indexedDB)},e.prototype.getDB=function(){return a(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(Le)||e.createObjectStore(Le,{keyPath:"key"}),e.objectStoreNames.contains(Ne)||e.createObjectStore(Ne,{keyPath:"key"}),e.objectStoreNames.contains(je)||e.createObjectStore(je,{keyPath:"key"}),e.objectStoreNames.contains(Ue))||e.createObjectStore(Ue,{keyPath:"id",autoIncrement:!0}).createIndex("time_idx","time",{unique:!1});e.objectStoreNames.contains(Me)||e.createObjectStore(Me,{keyPath:"key"})},e.prototype.setTags=function(e){return a(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([Le],"readwrite"),r=n.objectStore(Le),[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=l(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 a(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([Ne],"readwrite"),r=n.objectStore(Ne),[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=l(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 a(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([je],"readwrite"),r=n.objectStore(je),[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=l(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 a(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([Ue],"readwrite"),r=n.objectStore(Ue),[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 a(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([Me],"readwrite"),i=r.objectStore(Me),[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 a(this,void 0,void 0,function(){var t,n,r,i;return u(this,function(o){switch(o.lab