))&&(me(e)?Te:Se).test(Ee(e))},je=function(e,t){return null==e?void 0:e[t]},ke=function(e,t){var n=je(e,t);return xe(n)?n:void 0},Re=function(){try{var e=ke(Object,"defineProperty"); return e({},"",{}),e}catch(e){}}(),Pe=function(e,t,n){"__proto__"==t&&Re?Re(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n},Fe=function(e,t){return e===t||e!=e&&t!=t},Ue=Object.prototype.hasOwnProperty,De=function(e,t,n){var r=e[t];Ue.call(e,t)&&Fe(r,n)&&(void 0!==n||t in e)||Pe(e,t,n)},Me=function(e,t,n,r){var o=!n;n||(n={});for(var i=-1,s=t.length;++i0){if(++t>=ze)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}(Ke),Ye=function(e,t){return We(Ge(e,t,qe),e+"")},Qe=9007199254740991,Xe=function(e){return"number"==typeof e&&e>-1&&e%1==0&&Qe>=e},He=function(e){return null!=e&&Xe(e.length)&&!me(e)},Ze=9007199254740991,et=/^(?:0|[1-9]\d*)$/,tt=function(e,t){return!!(t=null==t?Ze:t)&&("number"==typeof e||et.test(e))&&e>-1&&e%1==0&&t>e},nt=function(e,t,n){if(!de(n))return!1;var r=typeof t;return!!("number"==r?He(n)&&tt(t,n.length):"string"==r&&t in n)&&Fe(n[t],e)},rt=function(e){return Ye(function(t,n){var r=-1,o=n.length,i=o>1?n[o-1]:void 0,s=o>2?n[2]:void 0;for(i=e.length>3&&"function"==typeof i?(o--,i):void 0,s&&nt(n[0],n[1],s)&&(i=3>o?void 0:i,o=1),t=Object(t);++r0?2==o.length?"function"==typeof o[1]?e[o[0]]=o[1].call(this,s):e[o[0]]=o[1]:3==o.length?"function"!=typeof o[1]||o[1].exec&&o[1].test?e[o[0]]=s?s.replace(o[1],o[2]):void 0:e[o[0]]=s?o[1].call(this,s,o[2]):void 0:4==o.length&&(e[o[0]]=s?o[3].call(this,s.replace(o[1],o[2])):void 0):e[o]=s||void 0;a+=2}return e},str:function(e,t){for(var n in t)if("object"==typeof t[n]&&t[n].length>0){for(var r=0;r>e/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,tn)},Mt={apiEndpoint:"api.amplitude.com",cookieExpiration:3650,cookieName:"amplitude_id",domain:"",includeReferrer:!1,includeUtm:!1,language:{language:navigator&&(navigator.languages&&navigator.languages[0]||navigator.language||navigator.userLanguage)||void 0}.language,logLevel:"WARN",optOut:!1,platform:"Web",savedMaxCount:1e3,saveEvents:!0,sessionTimeout:18e5,unsentKey:"amplitude_unsent",unsentIdentifyKey:"amplitude_unsent_identify",uploadBatchSize:100,batchEvents:!1,eventUploadThreshold:30,eventUploadPeriodMillis:3e4,forceHttps:!0,includeGclid:!1,saveParamsReferrerOncePerSession:!0,deviceIdFromUrlParam:!1},qt=function(e){this._instanceName=M.isEmptyString(e)?f.DEFAULT_INSTANCE:e.toLowerCase(),this._legacyStorageSuffix=this._instanceName===f.DEFAULT_INSTANCE?"":"_"+this._instanceName,this._unsentEvents=[],this._unsentIdentifys=[],this._ua=new Ut(navigator.userAgent).getResult(),this.options=xt({},Mt),this.cookieStorage=(new Y).getStorage(),this._q=[],this._sending=!1,this._updateScheduled=!1,this._eventId=0,this._identifyId=0,this._lastEventTime=null,this._newSession=!1,this._sequenceNumber=0,this._sessionId=null,this._userAgent=navigator&&navigator.userAgent||null};qt.prototype.Identify=Q,qt.prototype.Revenue=Ft,qt.prototype.init=function(e,t,n,r){if("string"!==A(e)||M.isEmptyString(e))M.log.error("Invalid apiKey. Please re-initialize with a valid apiKey");else try{if(this.options.apiKey=e,this._storageSuffix="_"+e+this._legacyStorageSuffix,Lt(this.options,n),this.cookieStorage.options({expirationDays:this.options.cookieExpiration,domain:this.options.domain}),this.options.domain=this.cookieStorage.options().domain,this._instanceName===f.DEFAULT_INSTANCE&&Vt(this),Gt(this),this.options.deviceId="object"===A(n)&&"string"===A(n.deviceId)&&!M.isEmptyString(n.deviceId)&&n.deviceId||this.options.deviceIdFromUrlParam&&this._getDeviceIdFromUrlParam(this._getUrlParams())||this.options.deviceId||Dt()+"R",this.options.userId="string"===A(t)&&!M.isEmptyString(t)&&t||"number"===A(t)&&t.toString()||this.options.userId||null,this.options.saveEvents){this._unsentEvents=this._loadSavedUnsentEvents(this.options.unsentKey),this._unsentIdentifys=this._loadSavedUnsentEvents(this.options.unsentIdentifyKey);for(var o=0;othis.options.sessionTimeout)&&(this._newSession=!0,this._sessionId=p,this.options.saveParamsReferrerOncePerSession&&this._trackParamsAndReferrer()),this.options.saveParamsReferrerOncePerSession||this._trackParamsAndReferrer(),this._lastEventTime=p,Kt(this),this._sendEventsIfReady()}catch(e){M.log.error(e)}finally{"function"===A(r)&&r(this)}},qt.prototype._trackParamsAndReferrer=function(){this.options.includeUtm&&this._initUtmData(),this.options.includeReferrer&&this._saveReferrer(this._getReferrer()),this.options.includeGclid&&this._saveGclid(this._getUrlParams())};var Lt=function(e,t){if("object"===A(t)){var n=function(n){if(Mt.hasOwnProperty(n)){var r=t[n],o=A(Mt[n]);M.validateInput(r,n+" option",o)&&("boolean"===o?e[n]=!!r:("string"===o&&!M.isEmptyString(r)||"number"===o&&r>0)&&(e[n]=r))}};for(var r in t)t.hasOwnProperty(r)&&n(r)}};qt.prototype.runQueuedFunctions=function(){for(var e=0;e=this.options.eventUploadThreshold?(this.sendEvents(e),!0):(this._updateScheduled||(this._updateScheduled=!0,setTimeout(function(){this._updateScheduled=!1,this.sendEvents()}.bind(this),this.options.eventUploadPeriodMillis)),!1):(this.sendEvents(e),!0))},qt.prototype._getFromStorage=function(e,t){return e.getItem(t+this._storageSuffix)},qt.prototype._getFromStorageLegacy=function(e,t){return e.getItem(t+this._legacyStorageSuffix)},qt.prototype._setInStorage=function(e,t,n){e.setItem(t+this._storageSuffix,n)};var Vt=function(e){var t=e.cookieStorage.get(e.options.cookieName+e._storageSuffix);if("object"!==A(t)&&(t=e.cookieStorage.get(e.options.cookieName+e._legacyStorageSuffix),!("object"===A(t)&&t.deviceId&&t.sessionId&&t.lastEventTime))){var n=function(e){var t=W.getItem(e);return W.removeItem(e),t},r="string"===A(e.options.apiKey)&&"_"+e.options.apiKey.slice(0,6)||"",o=n(f.DEVICE_ID+r),i=n(f.USER_ID+r),s=n(f.OPT_OUT+r);null!==s&&void 0!==s&&(s="true"===String(s));var a=parseInt(n(f.SESSION_ID)),u=parseInt(n(f.LAST_EVENT_TIME)),c=parseInt(n(f.LAST_EVENT_ID)),p=parseInt(n(f.LAST_IDENTIFY_ID)),l=parseInt(n(f.LAST_SEQUENCE_NUMBER)),d=function(e){return"object"===A(t)&&t[e]};e.options.deviceId=d("deviceId")||o,e.options.userId=d("userId")||i,e._sessionId=d("sessionId")||a||e._sessionId,e._lastEventTime=d("lastEventTime")||u||e._lastEventTime,e._eventId=d("eventId")||c||e._eventId,e._identifyId=d("identifyId")||p||e._identifyId,e._sequenceNumber=d("sequenceNumber")||l||e._sequenceNumber,e.options.optOut=s||!1,t&&void 0!==t.optOut&&null!==t.optOut&&(e.options.optOut="true"===String(t.optOut)),Kt(e)}},Gt=function(e){var t=e.cookieStorage.get(e.options.cookieName+e._storageSuffix);if("object"===A(t))Bt(e,t);else{var n=e.cookieStorage.get(e.options.cookieName+e._legacyStorageSuffix);"object"===A(n)&&(e.cookieStorage.remove(e.options.cookieName+e._legacyStorageSuffix),Bt(e,n))}},Bt=function(e,t){t.deviceId&&(e.options.deviceId=t.deviceId),t.userId&&(e.options.userId=t.userId),null!==t.optOut&&void 0!==t.optOut&&(e.options.optOut=t.optOut),t.sessionId&&(e._sessionId=parseInt(t.sessionId)),t.lastEventTime&&(e._lastEventTime=parseInt(t.lastEventTime)),t.eventId&&(e._eventId=parseInt(t.eventId)),t.identifyId&&(e._identifyId=parseInt(t.identifyId)),t.sequenceNumber&&(e._sequenceNumber=parseInt(t.sequenceNumber))},Kt=function(e){e.cookieStorage.set(e.options.cookieName+e._storageSuffix,{deviceId:e.options.deviceId,userId:e.options.userId,optOut:e.options.optOut,sessionId:e._sessionId,lastEventTime:e._lastEventTime,eventId:e._eventId,identifyId:e._identifyId,sequenceNumber:e._sequenceNumber})};qt.prototype._initUtmData=function(e,t){e=e||this._getUrlParams();var n=function(e,t){var n=e?"?"+e.split(".").slice(-1)[0].replace(/\|/g,"&"):"",r=function(e,t,n,r){return M.getQueryParam(e,t)||M.getQueryParam(n,r)},o=r("utm_source",t,"utmcsr",n),i=r("utm_medium",t,"utmcmd",n),s=r("utm_campaign",t,"utmccn",n),a=r("utm_term",t,"utmctr",n),u=r("utm_content",t,"utmcct",n),c={},p=function(e,t){M.isEmptyString(t)||(c[e]=t)};return p("utm_source",o),p("utm_medium",i),p("utm_campaign",s),p("utm_term",a),p("utm_content",u),c}(t=t||this.cookieStorage.get("__utmz"),e);zt(this,n)};var zt=function(e,t){if("object"===A(t)&&0!==Object.keys(t).length){var n=new Q;for(var r in t)t.hasOwnProperty(r)&&(n.setOnce("initial_"+r,t[r]),n.set(r,t[r]));e.identify(n)}};qt.prototype._getReferrer=function(){return document.referrer},qt.prototype._getUrlParams=function(){return location.search},qt.prototype._saveGclid=function(e){var t=M.getQueryParam("gclid",e);M.isEmptyString(t)||zt(this,{gclid:t})},qt.prototype._getDeviceIdFromUrlParam=function(e){return M.getQueryParam(f.AMP_DEVICE_ID_PARAM,e)},qt.prototype._getReferringDomain=function(e){if(M.isEmptyString(e))return null;var t=e.split("/");return t.length>=3?t[2]:null},qt.prototype._saveReferrer=function(e){if(!M.isEmptyString(e)){var t={referrer:e,referring_domain:this._getReferringDomain(e)};zt(this,t)}},qt.prototype.saveEvents=function(){try{this._setInStorage(W,this.options.unsentKey,JSON.stringify(this._unsentEvents))}catch(e){}try{this._setInStorage(W,this.options.unsentIdentifyKey,JSON.stringify(this._unsentIdentifys))}catch(e){}},qt.prototype.setDomain=function(e){if(M.validateInput(e,"domain","string"))try{this.cookieStorage.options({domain:e}),this.options.domain=this.cookieStorage.options().domain,Gt(this),Kt(this)}catch(e){M.log.error(e)}},qt.prototype.setUserId=function(e){try{this.options.userId=void 0!==e&&null!==e&&""+e||null,Kt(this)}catch(e){M.log.error(e)}},qt.prototype.setGroup=function(e,t){if(this._apiKeySet("setGroup()")&&M.validateInput(e,"groupType","string")&&!M.isEmptyString(e)){var n={};n[e]=t;var r=(new Q).set(e,t);this._logEvent(f.IDENTIFY_EVENT,null,null,r.userPropertiesOperations,n,null,null)}},qt.prototype.setOptOut=function(e){if(M.validateInput(e,"enable","boolean"))try{this.options.optOut=e,Kt(this)}catch(e){M.log.error(e)}},qt.prototype.setSessionId=function(e){if(M.validateInput(e,"sessionId","number"))try{this._sessionId=e,Kt(this)}catch(e){M.log.error(e)}},qt.prototype.regenerateDeviceId=function(){this.setDeviceId(Dt()+"R")},qt.prototype.setDeviceId=function(e){if(M.validateInput(e,"deviceId","string"))try{M.isEmptyString(e)||(this.options.deviceId=""+e,Kt(this))}catch(e){M.log.error(e)}},qt.prototype.setUserProperties=function(e){if(this._apiKeySet("setUserProperties()")&&M.validateInput(e,"userProperties","object")){var t=M.truncate(M.validateProperties(e));if(0!==Object.keys(t).length){var n=new Q;for(var r in t)t.hasOwnProperty(r)&&n.set(r,t[r]);this.identify(n)}}},qt.prototype.clearUserProperties=function(){if(this._apiKeySet("clearUserProperties()")){var e=new Q;e.clearAll(),this.identify(e)}};var Jt=function(e,t){for(var n=0;n0)return this._logEvent(f.IDENTIFY_EVENT,null,null,e.userPropertiesOperations,null,null,t)}else M.log.error("Invalid identify input type. Expected Identify object but saw "+A(e));"function"===A(t)&&t(0,"No request sent")}else"function"===A(t)&&t(0,"No request sent")},qt.prototype.setVersionName=function(e){M.validateInput(e,"versionName","string")&&(this.options.versionName=e)},qt.prototype._logEvent=function(e,t,n,r,o,i,s){if(Gt(this),e&&!this.options.optOut)try{var a;a=e===f.IDENTIFY_EVENT?this.nextIdentifyId():this.nextEventId();var u=this.nextSequenceNumber(),c="number"===A(i)?i:(new Date).getTime();(!this._sessionId||!this._lastEventTime||c-this._lastEventTime>this.options.sessionTimeout)&&(this._sessionId=c),this._lastEventTime=c,Kt(this),r=r||{},n=n||{},t=t||{},o=o||{};var p={device_id:this.options.deviceId,user_id:this.options.userId,timestamp:c,event_id:a,session_id:this._sessionId||-1,event_type:e,version_name:this.options.versionName||null,platform:this.options.platform,os_name:this._ua.browser.name||null,os_version:this._ua.browser.major||null,device_model:this._ua.os.name||null,language:this.options.language,api_properties:n,event_properties:M.truncate(M.validateProperties(t)),user_properties:M.truncate(M.validateProperties(r)),uuid:Dt(),library:{name:"amplitude-js",version:"4.1.1"},sequence_number:u,groups:M.truncate(M.validateGroups(o)),user_agent:this._userAgent};return e===f.IDENTIFY_EVENT?(this._unsentIdentifys.push(p),this._limitEventsQueued(this._unsentIdentifys)):(this._unsentEvents.push(p),this._limitEventsQueued(this._unsentEvents)),this.options.saveEvents&&this.saveEvents(),this._sendEventsIfReady(s)||"function"!==A(s)||s(0,"No request sent"),a}catch(e){M.log.error(e)}else"function"===A(s)&&s(0,"No request sent")},qt.prototype._limitEventsQueued=function(e){e.length>this.options.savedMaxCount&&e.splice(0,e.length-this.options.savedMaxCount)},qt.prototype.logEvent=function(e,t,n){return this.logEventWithTimestamp(e,t,null,n)},qt.prototype.logEventWithTimestamp=function(e,t,n,r){return this._apiKeySet("logEvent()")&&M.validateInput(e,"eventType","string")&&!M.isEmptyString(e)?this._logEvent(e,t,null,null,null,n,r):("function"===A(r)&&r(0,"No request sent"),-1)},qt.prototype.logEventWithGroups=function(e,t,n,r){return this._apiKeySet("logEventWithGroup()")&&M.validateInput(e,"eventType","string")?this._logEvent(e,t,null,null,n,null,r):("function"===A(r)&&r(0,"No request sent"),-1)};var $t=function(e){return!isNaN(parseFloat(e))&&isFinite(e)};qt.prototype.logRevenueV2=function(e){if(this._apiKeySet("logRevenueV2()"))if("object"===A(e)&&e.hasOwnProperty("_q")&&(e=Jt(new Ft,e)),e instanceof Ft){if(e&&e._isValidRevenue())return this.logEvent(f.REVENUE_EVENT,e._toJSONObject())}else M.log.error("Invalid revenue input type. Expected Revenue object but saw "+A(e))},qt.prototype.logRevenue=function(e,t,n){return this._apiKeySet("logRevenue()")&&$t(e)&&(void 0===t||$t(t))?this._logEvent(f.REVENUE_EVENT,{},{productId:n,special:"revenue_amount",quantity:t||1,price:e},null,null,null,null):-1},qt.prototype.removeEvents=function(e,t){Wt(this,"_unsentEvents",e),Wt(this,"_unsentIdentifys",t)};var Wt=function(e,t,n){if(!(0>n)){for(var r=[],o=0;on&&r.push(e[t][o]);e[t]=r}};qt.prototype.sendEvents=function(e){if(!this._apiKeySet("sendEvents()")||this._sending||this.options.optOut||0===this._unsentCount())"function"===A(e)&&e(0,"No request sent");else{this._sending=!0;var t=(this.options.forceHttps?"https":"https:"===window.location.protocol?"https":"http")+"://"+this.options.apiEndpoint+"/",n=Math.min(this._unsentCount(),this.options.uploadBatchSize),r=this._mergeEventsAndIdentifys(n),o=r.maxEventId,i=r.maxIdentifyId,s=JSON.stringify(r.eventsToSend),a=(new Date).getTime(),u={ client:this.options.apiKey,e:s,v:f.API_VERSION,upload_time:a,checksum:X(f.API_VERSION+this.options.apiKey+s+a)},c=this;new Pt(t,u).send(function(e,t){c._sending=!1;try{200===e&&"success"===t?(c.removeEvents(o,i),c.options.saveEvents&&c.saveEvents(),c._sendEventsIfReady(r)||"function"!==A(r)||r(e,t)):413===e?(1===c.options.uploadBatchSize&&c.removeEvents(o,i),c.options.uploadBatchSize=Math.ceil(n/2),c.sendEvents(r)):"function"===A(r)&&r(e,t)}catch(r){}})}},qt.prototype._mergeEventsAndIdentifys=function(e){for(var t=[],n=0,r=-1,o=0,i=-1;t.length=this._unsentIdentifys.length,u=n>=this._unsentEvents.length;if(u&&a){M.log.error("Merging Events and Identifys, less events and identifys than expected");break}a?r=(s=this._unsentEvents[n++]).event_id:u?i=(s=this._unsentIdentifys[o++]).event_id:!("sequence_number"in this._unsentEvents[n])||this._unsentEvents[n].sequence_number