@amplitude/plugin-session-replay-browser 1.28.0 → 1.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- 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,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})}function s(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(c){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,c])}}}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"==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 u,d="$default_instance",v="https://api2.amplitude.com/2/httpapi";!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"}(u||(u={}));var h,g=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=l([],c(Array(256).keys()),!1).map(function(e){return e.toString(16).padStart(2,"0")}),p=function(e){var t,n=g();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,p)}(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(f[r]):f[r]}).join("")},m=function(e){return{promise:e||Promise.resolve()}};!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"}(h||(h={}));var y="Amplitude Logger ",b=function(){function e(){this.logLevel=h.None}return e.prototype.disable=function(){this.logLevel=h.None},e.prototype.enable=function(e){void 0===e&&(e=h.Warn),this.logLevel=e},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<h.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<h.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<h.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<h.Debug||console.log("".concat(y,"[Debug]: ").concat(e.join(" ")))},e}(),S=function(){return{flushMaxRetries:12,flushQueueSize:200,flushIntervalMillis:1e4,instanceName:d,logLevel:h.Warn,loggerProvider:new b,offline:!1,optOut:!1,serverUrl:v,serverZone:"US",useBatch:!1}},I=function(){function e(e){var t,n,r,i;this._optOut=!1;var o=S();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=C(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}(),w=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":v},C=function(e,t,n){if(void 0===e&&(e=""),void 0===t&&(t=S().serverZone),void 0===n&&(n=S().useBatch),e)return{serverUrl:e,serverZone:void 0};var r=["US","EU"].includes(t)?t:S().serverZone;return{serverZone:r,serverUrl:w(r,n)}};var P=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(),c=a.logger,l=a.logLevel;if(l&&l<h.Debug||!l||!c)return e.apply(i,o);var u,d={type:"invoke public method",name:t,args:o,stacktrace:(u=1,void 0===u&&(u=0),((new Error).stack||"").split("\n").slice(2+u).map(function(e){return e.trim()})),time:{start:(new Date).toISOString()},states:{}};r&&d.states&&(d.states.before=r());var v=e.apply(i,o);return v&&v.promise?v.promise.then(function(){r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),c.debug(JSON.stringify(d,null,2))}):(r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),c.debug(JSON.stringify(d,null,2))),v}},k=function(){function e(){}return e.prototype.getApplicationContext=function(){return{versionName:this.versionName,language:E(),platform:"Web",os:void 0,deviceModel:void 0}},e}(),E=function(){return"undefined"!=typeof navigator&&(navigator.languages&&navigator.languages[0]||navigator.language)||""},R=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}(),T=function(){return T=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},T.apply(this,arguments)};function _(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 O(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 x=function(e,t){var n,r,i=typeof e;if(i!==typeof t)return!1;try{for(var o=_(["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),c=Array.isArray(t);if(a!==c)return!1;if(!a||!c){var l=Object.keys(e).sort(),u=Object.keys(t).sort();if(!x(l,u))return!1;var d=!0;return Object.keys(e).forEach(function(n){x(e[n],t[n])||(d=!1)}),d}for(var v=0;v<e.length;v++)if(!x(e[v],t[v]))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 M,L=function(){function e(){this.identity={userProperties:{}},this.listeners=new Set}return e.prototype.editIdentity=function(){var e=this,t=T({},this.identity.userProperties),n=T(T({},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,c=n.userProperties||{};try{for(var l=_(Object.entries(e)),u=l.next();!u.done;u=l.next()){var d=O(u.value,2),v=d[0],h=d[1];switch(v){case"$set":try{for(var g=(i=void 0,_(Object.entries(h))),f=g.next();!f.done;f=g.next()){var p=O(f.value,2),m=p[0],y=p[1];c[m]=y}}catch(e){i={error:e}}finally{try{f&&!f.done&&(o=g.return)&&o.call(g)}finally{if(i)throw i.error}}break;case"$unset":try{for(var b=(s=void 0,_(Object.keys(h))),S=b.next();!S.done;S=b.next()){delete c[m=S.value]}}catch(e){s={error:e}}finally{try{S&&!S.done&&(a=b.return)&&a.call(b)}finally{if(s)throw s.error}}break;case"$clearAll":c={}}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}return n.userProperties=c,this},commit:function(){return e.setIdentity(n),this}}},e.prototype.getIdentity=function(){return T({},this.identity)},e.prototype.setIdentity=function(e){var t=T({},this.identity);this.identity=T({},e),x(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}(),D="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self,F=function(){function e(){this.identityStore=new L,this.eventBridge=new R,this.applicationContextProvider=new k}return e.getInstance=function(t){return D.analyticsConnectorInstances||(D.analyticsConnectorInstances={}),D.analyticsConnectorInstances[t]||(D.analyticsConnectorInstances[t]=new e),D.analyticsConnectorInstances[t]},e}(),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},U=function(){function e(){}return e.prototype.send=function(e,t,n){return Promise.resolve(null)},e.prototype.buildResponse=function(e){var t,n,r,i,o,s,a,c,l,d,v,h,g,f,p,m,y,b,S,I,w,C;if("object"!=typeof e)return null;var P=e.code||0,k=this.buildStatus(P);switch(k){case u.Success:return{status:k,statusCode:P,body:{eventsIngested:null!==(t=e.events_ingested)&&void 0!==t?t:0,payloadSizeBytes:null!==(n=e.payload_size_bytes)&&void 0!==n?n:0,serverUploadTime:null!==(r=e.server_upload_time)&&void 0!==r?r:0}};case u.Invalid:return{status:k,statusCode:P,body:{error:null!==(i=e.error)&&void 0!==i?i:"",missingField:null!==(o=e.missing_field)&&void 0!==o?o:"",eventsWithInvalidFields:null!==(s=e.events_with_invalid_fields)&&void 0!==s?s:{},eventsWithMissingFields:null!==(a=e.events_with_missing_fields)&&void 0!==a?a:{},eventsWithInvalidIdLengths:null!==(c=e.events_with_invalid_id_lengths)&&void 0!==c?c:{},epsThreshold:null!==(l=e.eps_threshold)&&void 0!==l?l:0,exceededDailyQuotaDevices:null!==(d=e.exceeded_daily_quota_devices)&&void 0!==d?d:{},silencedDevices:null!==(v=e.silenced_devices)&&void 0!==v?v:[],silencedEvents:null!==(h=e.silenced_events)&&void 0!==h?h:[],throttledDevices:null!==(g=e.throttled_devices)&&void 0!==g?g:{},throttledEvents:null!==(f=e.throttled_events)&&void 0!==f?f:[]}};case u.PayloadTooLarge:return{status:k,statusCode:P,body:{error:null!==(p=e.error)&&void 0!==p?p:""}};case u.RateLimit:return{status:k,statusCode:P,body:{error:null!==(m=e.error)&&void 0!==m?m:"",epsThreshold:null!==(y=e.eps_threshold)&&void 0!==y?y:0,throttledDevices:null!==(b=e.throttled_devices)&&void 0!==b?b:{},throttledUsers:null!==(S=e.throttled_users)&&void 0!==S?S:{},exceededDailyQuotaDevices:null!==(I=e.exceeded_daily_quota_devices)&&void 0!==I?I:{},exceededDailyQuotaUsers:null!==(w=e.exceeded_daily_quota_users)&&void 0!==w?w:{},throttledEvents:null!==(C=e.throttled_events)&&void 0!==C?C:[]}};case u.Timeout:default:return{status:k,statusCode:P}}},e.prototype.buildStatus=function(e){return function(e){return e>=200&&e<300}(e)?u.Success:429===e?u.RateLimit:413===e?u.PayloadTooLarge:408===e?u.Timeout:e>=400&&e<500?u.Invalid:e>=500?u.Failed:u.Unknown},e}(),q=function(e){function n(t){void 0===t&&(t={});var n=e.call(this)||this;return n.customHeaders=t,n}return t(n,e),n.prototype.send=function(e,t){return o(this,void 0,void 0,function(){var n,r,o;return s(this,function(s){switch(s.label){case 0:if("undefined"==typeof fetch)throw new Error("FetchTransport is not supported");return n={headers:i({"Content-Type":"application/json",Accept:"*/*"},this.customHeaders),body:JSON.stringify(t),method:"POST"},[4,fetch(e,n)];case 1:return[4,(r=s.sent()).text()];case 2:o=s.sent();try{return[2,this.buildResponse(JSON.parse(o))]}catch(e){return[2,this.buildResponse({code:r.status})]}return[2]}})})},n}(U),A=function(){function e(e,t){this.key="AMP_remote_config_".concat(e.substring(0,10)),this.logger=t}return e.prototype.fetchConfig=function(){var e=null,t={remoteConfig:null,lastFetch:new Date};try{e=localStorage.getItem(this.key)}catch(e){return this.logger.debug("Remote config localstorage failed to access: ",e),Promise.resolve(t)}if(null===e)return this.logger.debug("Remote config localstorage gets null because the key does not exist"),Promise.resolve(t);try{var n=JSON.parse(e);return this.logger.debug("Remote config localstorage parsed successfully: ".concat(JSON.stringify(n))),Promise.resolve({remoteConfig:n.remoteConfig,lastFetch:new Date(n.lastFetch)})}catch(e){return this.logger.debug("Remote config localstorage failed to parse: ",e),localStorage.removeItem(this.key),Promise.resolve(t)}},e.prototype.setConfig=function(e){try{return localStorage.setItem(this.key,JSON.stringify(e)),this.logger.debug("Remote config localstorage set successfully."),Promise.resolve(!0)}catch(e){this.logger.debug("Remote config localstorage failed to set: ",e)}return Promise.resolve(!1)},e}(),j=401,B=403,W=429,K=function(){function e(e,t,n,r){void 0===n&&(n="US"),this.callbackInfos=[],this.lastSuccessfulFetch=null,this.fetchPromise=null,this.isLastFetchInvalidApiKey=!1,this.apiKey=e,this.serverUrl=r||("US"===n?"https://sr-client-cfg.amplitude.com/config":"https://sr-client-cfg.eu.amplitude.com/config"),this.logger=t,this.storage=new A(e,t)}return e.prototype.subscribe=function(e,t,n){var r=p(),i={id:r,key:e,deliveryMode:t,callback:n};return this.callbackInfos.push(i),"all"===t?this.subscribeAll(i):this.subscribeWaitForRemote(i,t.timeout),r},e.prototype.unsubscribe=function(e){var t=this.callbackInfos.findIndex(function(t){return t.id===e});return-1===t?(this.logger.debug("Remote config client unsubscribe failed because callback with id ".concat(e," doesn't exist.")),!1):(this.callbackInfos.splice(t,1),this.logger.debug("Remote config client unsubscribe succeeded removing callback with id ".concat(e,".")),!0)},e.prototype.updateConfigs=function(){return o(this,void 0,void 0,function(){var e,t=this;return s(this,function(n){switch(n.label){case 0:return this.lastSuccessfulFetch&&Date.now()-this.lastSuccessfulFetch<3e5?(this.logger.debug("Remote config client skipping updateConfigs: Too recent"),[2]):[4,this.getOrCreateFetchPromise()];case 1:return e=n.sent(),this.storage.setConfig(e),this.callbackInfos.forEach(function(n){t.sendCallback(n,e,"remote")}),[2]}})})},e.prototype.getOrCreateFetchPromise=function(){var e=this;return this.fetchPromise?this.fetchPromise:this.isLastFetchInvalidApiKey?(this.logger.debug("Remote config client skipping fetch: Invalid API key"),this.fetchPromise=Promise.resolve({remoteConfig:null,lastFetch:new Date}).finally(function(){e.fetchPromise=null}),this.fetchPromise):(this.fetchPromise=this.fetch().then(function(t){return null!==t.remoteConfig&&(e.lastSuccessfulFetch=Date.now()),t}).finally(function(){e.fetchPromise=null}),this.fetchPromise)},e.prototype.subscribeAll=function(e){return o(this,void 0,void 0,function(){var t,n,r,i=this;return s(this,function(o){switch(o.label){case 0:return t=this.getOrCreateFetchPromise().then(function(t){i.logger.debug("Remote config client subscription all mode fetched from remote: ".concat(JSON.stringify(t))),i.sendCallback(e,t,"remote"),i.storage.setConfig(t)}),n=this.storage.fetchConfig().then(function(e){return e}),[4,Promise.race([t,n])];case 1:return void 0!==(r=o.sent())&&(this.logger.debug("Remote config client subscription all mode fetched from cache: ".concat(JSON.stringify(r))),null!==r.remoteConfig?this.sendCallback(e,r,"cache"):this.logger.debug("Remote config client skips sending callback because cache is empty (first time user).")),[4,t];case 2:return o.sent(),[2]}})})},e.prototype.subscribeWaitForRemote=function(e,t){return o(this,void 0,void 0,function(){var n,r;return s(this,function(i){switch(i.label){case 0:n=new Promise(function(e,n){setTimeout(function(){n("Timeout exceeded")},t)}),i.label=1;case 1:return i.trys.push([1,3,,5]),[4,Promise.race([this.getOrCreateFetchPromise(),n])];case 2:return r=i.sent(),this.logger.debug("Remote config client subscription wait for remote mode returns from remote."),this.sendCallback(e,r,"remote"),this.storage.setConfig(r),[3,5];case 3:return i.sent(),this.logger.debug("Remote config client subscription wait for remote mode exceeded timeout. Try to fetch from cache."),[4,this.storage.fetchConfig()];case 4:return null!==(r=i.sent()).remoteConfig?(this.logger.debug("Remote config client subscription wait for remote mode returns a cached copy."),this.sendCallback(e,r,"cache")):(this.logger.debug("Remote config client subscription wait for remote mode failed to fetch cache."),this.sendCallback(e,r,"remote")),[3,5];case 5:return[2]}})})},e.prototype.sendCallback=function(e,t,n){var r;e.lastCallback=new Date,r=e.key?e.key.split(".").reduce(function(e,t){return null===e?e:t in e?e[t]:null},t.remoteConfig):t.remoteConfig,e.callback(r,n,t.lastFetch)},e.prototype.fetch=function(e,t){return void 0===e&&(e=3),void 0===t&&(t=1e3),o(this,void 0,void 0,function(){var n,r,i,o,a,c,l=this;return s(this,function(u){switch(u.label){case 0:n=t/e,r={remoteConfig:null,lastFetch:new Date},i=function(r){var i,a,c,u,d,v;return s(this,function(s){switch(s.label){case 0:i=!0,a=new AbortController,c=setTimeout(function(){return a.abort()},t),s.label=1;case 1:return s.trys.push([1,7,8,9]),[4,fetch(o.getUrlParams(),{method:"GET",headers:{Accept:"*/*"},signal:a.signal})];case 2:return(u=s.sent()).ok?[3,4]:[4,u.text()];case 3:return d=s.sent(),o.logger.debug("Remote config client fetch with retry time ".concat(e," failed with ").concat(u.status,": ").concat(d)),u.status===j||u.status===B?(o.logger.error("Remote config client fetch failed with ".concat(u.status,". Invalid API key; future fetches will be skipped.")),o.isLastFetchInvalidApiKey=!0,i=!1):u.status>=400&&u.status<500&&u.status!==W&&(i=!1),[3,6];case 4:return[4,u.json()];case 5:return[2,{value:{remoteConfig:s.sent(),lastFetch:new Date}}];case 6:return[3,9];case 7:return(v=s.sent())instanceof Error&&"AbortError"===v.name?o.logger.debug("Remote config client fetch with retry time ".concat(e," timed out after ").concat(t,"ms")):o.logger.debug("Remote config client fetch with retry time ".concat(e," is rejected because: "),v),[3,9];case 8:return clearTimeout(c),[7];case 9:return i?r<e-1?[4,new Promise(function(e){return setTimeout(e,l.getJitterDelay(n))})]:[3,11]:[2,"break"];case 10:s.sent(),s.label=11;case 11:return[2]}})},o=this,a=0,u.label=1;case 1:return a<e?[5,i(a)]:[3,4];case 2:if("object"==typeof(c=u.sent()))return[2,c.value];if("break"===c)return[3,4];u.label=3;case 3:return a++,[3,1];case 4:return[2,r]}})})},e.prototype.getJitterDelay=function(e){return Math.floor(Math.random()*e)},e.prototype.getUrlParams=function(){var t=encodeURIComponent(this.apiKey),n=new URLSearchParams;return n.append("config_group",e.CONFIG_GROUP),"".concat(this.serverUrl,"/").concat(t,"?").concat(n.toString())},e.CONFIG_GROUP="browser",e}();!function(e){e.US="US",e.EU="EU",e.STAGING="STAGING"}(M||(M={}));var $,H="https://app.amplitude.com",z={US:H,EU:"https://app.eu.amplitude.com",STAGING:"https://apps.stag2.amplitude.com"};var J="__AMPLITUDE_MESSENGER_INSTANCE__",G="__AMPLITUDE_MESSENGER__",V=function(){function e(e){var t=(void 0===e?{}:e).origin,n=void 0===t?H:t;this[$]=!0,this.isSetup=!1,this.messageHandler=null,this.requestCallbacks={},this.actionHandlers=new Map,this.pendingMessages=new Map,this.scriptLoadPromises=new Map,this.endpoint=n}return e.prototype.notify=function(e){var t,n,r,i;null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message sent: ",JSON.stringify(e)),null===(i=null===(r=window.opener)||void 0===r?void 0:r.postMessage)||void 0===i||i.call(r,e,this.endpoint)},e.prototype.sendRequest=function(e,t,n){var r=this;void 0===n&&(n={timeout:15e3});var i="".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),o={id:i,action:e,args:t};return new Promise(function(t,s){r.requestCallbacks[i]={resolve:t,reject:s},r.notify(o),n.timeout>0&&setTimeout(function(){s(new Error("".concat(e," timed out (id: ").concat(i,")"))),delete r.requestCallbacks[i]},n.timeout)})},e.prototype.handleResponse=function(e){var t;this.requestCallbacks[e.id]?(this.requestCallbacks[e.id].resolve(e.responseData),delete this.requestCallbacks[e.id]):null===(t=this.logger)||void 0===t||t.warn("No callback found for request id: ".concat(e.id))},e.prototype.registerActionHandler=function(e,t){var n,r,i,o;this.actionHandlers.has(e)&&(null===(o=null===(i=this.logger)||void 0===i?void 0:i.warn)||void 0===o||o.call(i,"Overwriting existing action handler for: ".concat(e))),this.actionHandlers.set(e,t);var s=this.pendingMessages.get(e);if(s){this.pendingMessages.delete(e);try{for(var c=a(s),l=c.next();!l.done;l=c.next()){t(l.value)}}catch(e){n={error:e}}finally{try{l&&!l.done&&(r=c.return)&&r.call(c)}finally{if(n)throw n.error}}}},e.prototype.loadScriptOnce=function(e){return o(this,void 0,void 0,function(){var t,n,r;return s(this,function(i){switch(i.label){case 0:if(t=this.scriptLoadPromises.get(e))return[2,t];n=function(e){return document.querySelector('script[src="'.concat(CSS.escape(e),'"]'))?Promise.resolve({status:!0}):new Promise(function(t,n){var r;try{var i=document.createElement("script");i.type="text/javascript",i.async=!0,i.src=e,i.addEventListener("load",function(){t({status:!0})},{once:!0}),i.addEventListener("error",function(){n({status:!1,message:"Failed to load the script ".concat(e)})}),null===(r=document.head)||void 0===r||r.appendChild(i)}catch(e){n(e)}})}(e).then(function(){}),this.scriptLoadPromises.set(e,n),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,n];case 2:return i.sent(),[3,4];case 3:throw r=i.sent(),this.scriptLoadPromises.delete(e),r;case 4:return[2]}})})},e.prototype.setup=function(e){var t,n,r=this,i=void 0===e?{}:e,o=i.logger,s=i.endpoint;o&&(this.logger=o),s&&this.endpoint===H&&(this.endpoint=s),this.isSetup||(this.isSetup=!0,null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Setting up messenger"),this.messageHandler=function(e){var t,n,i,o,s;if(null===(n=null===(t=r.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message received: ",JSON.stringify(e)),r.endpoint===e.origin){var a=e.data,c=null==a?void 0:a.action;if(c)if("id"in a&&a.id)null===(o=null===(i=r.logger)||void 0===i?void 0:i.debug)||void 0===o||o.call(i,"Received Response to previous request: ",JSON.stringify(e)),r.handleResponse(a);else{if("ping"===c)return void r.notify({action:"pong"});var l=r.actionHandlers.get(c);if(l)l(a.data);else{var u=null!==(s=r.pendingMessages.get(c))&&void 0!==s?s:[];u.push(a.data),r.pendingMessages.set(c,u)}}}},window.addEventListener("message",this.messageHandler),this.notify({action:"page-loaded"}))},e.prototype.destroy=function(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.isSetup=!1,this.actionHandlers.clear(),this.pendingMessages.clear(),this.requestCallbacks={},this.scriptLoadPromises.clear();var e=g();(null==e?void 0:e[G])===this&&delete e[G]},e}();function Z(e){var t,n=g(),r=null==n?void 0:n[G];if("object"==typeof(t=r)&&null!==t&&J in t&&!0===t[J])return r;var i=new V(e);return n&&(n[G]=i),i}$=J;var Q="__AMPLITUDE_BACKGROUND_CAPTURE__";var Y,X="[Amplitude]",ee="".concat(X," Session Replay ID"),te=M.US,ne={enabled:!0},re=1e3,ie="".concat(X," Session Replay Debug"),oe="amp-mask",se="https://api-sr.amplitude.com/sessions/v2/track",ae="https://api-sr.eu.amplitude.com/sessions/v2/track",ce="https://api-sr.stag2.amplitude.com/sessions/v2/track";!function(e){e.GET_SR_PROPS="get-sr-props",e.DEBUG_INFO="debug-info",e.FETCH_REQUEST="fetch-request",e.METADATA="metadata",e.TARGETING_DECISION="targeting-decision"}(Y||(Y={}));var le=function(){function e(e){this.logger=e,this.log=this.getSafeMethod("log"),this.warn=this.getSafeMethod("warn"),this.error=this.getSafeMethod("error"),this.debug=this.getSafeMethod("debug")}return e.prototype.getSafeMethod=function(e){var t;if(!this.logger)return function(){};var n=this.logger[e];return"function"==typeof n?(null!==(t=n.__rrweb_original__)&&void 0!==t?t:n).bind(this.logger):function(){}},e.prototype.enable=function(e){this.logger.enable(e)},e.prototype.disable=function(){this.logger.disable()},e}(),ue="medium";function de(e,t){return t||("STAGING"===e?ce:"EU"===e?ae:se)}var ve=function(e,t,n){switch(t){case"light":if("input"!==e)return!0;var r=n?function(e){var t=e.type;return e.hasAttribute("data-rr-is-password")?"password":t?t.toLowerCase():null}(n):"";return!!r&&(!!["password","hidden","email","tel"].includes(r)||!!n.autocomplete.startsWith("cc-"));case"medium":case"conservative":return!0;default:return ve(e,ue,n)}},he=function(e,t){var n,r,i;if(e&&t.urlMaskLevels)try{for(var o=a(t.urlMaskLevels),s=o.next();!s.done;s=o.next()){var c=s.value;if(be(c.match).test(e))return c.maskLevel}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return null!==(i=t.defaultMaskLevel)&&void 0!==i?i:ue},ge=function(e,t,n,r){var i,o;if(void 0===t&&(t={defaultMaskLevel:ue}),n){if(n.closest("."+oe))return!0;var s=(null!==(i=t.maskSelector)&&void 0!==i?i:[]).some(function(e){return n.closest(e)});if(s)return!0;if(n.closest(".amp-unmask"))return!1;var a=(null!==(o=t.unmaskSelector)&&void 0!==o?o:[]).some(function(e){return n.closest(e)});if(a)return!1}return ve(e,he(r,t),n)},fe=function(e,t,n){return function(r,i){return ge(e,t,i,null==n?void 0:n())?r.replace(/[^\s]/g,"*"):r}},pe=function(e,t){return function(n,r,i){var o;return"style"===n?r:(null!==(o=null==e?void 0:e.maskAttributes)&&void 0!==o?o:[]).includes(n)&&ge("text",e,i,null==t?void 0:t())?r.replace(/[^\s]/g,"*"):r}},me=function(){var e=g();return(null==e?void 0:e.location)?e.location.href:""},ye=new Map,be=function(e){var t=ye.get(e);if(t)return t;var n="\0TRAIL\0",r="\0MID\0",i="\0DS\0",o="\0ST\0",s="\0QU\0",a=e;a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=a.replace(/\/\*\*$/,n)).replace(/\/\*\*\//g,r)).replace(/\*\*/g,i)).replace(/\*/g,o)).replace(/\?/g,s)).replace(/[.+^${}()|[\]\\]/g,"\\$&")).split(n).join("(/.*)?")).split(r).join("/(.*\\/)?")).split(i).join(".*")).split(o).join(".*")).split(s).join(".");var c=new RegExp("^".concat(a,"$"));return ye.set(e,c),c},Se=function(e,t){var n,r;try{for(var i=a(t),o=i.next();!o.done;o=i.next()){var s=o.value,c=be(s.selector);if(c.test(e))return e.replace(c,s.replacement)}}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(){return o(void 0,void 0,void 0,function(){var e,t,n,r,i,o,a;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),(e=g())?[4,e.navigator.storage.estimate()]:[3,2];case 1:return t=s.sent(),n=t.usage,r=t.quota,i=t.usageDetails,o=n?Math.round(n/1024):0,a=n&&r?Math.round(1e3*(n/r+Number.EPSILON))/1e3:0,[2,{totalStorageSize:o,percentOfQuota:a,usageDetails:JSON.stringify(i)}];case 2:return[3,4];case 3:return s.sent(),[3,4];case 4:return[2,{totalStorageSize:0,percentOfQuota:0,usageDetails:""}]}})})},we=function(e){var t=i({},e),n=t.apiKey;return t.apiKey="****".concat(n.substring(n.length-4)),t},Ce=function(){return{flushMaxRetries:2,logLevel:h.Warn,loggerProvider:new b,transportProvider:new q}},Pe=function(e){function n(t,n){var r,o,s,a,c,l,u,d=this,v=Ce();if((d=e.call(this,i(i({transportProvider:v.transportProvider,loggerProvider:new le(n.loggerProvider||v.loggerProvider)},n),{apiKey:t}))||this).flushMaxRetries=void 0!==n.flushMaxRetries&&n.flushMaxRetries<=v.flushMaxRetries?n.flushMaxRetries:v.flushMaxRetries,d.apiKey=t,d.sampleRate=n.sampleRate||0,d.serverZone=n.serverZone||te,d.configServerUrl=n.configServerUrl,d.trackServerUrl=n.trackServerUrl,d.shouldInlineStylesheet=n.shouldInlineStylesheet,d.version=n.version,d.performanceConfig=n.performanceConfig||ne,d.storeType=null!==(r=n.storeType)&&void 0!==r?r:"idb",d.applyBackgroundColorToBlockedElements=null!==(o=n.applyBackgroundColorToBlockedElements)&&void 0!==o&&o,d.enableUrlChangePolling=null!==(s=n.enableUrlChangePolling)&&void 0!==s&&s,d.urlChangePollingInterval=null!==(a=n.urlChangePollingInterval)&&void 0!==a?a:re,d.captureDocumentTitle=null!==(c=n.captureDocumentTitle)&&void 0!==c&&c,n.privacyConfig&&(d.privacyConfig=n.privacyConfig),n.interactionConfig&&(d.interactionConfig=n.interactionConfig,d.interactionConfig.ugcFilterRules&&function(e){if(!e.every(function(e){return"string"==typeof e.selector&&"string"==typeof e.replacement}))throw new Error("ugcFilterRules must be an array of objects with selector and replacement properties");if(!e.every(function(e){return"string"==typeof(t=e.selector)&&""!==t.trim()&&!!/^\/|^https?:\/\/[^\s]+$/.test(t);var t}))throw new Error("ugcFilterRules must be an array of objects with valid globs")}(d.interactionConfig.ugcFilterRules)),n.debugMode&&(d.debugMode=n.debugMode),void 0!==n.useWebWorker)d.useWebWorker=n.useWebWorker;else{var h=n;void 0!==(null===(l=h.experimental)||void 0===l?void 0:l.useWebWorker)&&(d.useWebWorker=h.experimental.useWebWorker)}return n.omitElementTags&&(d.omitElementTags=n.omitElementTags),d.captureAdoptedStyleSheets=null===(u=n.captureAdoptedStyleSheets)||void 0===u||u,d}return t(n,e),n}(I),ke=(e=>(e[e.DomContentLoaded=0]="DomContentLoaded",e[e.Load=1]="Load",e[e.FullSnapshot=2]="FullSnapshot",e[e.IncrementalSnapshot=3]="IncrementalSnapshot",e[e.Meta=4]="Meta",e[e.Custom=5]="Custom",e[e.Plugin=6]="Plugin",e))(ke||{}),Ee=(e=>(e[e.MouseUp=0]="MouseUp",e[e.MouseDown=1]="MouseDown",e[e.Click=2]="Click",e[e.ContextMenu=3]="ContextMenu",e[e.DblClick=4]="DblClick",e[e.Focus=5]="Focus",e[e.Blur=6]="Blur",e[e.TouchStart=7]="TouchStart",e[e.TouchMove_Departed=8]="TouchMove_Departed",e[e.TouchEnd=9]="TouchEnd",e[e.TouchCancel=10]="TouchCancel",e))(Ee||{}),Re=function(){function e(e,t){this.localConfig=t,this.remoteConfigClient=e}return e.prototype.generateJoinedConfig=function(){var e,t,n,r,u,d,v;return o(this,void 0,void 0,function(){var o,h,g,f,p,m,y,b,S,I,w,C,P,k,E,R,T,_=this;return s(this,function(s){switch(s.label){case 0:(o=i({},this.localConfig)).optOut=this.localConfig.optOut,o.captureEnabled=!0,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,new Promise(function(e,t){_.remoteConfigClient.subscribe("configs.sessionReplay","all",function(n,r){var i;if(_.localConfig.loggerProvider.debug("Session Replay remote configuration received from ".concat(r,":"),JSON.stringify(n,null,2)),n){var s=n,a=s.sr_sampling_config,c=s.sr_privacy_config,l=s.sr_targeting_config,u=null===(i=o.interactionConfig)||void 0===i?void 0:i.ugcFilterRules;o.interactionConfig=s.sr_interaction_config,o.interactionConfig&&u&&(o.interactionConfig.ugcFilterRules=u),o.loggingConfig=s.sr_logging_config,(a||c||l)&&(h={},a&&(h.sr_sampling_config=a),c&&(h.sr_privacy_config=c),l&&(h.sr_targeting_config=l)),e()}else t(new Error("No remote config received"))})})];case 2:return s.sent(),[3,4];case 3:return g=s.sent(),this.localConfig.loggerProvider.error("Failed to generate joined config: ",g),o.captureEnabled=!1,[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:void 0}];case 4:if(!h)return[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:h}];if(f=h.sr_sampling_config,p=h.sr_privacy_config,m=h.sr_targeting_config,f&&Object.keys(f).length>0?(Object.prototype.hasOwnProperty.call(f,"capture_enabled")?o.captureEnabled=f.capture_enabled:o.captureEnabled=!1,Object.prototype.hasOwnProperty.call(f,"sample_rate")&&(o.sampleRate=f.sample_rate)):(o.captureEnabled=!0,this.localConfig.loggerProvider.debug("Remote config successfully fetched, but no values set for project, Session Replay capture enabled.")),p){y=null!==(e=o.privacyConfig)&&void 0!==e?e:{},b={defaultMaskLevel:null!==(n=null!==(t=p.defaultMaskLevel)&&void 0!==t?t:y.defaultMaskLevel)&&void 0!==n?n:"medium",blockSelector:[],maskSelector:[],unmaskSelector:[],maskAttributes:l([],c(new Set(l(l([],c(null!==(r=y.maskAttributes)&&void 0!==r?r:[]),!1),c(null!==(u=p.maskAttributes)&&void 0!==u?u:[]),!1))),!1),urlMaskLevels:l(l([],c(null!==(d=p.urlMaskLevels)&&void 0!==d?d:[]),!1),c(null!==(v=y.urlMaskLevels)&&void 0!==v?v:[]),!1)},S=function(e){var t,n,r,i,o,s,c,l,u,d={};"string"==typeof e.blockSelector&&(e.blockSelector=[e.blockSelector]);try{for(var v=a(null!==(c=e.blockSelector)&&void 0!==c?c:[]),h=v.next();!h.done;h=v.next()){d[h.value]="block"}}catch(e){t={error:e}}finally{try{h&&!h.done&&(n=v.return)&&n.call(v)}finally{if(t)throw t.error}}try{for(var g=a(null!==(l=e.maskSelector)&&void 0!==l?l:[]),f=g.next();!f.done;f=g.next()){d[f.value]="mask"}}catch(e){r={error:e}}finally{try{f&&!f.done&&(i=g.return)&&i.call(g)}finally{if(r)throw r.error}}try{for(var p=a(null!==(u=e.unmaskSelector)&&void 0!==u?u:[]),m=p.next();!m.done;m=p.next()){d[m.value]="unmask"}}catch(e){o={error:e}}finally{try{m&&!m.done&&(s=p.return)&&s.call(p)}finally{if(o)throw o.error}}return d},I=i(i({},S(y)),S(p));try{for(w=a(Object.entries(I)),C=w.next();!C.done;C=w.next())P=c(C.value,2),k=P[0],"mask"===(E=P[1])?b.maskSelector.push(k):"block"===E?b.blockSelector.push(k):"unmask"===E&&b.unmaskSelector.push(k)}catch(e){R={error:e}}finally{try{C&&!C.done&&(T=w.return)&&T.call(w)}finally{if(R)throw R.error}}o.privacyConfig=(O=b,x=this.localConfig.loggerProvider,M=document.createDocumentFragment(),L=function(e){if(void 0===e&&(e=[]),"string"==typeof e&&(e=[e]),e=e.filter(function(e){try{M.querySelector(e)}catch(t){return x.warn('[session-replay-browser] omitting selector "'.concat(e,'" because it is invalid')),!1}return!0}),0!==e.length)return e},O.blockSelector=L(O.blockSelector),O.maskSelector=L(O.maskSelector),O.unmaskSelector=L(O.unmaskSelector),O)}return m&&Object.keys(m).length>0&&(o.targetingConfig=m),this.localConfig.loggerProvider.debug(JSON.stringify({name:"session replay joined config",config:we(o)},null,2)),[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:h}]}var O,x,M,L})})},e}(),Te=function(e,t){return o(void 0,void 0,void 0,function(){var n,r;return s(this,function(i){return n=new Pe(e,t),r=new K(e,n.loggerProvider,n.serverZone,t.configServerUrl),[2,new Re(r,n)]})})},_e=function(){function e(e,t,n,r,i){var o,s=this;this.taskQueue=[],this.isProcessing=!1,this.compressEvent=function(e){var t=e,n=t.type,r=t.timestamp,i=t.delay,o=t.data;return null!=i?JSON.stringify({type:n,timestamp:r,delay:i,data:o}):JSON.stringify({type:n,timestamp:r,data:o})},this.addCompressedEventToManager=function(e,t){s.eventsManager&&s.deviceId&&s.eventsManager.addEvent({event:{type:"replay",data:e},sessionId:t,deviceId:s.deviceId})},this.addCompressedEvent=function(e,t){if(s.worker)try{s.worker.postMessage({event:e,sessionId:t})}catch(n){"DataCloneError"===n.name?s.worker.postMessage(JSON.stringify({event:e,sessionId:t})):s.config.loggerProvider.warn("Unexpected error while posting message to worker:",n)}else{var n=s.compressEvent(e);s.addCompressedEventToManager(n,t)}},this.terminate=function(){var e;null===(e=s.worker)||void 0===e||e.terminate()};var a=g();if(this.canUseIdleCallback=a&&"requestIdleCallback"in a,this.eventsManager=e,this.config=t,this.deviceId=n,this.timeout=(null===(o=t.performanceConfig)||void 0===o?void 0:o.timeout)||2e3,this.onFullSnapshotProcessed=i,r){t.loggerProvider.log("Enabling web worker for compression");try{var c=new Blob([r],{type:"application/javascript"}),l=URL.createObjectURL(c),u=new Worker(l);u.onerror=function(e){e.preventDefault(),t.loggerProvider.error("Worker failed, falling back to non-worker compression: ".concat(e.message," (").concat(e.filename,":").concat(e.lineno,")")),u.terminate(),s.worker=void 0},u.onmessage=function(e){var t=e.data,n=t.compressedEvent,r=t.sessionId;s.addCompressedEventToManager(n,r)},this.worker=u}catch(e){t.loggerProvider.error("Failed to create worker, falling back to non-worker compression:",e)}}}return e.prototype.scheduleIdleProcessing=function(){var e=this;this.isProcessing||(this.isProcessing=!0,requestIdleCallback(function(t){e.processQueue(t)},{timeout:this.timeout}))},e.prototype.enqueueEvent=function(e,t){var n,r,i,o;if(e.type===ke.FullSnapshot){if(this.config.loggerProvider.debug("Processing full snapshot immediately."),this.taskQueue.length>0){try{for(var s=a(this.taskQueue.splice(0)),c=s.next();!c.done;c=s.next()){var l=c.value,u=this.compressEvent(l.event);this.addCompressedEventToManager(u,l.sessionId)}}catch(e){n={error:e}}finally{try{c&&!c.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}this.isProcessing=!1}var d=this.compressEvent(e);return this.addCompressedEventToManager(d,t),void(null===(i=this.onFullSnapshotProcessed)||void 0===i||i.call(this))}this.canUseIdleCallback&&(null===(o=this.config.performanceConfig)||void 0===o?void 0:o.enabled)?(this.config.loggerProvider.debug("Enqueuing event for processing during idle time."),this.taskQueue.push({event:e,sessionId:t}),this.scheduleIdleProcessing()):(this.config.loggerProvider.debug("Processing event without idle callback."),this.addCompressedEvent(e,t))},e.prototype.processQueue=function(e){for(var t=this;this.taskQueue.length>0&&(e.timeRemaining()>0||e.didTimeout);){var n=this.taskQueue.shift();if(n){var r=n.event,i=n.sessionId;this.addCompressedEvent(r,i)}}this.taskQueue.length>0?requestIdleCallback(function(e){t.processQueue(e)},{timeout:this.timeout}):this.isProcessing=!1},e}(),Oe="Session replay event batch rejected due to exceeded retry count",xe="Failed to store session replay events in IndexedDB",Me="1.38.0";function Le(e,t){return o(this,void 0,void 0,function(){var n,r,i,c,l,u,d,v,h,g,f,p,m,y,b=this;return s(this,function(S){switch(S.label){case 0:return S.trys.push([0,4,,5]),n=t.CompressionStream,r=new n("gzip"),i=r.writable.getWriter(),c=r.readable.getReader(),l=[],u=o(b,void 0,void 0,function(){var e,t,n;return s(this,function(r){switch(r.label){case 0:return[4,c.read()];case 1:if(e=r.sent(),t=e.done,n=e.value,t)return[3,3];l.push(n),r.label=2;case 2:return[3,0];case 3:return[2]}})}),[4,i.write((new TextEncoder).encode(e))];case 1:return S.sent(),[4,i.close()];case 2:return S.sent(),[4,u];case 3:S.sent(),d=l.reduce(function(e,t){return e+t.length},0),v=new Uint8Array(d),h=0;try{for(g=a(l),f=g.next();!f.done;f=g.next())p=f.value,v.set(p,h),h+=p.length}catch(e){m={error:e}}finally{try{f&&!f.done&&(y=g.return)&&y.call(g)}finally{if(m)throw m.error}}return[2,v];case 4:return S.sent(),[2,null];case 5:return[2]}})})}var De=function(){function e(e){var t=e.trackServerUrl,n=e.loggerProvider,r=e.payloadBatcher,i=e.workerScript,o=this;if(this.storageKey="",this.retryTimeout=1e3,this.scheduled=null,this.queue=[],this.sendIdCounter=0,this.pendingWorkerRequests=new Map,this.loggerProvider=n,this.payloadBatcher=r||function(e){return e},this.trackServerUrl=t,i)try{var s=new Blob([i],{type:"application/javascript"}),l=URL.createObjectURL(s),u=new Worker(l);u.onerror=function(e){var t,r;e.preventDefault(),n.error("Track destination worker failed, falling back to main-thread sending: ".concat(e.message," (").concat(e.filename,":").concat(e.lineno,")")),u.terminate(),o.worker=void 0;try{for(var i=a(o.pendingWorkerRequests),s=i.next();!s.done;s=i.next()){var l=c(s.value,2)[1];n.warn("Session replay event send failed due to worker crash: ".concat(e.message)),l.resolve()}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}o.pendingWorkerRequests.clear()},u.onmessage=function(e){var t=e.data;if("log"===t.type)n.log(t.message);else if("warn"===t.type)n.warn(t.message);else if("complete"===t.type){var r=o.pendingWorkerRequests.get(t.id);r&&(o.completeRequest({context:r.context}),r.resolve(),o.pendingWorkerRequests.delete(t.id))}},this.worker=u}catch(e){n.error("Failed to create track destination worker, falling back to main-thread sending:",e)}}return e.prototype.sendEventsList=function(e){this.addToQueue(i(i({},e),{attempts:0,timeout:0}))},e.prototype.sendBeacon=function(e){var t,n,r=e.events,i=e.sessionId,o=e.deviceId,s=e.apiKey,a=e.serverZone,c=function(e){return new Blob([e]).size},l=r,u=JSON.stringify({version:2,events:l});if(c(u)>65536){for(var d=0,v=l.length;d<v;){var h=Math.floor((d+v+1)/2);c(JSON.stringify({version:2,events:l.slice(0,h)}))<=65536?d=h:v=h-1}l=l.slice(0,d),u=JSON.stringify({version:2,events:l}),this.loggerProvider.warn("sendBeacon payload exceeded 64 KB limit, trimmed from ".concat(r.length," to ").concat(l.length," events"))}if(0!==l.length){var f=new URLSearchParams({device_id:o,session_id:String(i),type:"replay",api_key:s}),p="".concat(de(a,this.trackServerUrl),"?").concat(f.toString()),m=g();try{var y=new Blob([u],{type:"application/json"});!1===(null===(n=null===(t=null==m?void 0:m.navigator)||void 0===t?void 0:t.sendBeacon)||void 0===n?void 0:n.call(t,p,y))&&this.loggerProvider.warn("sendBeacon failed to queue session replay payload")}catch(e){}}},e.prototype.addToQueue=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];t.filter(function(t){return t.attempts<(t.flushMaxRetries||0)?(t.attempts+=1,!0):(e.completeRequest({context:t,err:Oe}),!1)}).forEach(function(t){e.queue=e.queue.concat(t),e.schedule(0)})},e.prototype.schedule=function(e){var t=this;this.scheduled||(this.scheduled=setTimeout(function(){t.flush(!0).then(function(){t.queue.length>0&&t.schedule(e)})},e))},e.prototype.flush=function(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var t,n,r,i,o,c,l;return s(this,function(s){switch(s.label){case 0:t=this.queue,this.queue=[],this.scheduled&&(clearTimeout(this.scheduled),this.scheduled=null),s.label=1;case 1:s.trys.push([1,6,7,8]),n=a(t),r=n.next(),s.label=2;case 2:return r.done?[3,5]:(i=r.value,[4,this.send(i,e)]);case 3:s.sent(),s.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=s.sent(),c={error:o},[3,8];case 7:try{r&&!r.done&&(l=n.return)&&l.call(n)}finally{if(c)throw c.error}return[7];case 8:return[2]}})})},e.prototype.send=function(e,t){return void 0===t&&(t=!0),o(this,void 0,void 0,function(){var n,r,i,o;return s(this,function(s){return(n=e.apiKey)?(r=e.deviceId)?0===(i=this.payloadBatcher({version:1,events:e.events})).events.length?(this.completeRequest({context:e}),[2]):(o=this.worker)?[2,this.sendViaWorker(o,e,i,t)]:[2,this.sendOnMainThread(n,r,e,i,t)]:[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing device ID"})]:[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing api key"})]})})},e.prototype.sendViaWorker=function(e,t,n,r){return o(this,void 0,void 0,function(){var i,o=this;return s(this,function(s){return i="".concat(++this.sendIdCounter),[2,new Promise(function(s){var a;o.pendingWorkerRequests.set(i,{context:t,resolve:s}),e.postMessage({type:"send",id:i,payload:n,useRetry:r,context:{apiKey:t.apiKey,deviceId:t.deviceId,sessionId:t.sessionId,events:t.events,eventType:t.type,flushMaxRetries:null!==(a=t.flushMaxRetries)&&void 0!==a?a:0,sampleRate:t.sampleRate,serverZone:t.serverZone,trackServerUrl:o.trackServerUrl,version:t.version,currentUrl:me(),sdkVersion:Me}})})]})})},e.prototype.sendOnMainThread=function(e,t,n,r,a){var c,l,u,d;return o(this,void 0,void 0,function(){var o,v,h,f,p,m,y,b,S,I,w,C,P,k;return s(this,function(s){switch(s.label){case 0:o=me(),v=Me,h=n.sampleRate,f=new URLSearchParams({device_id:t,session_id:"".concat(n.sessionId),type:"".concat(n.type)}),p="".concat(null!==(l=null===(c=n.version)||void 0===c?void 0:c.type)&&void 0!==l?l:"standalone","/").concat(null!==(d=null===(u=n.version)||void 0===u?void 0:u.version)&&void 0!==d?d:v),s.label=1;case 1:return s.trys.push([1,9,,10]),m=JSON.stringify(r),(y=g())&&"CompressionStream"in y?[4,Le(m,y)]:[3,3];case 2:return S=s.sent(),[3,4];case 3:S=null,s.label=4;case 4:return b=S,I={headers:i({"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(e),"X-Client-Version":v,"X-Client-Library":p,"X-Client-Url":o.substring(0,1e3),"X-Client-Sample-Rate":"".concat(h),"X-Sampling-Hash-Alg":"xxhash32"},b?{"Content-Encoding":"gzip"}:{}),body:null!=b?b:m,method:"POST"},w="".concat(de(n.serverZone,this.trackServerUrl),"?").concat(f.toString()),[4,fetch(w,I)];case 5:if(null===(C=s.sent()))return this.completeRequest({context:n,err:"Unexpected error occurred"}),[2];if(a)return[3,6];P="";try{P=JSON.stringify(C.body,null,2)}catch(e){}return this.completeRequest({context:n,success:"".concat(C.status,": ").concat(P)}),[3,8];case 6:return[4,this.handleReponse(C.status,n)];case 7:s.sent(),s.label=8;case 8:return[3,10];case 9:return k=s.sent(),this.completeRequest({context:n,err:k}),[3,10];case 10:return[2]}})})},e.prototype.handleReponse=function(e,t){return o(this,void 0,void 0,function(){var n;return s(this,function(r){switch(r.label){case 0:switch(n=(new U).buildStatus(e),n){case u.Success:return[3,1];case u.Failed:case u.Timeout:case u.RateLimit:return[3,2]}return[3,4];case 1:return this.handleSuccessResponse(t),[3,7];case 2:return[4,this.handleOtherResponse(t)];case 3:return r.sent(),[3,7];case 4:return 499!==e?[3,6]:[4,this.handleOtherResponse(t)];case 5:return r.sent(),[3,7];case 6:this.completeRequest({context:t,err:"Network error occurred, event batch rejected"}),r.label=7;case 7:return[2]}})})},e.prototype.handleSuccessResponse=function(e){var t=Math.round(new Blob(e.events).size/1024);this.completeRequest({context:e,success:"Session replay event batch tracked successfully for session id ".concat(e.sessionId,", size of events: ").concat(t," KB")})},e.prototype.handleOtherResponse=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=Math.random()*e.attempts*this.retryTimeout,e.attempts++,e.attempts>(e.flushMaxRetries||0)?(this.completeRequest({context:e,err:Oe}),[2]):[4,new Promise(function(e){return setTimeout(e,t)})];case 1:return n.sent(),[4,this.send(e,!0)];case 2:return n.sent(),[2]}})})},e.prototype.completeRequest=function(e){var t=e.context,n=e.err,r=e.success;t.onComplete(),n?this.loggerProvider.warn(n):r&&this.loggerProvider.log(r)},e}();const Fe=(e,t)=>t.some(t=>e instanceof t);let Ne,Ue;const qe=new WeakMap,Ae=new WeakMap,je=new WeakMap;let Be={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return qe.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return He(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function We(e){Be=e(Be)}function Ke(e){return(Ue||(Ue=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(ze(this),t),He(this.request)}:function(...t){return He(e.apply(ze(this),t))}}function $e(e){return"function"==typeof e?Ke(e):(e instanceof IDBTransaction&&function(e){if(qe.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",i),e.removeEventListener("error",o),e.removeEventListener("abort",o)},i=()=>{t(),r()},o=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",i),e.addEventListener("error",o),e.addEventListener("abort",o)});qe.set(e,t)}(e),Fe(e,Ne||(Ne=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,Be):e)}function He(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",i),e.removeEventListener("error",o)},i=()=>{t(He(e.result)),r()},o=()=>{n(e.error),r()};e.addEventListener("success",i),e.addEventListener("error",o)});return je.set(t,e),t}(e);if(Ae.has(e))return Ae.get(e);const t=$e(e);return t!==e&&(Ae.set(e,t),je.set(t,e)),t}const ze=e=>je.get(e);function Je(e,t,{blocked:n,upgrade:r,blocking:i,terminated:o}={}){const s=indexedDB.open(e,t),a=He(s);return r&&s.addEventListener("upgradeneeded",e=>{r(He(s.result),e.oldVersion,e.newVersion,He(s.transaction),e)}),n&&s.addEventListener("blocked",e=>n(e.oldVersion,e.newVersion,e)),a.then(e=>{o&&e.addEventListener("close",()=>o()),i&&e.addEventListener("versionchange",e=>i(e.oldVersion,e.newVersion,e))}).catch(()=>{}),a}const Ge=["get","getKey","getAll","getAllKeys","count"],Ve=["put","add","delete","clear"],Ze=new Map;function Qe(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(Ze.get(t))return Ze.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,i=Ve.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!i&&!Ge.includes(n))return;const o=async function(e,...t){const o=this.transaction(e,i?"readwrite":"readonly");let s=o.store;return r&&(s=s.index(t.shift())),(await Promise.all([s[n](...t),i&&o.done]))[0]};return Ze.set(t,o),o}We(e=>({...e,get:(t,n,r)=>Qe(t,n)||e.get(t,n,r),has:(t,n)=>!!Qe(t,n)||e.has(t,n)}));const Ye=["continue","continuePrimaryKey","advance"],Xe={},et=new WeakMap,tt=new WeakMap,nt={get(e,t){if(!Ye.includes(t))return e[t];let n=Xe[t];return n||(n=Xe[t]=function(...e){et.set(this,tt.get(this)[t](...e))}),n}};async function*rt(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,nt);for(tt.set(n,t),je.set(n,ze(t));t;)yield n,t=await(et.get(n)||t.continue()),et.delete(n)}function it(e,t){return t===Symbol.asyncIterator&&Fe(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&Fe(e,[IDBIndex,IDBObjectStore])}We(e=>({...e,get:(t,n,r)=>it(t,n)?rt:e.get(t,n,r),has:(t,n)=>it(t,n)||e.has(t,n)}));var ot,st,at,ct=function(){function e(e){var t,n,r,i=this;this.minInterval=500,this.maxInterval=1e4,this.maxPersistedEventsSize=1e6,this.interval=this.minInterval,this._timeAtLastSplit=Date.now(),this.shouldSplitEventsList=function(e,t){var n=i.getStringSize(t);return i.getEventsArraySize(e)+n>=i.maxPersistedEventsSize||!!(Date.now()-i.timeAtLastSplit>i.interval&&e.length)&&(i.interval=Math.min(i.maxInterval,i.interval+i.minInterval),i._timeAtLastSplit=Date.now(),!0)},this.loggerProvider=e.loggerProvider,this.minInterval=null!==(t=e.minInterval)&&void 0!==t?t:this.minInterval,this.maxInterval=null!==(n=e.maxInterval)&&void 0!==n?n:this.maxInterval,this.maxPersistedEventsSize=null!==(r=e.maxPersistedEventsSize)&&void 0!==r?r:this.maxPersistedEventsSize}return Object.defineProperty(e.prototype,"timeAtLastSplit",{get:function(){return this._timeAtLastSplit},enumerable:!1,configurable:!0}),e.prototype.getStringSize=function(e){return e.length},e.prototype.getEventsArraySize=function(e){var t,n,r=0;try{for(var i=a(e),o=i.next();!o.done;o=i.next()){var s=o.value;r+=this.getStringSize(s)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return r+(2+Math.max(0,e.length-1)+2*e.length)},e}(),lt=function(e,t,n){var r;"object"==typeof(r=n)&&null!==r&&"AbortError"===r.name?e.debug(t):e.warn(t)},ut="sessionCurrentSequence",dt="sequencesToSend",vt=function(e){var t,n;return e.objectStoreNames.contains(ut)||(n=e.createObjectStore(ut,{keyPath:"sessionId"})),e.objectStoreNames.contains(dt)||(t=e.createObjectStore(dt,{keyPath:"sequenceId",autoIncrement:!0})).createIndex("sessionId","sessionId"),{sequencesStore:t,currentSequenceStore:n}},ht=function(e){return o(void 0,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,Je(e,1,{upgrade:vt})];case 1:return[2,t.sent()]}})})},gt=function(e){function n(t){var n,r=this;return(r=e.call(this,t)||this).consecutiveFailures=0,r.hasTriggeredFallback=!1,r.getSequencesToSend=function(){return o(r,void 0,void 0,function(){var e,t,n,r,i,o,a,c,l=this;return s(this,function(s){switch(s.label){case 0:e=!1,s.label=1;case 1:return s.trys.push([1,6,,7]),t=[],(n=this.db.transaction("sequencesToSend")).done.catch(function(t){e||lt(l.loggerProvider,"".concat(xe,": ").concat(t),t)}),[4,n.store.openCursor()];case 2:r=s.sent(),s.label=3;case 3:return r?(i=r.value,o=i.sessionId,a=i.events,t.push({events:a,sequenceId:r.key,sessionId:o}),[4,r.continue()]):[3,5];case 4:return r=s.sent(),[3,3];case 5:return this.recordSuccess(),[2,t];case 6:return c=s.sent(),e=!0,lt(this.loggerProvider,"".concat(xe,": ").concat(c),c),this.recordFailure(),[3,7];case 7:return[2,void 0]}})})},r.storeCurrentSequence=function(e){return o(r,void 0,void 0,function(){var t,n,r;return s(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,this.db.get(ut,e)];case 1:return(t=o.sent())?[4,this.db.put(dt,{sessionId:e,events:t.events})]:(this.recordSuccess(),[2,void 0]);case 2:return n=o.sent(),[4,this.db.put(ut,{sessionId:e,events:[]})];case 3:return o.sent(),this.recordSuccess(),[2,i(i({},t),{sessionId:e,sequenceId:n})];case 4:return r=o.sent(),lt(this.loggerProvider,"".concat(xe,": ").concat(r),r),this.recordFailure(),[3,5];case 5:return[2,void 0]}})})},r.addEventToCurrentSequence=function(e,t){return o(r,void 0,void 0,function(){var n,r,i,o,a,c,l=this;return s(this,function(s){switch(s.label){case 0:n=!1,s.label=1;case 1:return s.trys.push([1,9,,10]),(r=this.db.transaction([ut,dt],"readwrite")).done.catch(function(e){n||lt(l.loggerProvider,"".concat(xe,": ").concat(e),e)}),[4,r.objectStore(ut).get(e)];case 2:return(i=s.sent())?[3,4]:[4,r.objectStore(ut).put({sessionId:e,events:[t]})];case 3:return s.sent(),this.recordSuccess(),[2,void 0];case 4:return this.shouldSplitEventsList(i.events,t)?[3,6]:[4,r.objectStore(ut).put({sessionId:e,events:i.events.concat(t)})];case 5:return s.sent(),this.recordSuccess(),[2,void 0];case 6:return o=i.events,[4,r.objectStore(ut).put({sessionId:e,events:[t]})];case 7:return s.sent(),[4,r.objectStore(dt).put({sessionId:e,events:o})];case 8:return a=s.sent(),this.recordSuccess(),[2,{events:o,sessionId:e,sequenceId:a}];case 9:return c=s.sent(),n=!0,lt(this.loggerProvider,"".concat(xe,": ").concat(c),c),this.recordFailure(),[3,10];case 10:return[2,void 0]}})})},r.storeSendingEvents=function(e,t){return o(r,void 0,void 0,function(){var n,r;return s(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.db.put(dt,{sessionId:e,events:t})];case 1:return n=i.sent(),this.recordSuccess(),[2,n];case 2:return r=i.sent(),lt(this.loggerProvider,"".concat(xe,": ").concat(r),r),this.recordFailure(),[3,3];case 3:return[2,void 0]}})})},r.cleanUpSessionEventsStore=function(e,t){return o(r,void 0,void 0,function(){var e;return s(this,function(n){switch(n.label){case 0:if(!t)return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.db.delete(dt,t)];case 2:return n.sent(),this.recordSuccess(),[3,4];case 3:return e=n.sent(),lt(this.loggerProvider,"".concat(xe,": ").concat(e),e),this.recordFailure(),[3,4];case 4:return[2]}})})},r.db=t.db,r.onPersistentFailure=t.onPersistentFailure,r.consecutiveFailureThreshold=null!==(n=t.consecutiveFailureThreshold)&&void 0!==n?n:3,r}return t(n,e),n.prototype.recordFailure=function(){var e;this.consecutiveFailures++,!this.hasTriggeredFallback&&this.consecutiveFailures>=this.consecutiveFailureThreshold&&(this.hasTriggeredFallback=!0,null===(e=this.onPersistentFailure)||void 0===e||e.call(this))},n.prototype.recordSuccess=function(){this.consecutiveFailures=0},n.new=function(e,t){return o(this,void 0,void 0,function(){var r,o,a,c;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),r="replay"===e?"":"_".concat(e),o="".concat(t.apiKey.substring(0,10),"_amp_session_replay_events").concat(r),[4,ht(o)];case 1:return a=s.sent(),[2,new n(i(i({},t),{db:a}))];case 2:return c=s.sent(),lt(t.loggerProvider,"".concat(xe,": ").concat(c),c),[3,3];case 3:return[2]}})})},n.prototype.getCurrentSequenceEvents=function(e){return o(this,void 0,void 0,function(){var t,n,r,i,o,c,l;return s(this,function(s){switch(s.label){case 0:return e?[4,this.db.get("sessionCurrentSequence",e)]:[3,2];case 1:return(i=s.sent())?[2,[i]]:[2,void 0];case 2:t=[],s.label=3;case 3:return s.trys.push([3,8,9,10]),[4,this.db.getAll("sessionCurrentSequence")];case 4:n=a.apply(void 0,[s.sent()]),r=n.next(),s.label=5;case 5:if(r.done)return[3,7];i=r.value,t.push(i),s.label=6;case 6:return r=n.next(),[3,5];case 7:return[3,10];case 8:return o=s.sent(),c={error:o},[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[2,t]}})})},n}(ct),ft=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.finalizedSequences={},t.sequences={},t.sequenceId=0,t}return t(n,e),n.prototype.resetCurrentSequence=function(e){this.sequences[e]=[]},n.prototype.addSequence=function(e){var t=this.sequenceId++,n=l([],c(this.sequences[e]),!1);return this.finalizedSequences[t]={sessionId:e,events:n},this.resetCurrentSequence(e),{sequenceId:t,events:n,sessionId:e}},n.prototype.getSequencesToSend=function(){return o(this,void 0,void 0,function(){return s(this,function(e){return[2,Object.entries(this.finalizedSequences).map(function(e){var t=c(e,2),n=t[0],r=t[1],i=r.sessionId,o=r.events;return{sequenceId:Number(n),sessionId:i,events:o}})]})})},n.prototype.storeCurrentSequence=function(e){return o(this,void 0,void 0,function(){return s(this,function(t){return this.sequences[e]?[2,this.addSequence(e)]:[2,void 0]})})},n.prototype.addEventToCurrentSequence=function(e,t){return o(this,void 0,void 0,function(){var n;return s(this,function(r){return this.sequences[e]||this.resetCurrentSequence(e),this.shouldSplitEventsList(this.sequences[e],t)&&(n=this.addSequence(e)),this.sequences[e].push(t),[2,n]})})},n.prototype.storeSendingEvents=function(e,t){return o(this,void 0,void 0,function(){return s(this,function(n){return this.finalizedSequences[this.sequenceId]={sessionId:e,events:t},[2,this.sequenceId++]})})},n.prototype.cleanUpSessionEventsStore=function(e,t){return o(this,void 0,void 0,function(){return s(this,function(e){return void 0!==t&&delete this.finalizedSequences[t],[2]})})},n}(ct),pt=function(e){var t=e.config,n=e.minInterval,r=e.maxInterval,a=e.type,u=e.payloadBatcher,d=e.storeType,v=e.trackDestinationWorkerScript;return o(void 0,void 0,void 0,function(){function e(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){return s(this,function(t){return[2,h.flush(e)]})})}var h,g,f,p,m,y,b,S,I,w,C,P,k,E,R;return s(this,function(T){switch(T.label){case 0:return h=new De(i(i({},t),{loggerProvider:t.loggerProvider,payloadBatcher:u,workerScript:v})),g=function(){return new ft({loggerProvider:t.loggerProvider,maxInterval:r,minInterval:n})},p=!1,y=function(){return o(void 0,void 0,void 0,function(){var e,n,r;return s(this,function(i){switch(i.label){case 0:return p?(p=!1,t.loggerProvider.warn("IDB store is experiencing repeated failures; falling back to in-memory event store."),f?[4,m.getSequencesToSend()]:[3,2]):[2];case 1:return n=i.sent(),[3,3];case 2:n=void 0,i.label=3;case 3:return e=n,m=g(),e&&f&&(r=f,e.forEach(function(e){P({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:r})})),[2]}})})},b=function(){return o(void 0,void 0,void 0,function(){var e;return s(this,function(i){switch(i.label){case 0:return[4,gt.new(a,{loggerProvider:t.loggerProvider,minInterval:n,maxInterval:r,apiKey:t.apiKey,onPersistentFailure:function(){y()}})];case 1:return(e=i.sent())?(p=!0,[2,e]):(t.loggerProvider.log("Failed to initialize idb store, falling back to memory store."),[2,g()])}})})},"idb"!==d?[3,2]:[4,b()];case 1:return S=T.sent(),[3,3];case 2:S=g(),T.label=3;case 3:return m=S,I=[],w=0,C=function(e){if(!(e<=w)){var t=Math.min(e-w,I.length);t>0&&(I.splice(0,t),w=e)}},P=function(e){var n=e.events,r=e.sessionId,i=e.deviceId,c=e.sequenceId;t.debugMode&&Ie().then(function(e){var n=e.totalStorageSize,r=e.percentOfQuota,i=e.usageDetails;t.loggerProvider.debug("Total storage size: ".concat(n," KB, percentage of quota: ").concat(r,"%, usage details: ").concat(i))}).catch(function(){}),h.sendEventsList({events:n,sessionId:r,flushMaxRetries:t.flushMaxRetries,apiKey:t.apiKey,deviceId:i,sampleRate:t.sampleRate,serverZone:t.serverZone,version:t.version,type:a,onComplete:function(){return o(void 0,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,m.cleanUpSessionEventsStore(r,c)];case 1:return e.sent(),[2]}})})}})},k=function(e){var n=e.sessionId,r=e.deviceId;f=r;var i=w+I.length;m.storeCurrentSequence(n).then(function(e){e&&(C(i),P({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:r}))}).catch(function(e){t.loggerProvider.warn("Failed to get current sequence of session replay events for session:",e)})},E=function(e){var t=e.deviceId;return o(void 0,void 0,void 0,function(){var e;return s(this,function(n){switch(n.label){case 0:return f=t,[4,m.getSequencesToSend()];case 1:return(e=n.sent())&&e.forEach(function(e){P({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:t})}),[2]}})})},R=function(e){var n=e.event,r=e.sessionId,i=e.deviceId;f=i;var o=w+I.length;I.push(n.data),m.addEventToCurrentSequence(r,n.data).then(function(e){e&&(C(o),P({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:i}))}).catch(function(e){t.loggerProvider.warn("Failed to add event to session replay capture:",e)})},[2,{sendCurrentSequenceEvents:k,addEvent:R,sendStoredEvents:E,flush:e,getBeaconEvents:function(){return l([],c(I),!1)},trackDestination:h}]}})})},mt=function(){function e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new Map;e.forEach(function(e){n.set(e.name,e.manager)}),this.managers=n}return e.prototype.sendStoredEvents=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.sendStoredEvents(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e.prototype.addEvent=function(e){var t,n=e.sessionId,r=e.event,i=e.deviceId;null===(t=this.managers.get(r.type))||void 0===t||t.addEvent({sessionId:n,event:r,deviceId:i})},e.prototype.sendCurrentSequenceEvents=function(e){var t=e.sessionId,n=e.deviceId;this.managers.forEach(function(e){e.sendCurrentSequenceEvents({sessionId:t,deviceId:n})})},e.prototype.flush=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.flush(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e}();function yt(e,t){if(at=new Date,e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";var n={root:document.body,idName:function(e){return!0},className:function(e){return!0},tagName:function(e){return!0},attr:function(e,t){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4,timeoutMs:void 0};ot=i(i({},n),t),st=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(ot.root,n);var r=bt(e,"all",function(){return bt(e,"two",function(){return bt(e,"one",function(){return bt(e,"none")})})});if(r){var o=_t(Ot(r,e));return o.length>0&&(r=o[0]),It(r)}throw new Error("Selector was not found.")}function bt(e,t,n){for(var r=null,i=[],o=e,s=0,u=function(){var e,u,d=(new Date).getTime()-at.getTime();if(void 0!==ot.timeoutMs&&d>ot.timeoutMs)throw new Error("Timeout: Can't find a unique selector after ".concat(d,"ms"));var v=Et(function(e){var t=e.getAttribute("id");if(t&&ot.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(o))||Et.apply(void 0,l([],c(function(e){var t=Array.from(e.attributes).filter(function(e){return ot.attr(e.name,e.value)});return t.map(function(e){return{name:"[".concat(CSS.escape(e.name),'="').concat(CSS.escape(e.value),'"]'),penalty:.5}})}(o)),!1))||Et.apply(void 0,l([],c(function(e){var t=Array.from(e.classList).filter(ot.className);return t.map(function(e){return{name:"."+CSS.escape(e),penalty:1}})}(o)),!1))||Et(function(e){var t=e.tagName.toLowerCase();if(ot.tagName(t))return{name:t,penalty:2};return null}(o))||[{name:"*",penalty:3}],h=function(e){var t=e.parentNode;if(!t)return null;var n=t.firstChild;if(!n)return null;var r=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&r++,n!==e);)n=n.nextSibling;return r}(o);if("all"==t)h&&(v=v.concat(v.filter(kt).map(function(e){return Pt(e,h)})));else if("two"==t)v=v.slice(0,1),h&&(v=v.concat(v.filter(kt).map(function(e){return Pt(e,h)})));else if("one"==t){var g=c(v=v.slice(0,1),1)[0];h&&kt(g)&&(v=[Pt(g,h)])}else"none"==t&&(v=[{name:"*",penalty:3}],h&&(v=[Pt(v[0],h)]));try{for(var f=(e=void 0,a(v)),p=f.next();!p.done;p=f.next()){(g=p.value).level=s}}catch(t){e={error:t}}finally{try{p&&!p.done&&(u=f.return)&&u.call(f)}finally{if(e)throw e.error}}if(i.push(v),i.length>=ot.seedMinLength&&(r=St(i,n)))return"break";o=o.parentElement,s++};o;){if("break"===u())break}return r||(r=St(i,n)),!r&&n?n():r}function St(e,t){var n,r,i=_t(Tt(e));if(i.length>ot.threshold)return t?t():null;try{for(var o=a(i),s=o.next();!s.done;s=o.next()){var c=s.value;if(Ct(c))return c}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return null}function It(e){for(var t=e[0],n=t.name,r=1;r<e.length;r++){var i=e[r].level||0;n=t.level===i-1?"".concat(e[r].name," > ").concat(n):"".concat(e[r].name," ").concat(n),t=e[r]}return n}function wt(e){return e.map(function(e){return e.penalty}).reduce(function(e,t){return e+t},0)}function Ct(e){var t=It(e);switch(st.querySelectorAll(t).length){case 0:throw new Error("Can't select any node with this selector: ".concat(t));case 1:return!0;default:return!1}}function Pt(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function kt(e){return"html"!==e.name&&!e.name.startsWith("#")}function Et(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(Rt);return n.length>0?n:null}function Rt(e){return null!=e}function Tt(e,t){var n,r,i,o,c,l;return void 0===t&&(t=[]),s(this,function(s){switch(s.label){case 0:if(!(e.length>0))return[3,9];s.label=1;case 1:s.trys.push([1,6,7,8]),n=a(e[0]),r=n.next(),s.label=2;case 2:return r.done?[3,5]:(i=r.value,[5,a(Tt(e.slice(1,e.length),t.concat(i)))]);case 3:s.sent(),s.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=s.sent(),c={error:o},[3,8];case 7:try{r&&!r.done&&(l=n.return)&&l.call(n)}finally{if(c)throw c.error}return[7];case 8:return[3,11];case 9:return[4,t];case 10:s.sent(),s.label=11;case 11:return[2]}})}function _t(e){return l([],c(e),!1).sort(function(e,t){return wt(e)-wt(t)})}function Ot(e,t,n){var r,i,o;return void 0===n&&(n={counter:0,visited:new Map}),s(this,function(s){switch(s.label){case 0:if(!(e.length>2&&e.length>ot.optimizedMinLength))return[3,5];r=1,s.label=1;case 1:return r<e.length-1?n.counter>ot.maxNumberOfTries?[2]:(n.counter+=1,(i=l([],c(e),!1)).splice(r,1),o=It(i),n.visited.has(o)?[2]:Ct(i)&&function(e,t){return st.querySelector(It(e))===t}(i,t)?[4,i]:[3,4]):[3,5];case 2:return s.sent(),n.visited.set(o,!0),[5,a(Ot(i,t,n))];case 3:s.sent(),s.label=4;case 4:return r++,[3,1];case 5:return[2]}})}var xt=function(e){var t=e.version,n=e.events,r=[];return n.forEach(function(e){var t=JSON.parse(e);t.count=1,"click"===t.type&&r.push(t)}),{version:t,events:r}},Mt=function(e){var t=e.version,n=e.events,r=[];n.forEach(function(e){var t=JSON.parse(e);"click"===t.type&&r.push(t)});var o=r.reduce(function(e,t){var n=t.x,r=t.y,o=t.selector,s=t.timestamp,a=s-s%36e5,c="".concat(n,":").concat(r,":").concat(null!=o?o:"",":").concat(a);return e[c]?e[c].count+=1:e[c]=i(i({},t),{timestamp:a,count:1}),e},{});return{version:t,events:Object.values(o)}},Lt=function(e,t){var n=this;this.createHook=function(e){var t=e.eventsManager,r=e.sessionId,i=e.deviceIdFn,o=e.mirror,s=e.ugcFilterRules,a=e.performanceOptions;return function(e){if(e.type===Ee.Click){var c=g();if(c){var l=c.location,u=c.innerHeight,d=c.innerWidth;if(l){var v=e.x,h=e.y;if(void 0!==v&&void 0!==h){var f,p=o.getNode(e.id);if(p)try{f=yt(p,a)}catch(e){n.logger.debug("error resolving selector from finder")}var m=Se(l.href,s),y={x:v+n.scrollWatcher.currentScrollX,y:h+n.scrollWatcher.currentScrollY,selector:f,viewportHeight:u,viewportWidth:d,pageUrl:m,timestamp:Date.now(),type:"click"},b=i();b&&t.addEvent({sessionId:r,event:{type:"interaction",data:JSON.stringify(y)},deviceId:b})}}}}}},this.logger=e,this.scrollWatcher=t};function Dt(){var e=g();return(null==e?void 0:e.innerHeight)||document.documentElement&&document.documentElement.clientHeight||0}function Ft(){var e=g();return(null==e?void 0:e.innerWidth)||document.documentElement&&document.documentElement.clientWidth||0}var Nt=function(){function e(e,t){var n=g();n&&n.navigator&&"function"==typeof n.navigator.sendBeacon?this.sendBeacon=function(e,t){try{if(n.navigator.sendBeacon(e,JSON.stringify(t)))return!0}catch(e){}return!1}:this.sendBeacon=function(){return!1},this.sendXhr=function(e,t){var n=new XMLHttpRequest;return n.open("POST",e,!0),n.setRequestHeader("Accept","*/*"),n.send(JSON.stringify(t)),!0},this.basePageUrl=de(t.serverZone,t.trackServerUrl),this.apiKey=t.apiKey,this.context=e}return e.prototype.send=function(e,t){var n=this.context,r=n.sessionId,i=n.type,o=new URLSearchParams({device_id:e,session_id:String(r),type:String(i),api_key:this.apiKey}),s="".concat(this.basePageUrl,"?").concat(o.toString());this.sendBeacon(s,t)||this.sendXhr(s,t)},e}(),Ut=function(){function e(e,t){var n=this;this.timestamp=Date.now(),this.hook=function(e){n.update(e)},this.send=function(e){return function(t){var r,i,o,s,a=e(),c=g();if(c&&a){var l=null!==(r=c.scrollX)&&void 0!==r?r:0,u=null!==(i=c.scrollY)&&void 0!==i?i:0;(l>0||u>0)&&n.update({id:1,x:l,y:u}),n.transport.send(a,{version:1,events:[{maxScrollX:n._maxScrollX,maxScrollY:n._maxScrollY,maxScrollWidth:n._maxScrollWidth,maxScrollHeight:n._maxScrollHeight,viewportHeight:Dt(),viewportWidth:Ft(),pageUrl:Se(c.location.href,null!==(s=null===(o=n.config.interactionConfig)||void 0===o?void 0:o.ugcFilterRules)&&void 0!==s?s:[]),timestamp:n.timestamp,type:"scroll"}]})}}},this._maxScrollX=0,this._maxScrollY=0,this._currentScrollX=0,this._currentScrollY=0,this._maxScrollWidth=Ft(),this._maxScrollHeight=Dt(),this.config=t,this.transport=e}return e.default=function(t,n){return new e(new Nt(t,n),n)},Object.defineProperty(e.prototype,"maxScrollX",{get:function(){return this._maxScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollY",{get:function(){return this._maxScrollY},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollWidth",{get:function(){return this._maxScrollWidth},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollHeight",{get:function(){return this._maxScrollHeight},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollX",{get:function(){return this._currentScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollY",{get:function(){return this._currentScrollY},enumerable:!1,configurable:!0}),e.prototype.update=function(e){var t=Date.now();if(this._currentScrollX=e.x,this._currentScrollY=e.y,e.x>this._maxScrollX){var n=Ft();this._maxScrollX=e.x;var r=e.x+n;r>this._maxScrollWidth&&(this._maxScrollWidth=r),this.timestamp=t}if(e.y>this._maxScrollY){var i=Dt();this._maxScrollY=e.y;var o=e.y+i;o>this._maxScrollHeight&&(this._maxScrollHeight=o),this.timestamp=t}},e}(),qt=function(e){var t=e.sessionId,n=e.deviceId;this.deviceId=n,this.sessionId=t,t&&n&&(this.sessionReplayId=function(e,t){return"".concat(t,"/").concat(e)}(t,n))},At=function(){var e=this;this.dbs={},this.createStore=function(t){return o(e,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,Je(t,1,{upgrade:function(e){e.objectStoreNames.contains("sessionTargetingMatch")||e.createObjectStore("sessionTargetingMatch",{keyPath:"sessionId"})}})];case 1:return[2,e.sent()]}})})},this.openOrCreateDB=function(t){return o(e,void 0,void 0,function(){var e,n;return s(this,function(r){switch(r.label){case 0:return this.dbs&&this.dbs[t]?[2,this.dbs[t]]:(e="".concat(t.substring(0,10),"_amp_session_replay_targeting"),[4,this.createStore(e)]);case 1:return n=r.sent(),this.dbs[t]=n,[2,n]}})})},this.getTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId;return o(e,void 0,void 0,function(){var e,t,o,a;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,e.get("sessionTargetingMatch",t)];case 2:return[2,null==(o=s.sent())?void 0:o.targetingMatch];case 3:return a=s.sent(),lt(n,"Failed to get targeting match for session id ".concat(i,": ").concat(a),a),[3,4];case 4:return[2,void 0]}})})},this.storeTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId,a=t.targetingMatch;return o(e,void 0,void 0,function(){var e,t,o;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,e.put("sessionTargetingMatch",{targetingMatch:a,sessionId:t,lastUpdated:Date.now()})];case 2:return[2,s.sent()];case 3:return o=s.sent(),lt(n,"Failed to store targeting match for session id ".concat(i,": ").concat(o),o),[3,4];case 4:return[2,void 0]}})})},this.clearStoreOfOldSessions=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.currentSessionId;return o(e,void 0,void 0,function(){var e,t,o,a,c,l,u,d;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,8,,9]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,(o=e.transaction("sessionTargetingMatch","readwrite")).store.getAll()];case 2:a=s.sent(),c=0,s.label=3;case 3:return c<a.length?(l=a[c],u=Date.now()-l.lastUpdated,l.sessionId!==t&&u>1728e5?[4,o.store.delete(l.sessionId)]:[3,5]):[3,6];case 4:s.sent(),s.label=5;case 5:return c++,[3,3];case 6:return[4,o.done];case 7:return s.sent(),[3,9];case 8:return d=s.sent(),lt(n,"Failed to clear old targeting matches for sessions: ".concat(d),d),[3,9];case 9:return[2]}})})}},jt=new At,Bt=function(e){var t=e.sessionId,n=e.targetingConfig,r=e.loggerProvider,a=e.apiKey,c=e.targetingParams,l=e.urlChange,u=void 0!==l&&l;return o(void 0,void 0,void 0,function(){var e,o,l,d,v,h;return s(this,function(s){switch(s.label){case 0:return[4,jt.clearStoreOfOldSessions({loggerProvider:r,apiKey:a,currentSessionId:t})];case 1:return s.sent(),[4,jt.getTargetingMatchForSession({loggerProvider:r,apiKey:a,sessionId:t})];case 2:if(!0===s.sent()&&!u)return[2,!0];e=!0,s.label=3;case 3:return s.trys.push([3,6,,7]),[4,import("./index-min3.js")];case 4:return o=s.sent().evaluateTargeting,l=i(i({},c),{flag:n,sessionId:"string"==typeof t?parseInt(t,10):t,apiKey:a,loggerProvider:r}),[4,o(l)];case 5:return(d=s.sent())&&d.sr_targeting_config&&(e="on"===d.sr_targeting_config.key),jt.storeTargetingMatchForSession({loggerProvider:r,apiKey:a,sessionId:t,targetingMatch:e}),[3,7];case 6:return v=s.sent(),h=v,r.warn(h.message),[3,7];case 7:return[2,e]}})})},Wt=2654435761,Kt=2246822519,$t=3266489917,Ht=374761393;function zt(e,t){return(e<<t|e>>>32-t)>>>0}function Jt(e,t){return e=zt(e=e+Math.imul(t,Kt)>>>0,13),e=Math.imul(e,Wt)>>>0}function Gt(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function Vt(e,t){void 0===t&&(t=0);var n,r=function(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r>=55296&&r<=56319&&n+1<e.length){var i=e.charCodeAt(n+1);i>=56320&&i<=57343&&(r=i-56320+(r-55296<<10)+65536,n++)}r<128?t.push(r):r<2048?t.push(192|r>>6,128|63&r):r<65536?t.push(224|r>>12,128|r>>6&63,128|63&r):t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)}return new Uint8Array(t)}(e),i=r.length,o=0;if(i>=16){for(var s=t+Wt+Kt>>>0,a=t+Kt>>>0,c=t>>>0,l=t-Wt>>>0;o<=i-16;)s=Jt(s,Gt(r,o)),a=Jt(a,Gt(r,o+=4)),c=Jt(c,Gt(r,o+=4)),l=Jt(l,Gt(r,o+=4)),o+=4;n=zt(s,1)+zt(a,7)+zt(c,12)+zt(l,18)>>>0}else n=t+Ht>>>0;for(n=n+i>>>0;o<=i-4;)n=n+Math.imul(Gt(r,o),$t)>>>0,n=Math.imul(zt(n,17),668265263)>>>0,o+=4;for(;o<i;)n=n+Math.imul(r[o],Ht)>>>0,n=Math.imul(zt(n,11),Wt)>>>0,o++;return n^=n>>>15,n=Math.imul(n,Kt)>>>0,n^=n>>>13,n=Math.imul(n,$t)>>>0,(n^=n>>>16)>>>0}var Zt="__amplitude_url_tracking_patched__",Qt=new WeakMap;function Yt(e,t,n){if(void 0===n&&(n={}),!(null==e?void 0:e.location))return function(){};var r=n.enablePolling,i=void 0!==r&&r,o=n.pollingInterval,s=void 0===o?re:o;if(i){var a=function(){var t;return null!==(t=e.location.href)&&void 0!==t?t:""},c=a(),l=e.setInterval(function(){var e=a();e!==c&&(c=e,t(e))},s);return function(){null!=l&&e.clearInterval(l)}}var u=Qt.get(e);if(!u){var d=void 0,v=new Set,h=function(){var t=function(){var t;return null!==(t=e.location.href)&&void 0!==t?t:""}();void 0!==d&&t===d||(d=t,v.forEach(function(e){return e(t)}))},g=function(e){var t=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=e.apply(this,t);return h(),r};return t[Zt]=!0,t},f=e.history;if(null==f?void 0:f.pushState){var p=Reflect.get(f,"pushState");p[Zt]||(f.pushState=g(p))}if(null==f?void 0:f.replaceState){var m=Reflect.get(f,"replaceState");m[Zt]||(f.replaceState=g(m))}u={callbacks:v,notify:h,onPopStateOrHashChange:function(){return h()},listenersAttached:!1},Qt.set(e,u)}var y=u;return y.listenersAttached||(e.addEventListener("popstate",y.onPopStateOrHashChange),e.addEventListener("hashchange",y.onPopStateOrHashChange),y.listenersAttached=!0),y.callbacks.add(t),function(){y.callbacks.delete(t),0===y.callbacks.size&&y.listenersAttached&&(e.removeEventListener("popstate",y.onPopStateOrHashChange),e.removeEventListener("hashchange",y.onPopStateOrHashChange),y.listenersAttached=!1)}}function Xt(e){return void 0===e&&(e={}),{name:"amplitude/url-tracking@1",observer:function(t,n,r){var o,s,a,c=i(i({},e),r),l=c.ugcFilterRules||[],u=null!==(o=c.enablePolling)&&void 0!==o&&o,d=null!==(s=c.pollingInterval)&&void 0!==s?s:re,v=null!==(a=c.captureDocumentTitle)&&void 0!==a&&a;if(!n)return function(){};var h=void 0,g=function(){return n.location&&n.location.href||""},f=function(){var e=g();if(void 0===h||e!==h){h=e;var r=function(){var e=n.innerHeight,t=n.innerWidth,r=n.document,i=g(),o="";return v&&(o=(null==r?void 0:r.title)||""),{href:l.length>0?Se(i,l):i,title:o,viewportHeight:e,viewportWidth:t,type:"url-change-event"}}();t(r)}},p=Yt(n,function(){return f()},u?{enablePolling:!0,pollingInterval:d}:{});return f(),function(){return p()}},options:e}}Xt();var en,tn,nn,rn=function(){function e(){var e=this;this.name="@amplitude/session-replay-browser",this.recordCancelCallback=null,this.eventCount=0,this.sessionTargetingMatch=!1,this.pageLeaveFns=[],this.recordFunction=null,this.recordEventsInFlight=!1,this.currentPageUrl="",this.recordEventsPendingShouldLogMetadata=null,this.urlChangeCleanup=null,this.latestUrlChangeTargetingEvaluationId=0,this.teardownEventListeners=function(t){var n=g();n&&(n.removeEventListener("blur",e.blurListener),n.removeEventListener("focus",e.focusListener),!t&&n.addEventListener("blur",e.blurListener),!t&&n.addEventListener("focus",e.focusListener),n.self&&"onpagehide"in n.self?(n.removeEventListener("pagehide",e.pageLeaveListener),!t&&n.addEventListener("pagehide",e.pageLeaveListener)):(n.removeEventListener("beforeunload",e.pageLeaveListener),!t&&n.addEventListener("beforeunload",e.pageLeaveListener)))},this.blurListener=function(){e.sendEvents()},this.focusListener=function(){if(e.recordCancelCallback&&e.recordFunction)try{e.recordFunction.takeFullSnapshot(!0)}catch(t){e.loggerProvider.warn("Failed to take full snapshot on focus:",t)}else e.recordEventsInFlight||e.recordEvents(!1)},this.pageLeaveListener=function(t){e.pageLeaveFns.forEach(function(e){e(t)})},this.evaluateTargetingAndCapture=function(t,n,i,a){return void 0===n&&(n=!1),void 0===i&&(i=!1),void 0===a&&(a=!1),o(e,void 0,void 0,function(){var e,o,c,l,u,d,v,h,f,p,m,y;return s(this,function(s){switch(s.label){case 0:if(!this.identifiers||!this.identifiers.sessionId||!this.config)return this.identifiers&&!this.identifiers.sessionId?this.loggerProvider.log("Session ID has not been set yet, cannot evaluate targeting for Session Replay."):this.loggerProvider.warn("Session replay init has not been called, cannot evaluate targeting."),[2];if(!this.config.targetingConfig){if(!n)return this.loggerProvider.log("No targeting config set, skipping initialization/recording for event."),[2];this.loggerProvider.log("Targeting config has not been set yet, cannot evaluate targeting.")}return this.lastTargetingParams=t,e=this.config.targetingConfig,e&&!this.sessionTargetingMatch?(o=a?this.latestUrlChangeTargetingEvaluationId:void 0,(c=t.event)&&Object.values(r).includes(c.event_type)&&(c=void 0),l=null!==(m=null!==(h=null===(v=t.page)||void 0===v?void 0:v.url)&&void 0!==h?h:null===(p=null===(f=g())||void 0===f?void 0:f.location)||void 0===p?void 0:p.href)&&void 0!==m?m:"",u=null!==(y=t.page)&&void 0!==y?y:""!==l?{url:l}:void 0,[4,Bt({sessionId:this.identifiers.sessionId,targetingConfig:e,loggerProvider:this.loggerProvider,apiKey:this.config.apiKey,targetingParams:{userProperties:t.userProperties,event:c,page:u},urlChange:a})]):[3,2];case 1:if(d=s.sent(),a&&void 0!==o&&o!==this.latestUrlChangeTargetingEvaluationId)return this.loggerProvider.debug("Ignoring stale URL-change targeting result #".concat(o,"; latest is #").concat(this.latestUrlChangeTargetingEvaluationId,".")),[2];this.sessionTargetingMatch=this.sessionTargetingMatch||d,this.loggerProvider.debug(JSON.stringify({name:"targeted replay capture config",sessionTargetingMatch:this.sessionTargetingMatch,event:c,targetingParams:t},null,2)),s.label=2;case 2:return n?(this.initialize(!0),[3,5]):[3,3];case 3:return!i&&this.recordCancelCallback?[3,5]:(this.loggerProvider.log("Recording events for session due to forceRestart or no ongoing recording."),[4,this.recordEvents()]);case 4:s.sent(),s.label=5;case 5:return[2]}})})},this.addCustomRRWebEvent=function(t,n,r){return void 0===n&&(n={}),void 0===r&&(r=!0),o(e,void 0,void 0,function(){var e,o,a,c;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),e=void 0,(o=this.config)&&t!==Y.METADATA?(e={config:we(o),version:Me},r?[4,Ie()]:[3,2]):[3,2];case 1:a=s.sent(),e=i(i({},a),e),s.label=2;case 2:return this.recordCancelCallback&&this.recordFunction?this.recordFunction.addCustomEvent(t,i(i({},n),e)):this.loggerProvider.debug("Not able to add custom replay capture event ".concat(t," due to no ongoing recording.")),[3,4];case 3:return c=s.sent(),this.loggerProvider.debug("Error while adding custom replay capture event: ",c),[3,4];case 4:return[2]}})})},this.stopRecordingEvents=function(){var t;try{e.loggerProvider.log("Session Replay capture stopping."),e.recordCancelCallback&&e.recordCancelCallback(),e.recordCancelCallback=null,null===(t=e.networkObservers)||void 0===t||t.stop()}catch(t){var n=t;e.loggerProvider.warn("Error occurred while stopping replay capture: ".concat(n.toString()))}},this.loggerProvider=new le(new b)}return e.prototype.init=function(e,t){return m(this._init(e,t))},e.prototype.setupUrlChangeListener=function(){var e,t,n=this;null===(e=this.urlChangeCleanup)||void 0===e||e.call(this);var r=g();if(null==r?void 0:r.location){var i=!!(null===(t=this.config)||void 0===t?void 0:t.targetingConfig),o=Yt(r,function(e){if(n.currentPageUrl=e,i){var t=++n.latestUrlChangeTargetingEvaluationId;n.evaluateTargetingAndCapture({userProperties:{},event:void 0,page:{url:e}},!1,!1,!0),n.loggerProvider.debug("Queued URL-change targeting re-evaluation #".concat(t," for ").concat(e,"."))}});this.urlChangeCleanup=function(){o(),n.urlChangeCleanup=null}}},e.prototype.getCurrentPageForTargeting=function(){var e,t,n=null===(t=null===(e=g())||void 0===e?void 0:e.location)||void 0===t?void 0:t.href;return null!=n?{url:n}:void 0},e.prototype._init=function(e,t){var n,r,a,u,d,v,h,f,p,m,y;return o(this,void 0,void 0,function(){var o,S,I,w,C,P,k,E,R,T,_,O,x,M,L,D,F,N,U,q,A,j=this;return s(this,function(s){switch(s.label){case 0:return null===(n=this.urlChangeCleanup)||void 0===n||n.call(this),this.loggerProvider=new le(t.loggerProvider||new b),Object.prototype.hasOwnProperty.call(t,"logLevel")&&this.loggerProvider.enable(t.logLevel),this.currentPageUrl=me(),this.identifiers=new qt({sessionId:t.sessionId,deviceId:t.deviceId}),o=this,[4,Te(e,t)];case 1:return o.joinedConfigGenerator=s.sent(),[4,this.joinedConfigGenerator.generateJoinedConfig()];case 2:return S=s.sent(),I=S.joinedConfig,w=S.localConfig,C=S.remoteConfig,this.config=I,this.setMetadata(t.sessionId,I,w,C,null===(r=t.version)||void 0===r?void 0:r.version,Me,null===(a=t.version)||void 0===a?void 0:a.type),this.pageLeaveFns=[],t.sessionId&&(null===(u=this.config.interactionConfig)||void 0===u?void 0:u.enabled)&&(P=Ut.default({sessionId:t.sessionId,type:"interaction"},this.config),this.pageLeaveFns=[P.send(this.getDeviceId.bind(this)).bind(P)],this.scrollHook=P.hook.bind(P),this.clickHandler=new Lt(this.loggerProvider,P)),k=[],"idb"!==(E=this.config.storeType)||(null===(d=g())||void 0===d?void 0:d.indexedDB)||(E="memory",this.loggerProvider.warn("Could not use preferred indexedDB storage, reverting to in memory option.")),this.loggerProvider.log("Using ".concat(E," for event storage.")),_=g(),this.config.useWebWorker&&_&&_.Worker?[4,import("./index-min2.js")]:[3,4];case 3:O=s.sent(),x=O.compressionScript,M=O.trackDestinationScript,R=x,T=M,s.label=4;case 4:return s.trys.push([4,6,,7]),[4,pt({config:this.config,type:"replay",storeType:E,trackDestinationWorkerScript:T})];case 5:return L=s.sent(),k.push({name:"replay",manager:L}),[3,7];case 6:return D=s.sent(),q=D,this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(q.toString())),[3,7];case 7:if(!(null===(v=this.config.interactionConfig)||void 0===v?void 0:v.enabled))return[3,11];F=this.config.interactionConfig.batch?Mt:xt,s.label=8;case 8:return s.trys.push([8,10,,11]),[4,pt({config:this.config,type:"interaction",minInterval:null!==(h=this.config.interactionConfig.trackEveryNms)&&void 0!==h?h:3e4,maxInterval:6e4,payloadBatcher:F,storeType:E,trackDestinationWorkerScript:T})];case 9:return N=s.sent(),k.push({name:"interaction",manager:N}),[3,11];case 10:return U=s.sent(),q=U,this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(q.toString())),[3,11];case 11:return this.eventsManager=new(mt.bind.apply(mt,l([void 0],c(k),!1))),this.eventCompressor&&this.eventCompressor.terminate(),this.eventCompressor=new _e(this.eventsManager,this.config,this.getDeviceId(),R,function(){return j.sendEvents()}),this.pageLeaveFns=l(l([],c(this.pageLeaveFns),!1),[function(){var e;if(j.config&&(null===(e=j.identifiers)||void 0===e?void 0:e.sessionId)&&L){var t=L.getBeaconEvents();if(t.length){var n=j.getDeviceId();n&&L.trackDestination.sendBeacon({events:t,sessionId:j.identifiers.sessionId,deviceId:n,apiKey:j.config.apiKey,serverZone:j.config.serverZone})}}}],!1),[4,this.initializeNetworkObservers()];case 12:return s.sent(),(null===(f=g())||void 0===f?void 0:f.opener)&&(function(e,t){var n,r=e;if(!0!==r[Q]){r[Q]=!0;var i=null!==(n=null==t?void 0:t.scriptUrl)&&void 0!==n?n:"https://cdn.amplitude.com/libs/background-capture-1.0.0-alpha.3.js.gz",o=null,s=function(t,n){var r,i;"background-capture-complete"===t&&(null===(i=null===(r=e.logger)||void 0===r?void 0:r.debug)||void 0===i||i.call(r,"Background capture complete"),e.notify({action:"background-capture-complete",data:n}))};e.registerActionHandler("initialize-background-capture",function(){var t,n;null===(n=null===(t=e.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Initializing background capture (external script)");var r=new URL(i,e.endpoint).toString();e.loadScriptOnce(r).then(function(){var t,n,r;null===(n=null===(t=e.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Background capture script loaded (external)"),o=null===(r=null===window||void 0===window?void 0:window.amplitudeBackgroundCapture)||void 0===r?void 0:r.call(window,{messenger:e,onBackgroundCapture:s}),e.notify({action:"background-capture-loaded"})}).catch(function(){var t;null===(t=e.logger)||void 0===t||t.warn("Failed to initialize background capture")})}),e.registerActionHandler("close-background-capture",function(){var e;null===(e=null==o?void 0:o.close)||void 0===e||e.call(o),o=null})}}(A=Z()),A.setup(i({logger:this.loggerProvider},this.config.serverZone&&{endpoint:z[this.config.serverZone]}))),this.loggerProvider.log("Installing @amplitude/session-replay-browser."),this.teardownEventListeners(!1),[4,this.evaluateTargetingAndCapture({userProperties:t.userProperties,page:this.getCurrentPageForTargeting()},!0)];case 13:return s.sent(),(this.config.targetingConfig||(null!==(y=null===(m=null===(p=this.config.privacyConfig)||void 0===p?void 0:p.urlMaskLevels)||void 0===m?void 0:m.length)&&void 0!==y?y:0)>0)&&this.setupUrlChangeListener(),[2]}})})},e.prototype.setSessionId=function(e,t){return m(this.asyncSetSessionId(e,t))},e.prototype.asyncSetSessionId=function(e,t,n){var r;return o(this,void 0,void 0,function(){var i,o,a;return s(this,function(s){switch(s.label){case 0:return this.latestUrlChangeTargetingEvaluationId++,this.sessionTargetingMatch=!1,this.lastShouldRecordDecision=void 0,(i=this.identifiers&&this.identifiers.sessionId)&&this.sendEvents(i),o=t||this.getDeviceId(),this.identifiers=new qt({sessionId:e,deviceId:o}),this.joinedConfigGenerator&&i?[4,this.joinedConfigGenerator.generateJoinedConfig()]:[3,2];case 1:a=s.sent().joinedConfig,this.config=a,s.label=2;case 2:return(null===(r=this.config)||void 0===r?void 0:r.targetingConfig)?[4,this.evaluateTargetingAndCapture({userProperties:null==n?void 0:n.userProperties,page:this.getCurrentPageForTargeting()},!1,!0)]:[3,4];case 3:return s.sent(),[3,6];case 4:return[4,this.recordEvents()];case 5:s.sent(),s.label=6;case 6:return[2]}})})},e.prototype.getSessionReplayProperties=function(){var e,t=this.config,n=this.identifiers;if(!t||!n)return this.loggerProvider.warn("Session replay init has not been called, cannot get session replay properties."),{};var r=this.getShouldRecord(),i={};return r&&((e={})[ee]=n.sessionReplayId?n.sessionReplayId:null,i=e,t.debugMode&&(i[ie]=JSON.stringify({appHash:N(t.apiKey).toString()}))),this.addCustomRRWebEvent(Y.GET_SR_PROPS,{shouldRecord:r,eventProperties:i},10===this.eventCount),10===this.eventCount&&(this.eventCount=0),this.eventCount++,i},e.prototype.sendEvents=function(e){var t,n=e||(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId),r=this.getDeviceId();this.eventsManager&&n&&r&&this.eventsManager.sendCurrentSequenceEvents({sessionId:n,deviceId:r})},e.prototype.initialize=function(e){var t;return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var n;return s(this,function(r){return(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId)?(n=this.getDeviceId())?(this.eventsManager&&e&&this.eventsManager.sendStoredEvents({deviceId:n}),[2,this.recordEvents()]):(this.loggerProvider.log("Session is not being recorded due to lack of device id."),[2,Promise.resolve()]):(this.loggerProvider.log("Session is not being recorded due to lack of session id."),[2,Promise.resolve()])})})},e.prototype.shouldOptOut=function(){var e,t,n,r;(null===(e=this.config)||void 0===e?void 0:e.instanceName)&&(n=(r=this.config.instanceName,void 0===r&&(r=d),F.getInstance(r)).identityStore.getIdentity().optOut);return void 0!==n?n:null===(t=this.config)||void 0===t?void 0:t.optOut},e.prototype.getShouldRecord=function(){if(!this.identifiers||!this.config||!this.identifiers.sessionId)return this.loggerProvider.warn("Session is not being recorded due to lack of config, please call sessionReplay.init."),!1;if(!this.config.captureEnabled)return this.loggerProvider.log("Session ".concat(this.identifiers.sessionId," not being captured due to capture being disabled for project or because the remote config could not be fetched.")),!1;if(this.shouldOptOut())return this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId," out of recording due to optOut config.")),!1;var e,t,n=!1,r="",i=!1;this.config.targetingConfig?this.sessionTargetingMatch?(r="Capturing replays for session ".concat(this.identifiers.sessionId," due to matching targeting conditions."),this.loggerProvider.log(r),n=!0,i=!0):(r="Not capturing replays for session ".concat(this.identifiers.sessionId," due to not matching targeting conditions."),this.loggerProvider.log(r),n=!1,i=!1):(e=this.identifiers.sessionId,t=this.config.sampleRate,Vt(e.toString())%1e6/1e6<t)?(n=!0,i=!0):(r="Opting session ".concat(this.identifiers.sessionId," out of recording due to sample rate."),this.loggerProvider.log(r),n=!1,i=!1);return this.lastShouldRecordDecision!==n&&this.config.targetingConfig&&(this.addCustomRRWebEvent(Y.TARGETING_DECISION,{message:r,sessionId:this.identifiers.sessionId,matched:i,targetingParams:this.lastTargetingParams}),this.lastShouldRecordDecision=n),n},e.prototype.getBlockSelectors=function(){var e,t,n,r=null!==(n=null===(t=null===(e=this.config)||void 0===e?void 0:e.privacyConfig)||void 0===t?void 0:t.blockSelector)&&void 0!==n?n:[];if(0!==r.length)return r},e.prototype.getMaskTextSelectors=function(){var e,t,n=null===(e=this.config)||void 0===e?void 0:e.privacyConfig;if("conservative"===(n?he(this.currentPageUrl,n):void 0))return"*";if(null===(t=null==n?void 0:n.urlMaskLevels)||void 0===t?void 0:t.some(function(e){return"conservative"===e.maskLevel}))return"*";var r=null==n?void 0:n.urlMaskLevels;if("conservative"===(null==n?void 0:n.defaultMaskLevel)&&r&&r.length>0)return"*";var i=null==n?void 0:n.maskSelector;return i||void 0},e.prototype.getRecordingPlugins=function(e){var t,n,r,i,a,c;return o(this,void 0,void 0,function(){var o,l,u,d;return s(this,function(s){switch(s.label){case 0:o=[];try{l=Xt({ugcFilterRules:(null===(n=null===(t=this.config)||void 0===t?void 0:t.interactionConfig)||void 0===n?void 0:n.ugcFilterRules)||[],enablePolling:(null===(r=this.config)||void 0===r?void 0:r.enableUrlChangePolling)||!1,pollingInterval:null===(i=this.config)||void 0===i?void 0:i.urlChangePollingInterval,captureDocumentTitle:null===(a=this.config)||void 0===a?void 0:a.captureDocumentTitle}),o.push(l)}catch(e){this.loggerProvider.warn("Failed to create URL tracking plugin:",e)}if(!(null===(c=null==e?void 0:e.console)||void 0===c?void 0:c.enabled))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,import("./console-plugin-min.js")];case 2:return u=s.sent().getRecordConsolePlugin,o.push(u({level:e.console.levels})),[3,4];case 3:return d=s.sent(),this.loggerProvider.warn("Failed to load console plugin:",d),[3,4];case 4:return[2,o.length>0?o:void 0]}})})},e.prototype.getRecordFunction=function(){return o(this,void 0,void 0,function(){var e,t;return s(this,function(n){switch(n.label){case 0:if(this.recordFunction)return[2,this.recordFunction];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,import("./rrweb-record-min.js")];case 2:return e=n.sent().record,this.recordFunction=e,[2,e];case 3:return t=n.sent(),this.loggerProvider.warn("Failed to load rrweb-record module:",t),[2,null];case 4:return[2]}})})},e.prototype.recordEvents=function(e){return void 0===e&&(e=!0),o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:if(this.recordEventsInFlight)return this.recordEventsPendingShouldLogMetadata=e,[2];this.recordEventsInFlight=!0,n.label=1;case 1:return n.trys.push([1,,6,7]),[4,this._recordEvents(e)];case 2:n.sent(),n.label=3;case 3:return null===this.recordEventsPendingShouldLogMetadata?[3,5]:(t=this.recordEventsPendingShouldLogMetadata,this.recordEventsPendingShouldLogMetadata=null,[4,this._recordEvents(t)]);case 4:return n.sent(),[3,3];case 5:return[3,7];case 6:return this.recordEventsInFlight=!1,this.recordEventsPendingShouldLogMetadata=null,[7];case 7:return[2]}})})},e.prototype._recordEvents=function(e){var t,n,r,i,a,c,l,u;return void 0===e&&(e=!0),o(this,void 0,void 0,function(){var o,d,v,h,g,f,p,m,y,b,S,I,w,C,P,k,E=this;return s(this,function(s){switch(s.label){case 0:return o=this.config,d=this.getShouldRecord(),v=null===(t=this.identifiers)||void 0===t?void 0:t.sessionId,d&&v&&o?(this.stopRecordingEvents(),[4,this.getRecordFunction()]):[2];case 1:return(h=s.sent())?[4,this.initializeNetworkObservers()]:[2];case 2:s.sent(),g=null===(n=o.loggingConfig)||void 0===n?void 0:n.network,f=de(o.serverZone,o.trackServerUrl),p=[se,ae,ce,f],null===(r=this.networkObservers)||void 0===r||r.start(function(e){p.some(function(t){return e.url.startsWith(t)})||E.addCustomRRWebEvent(Y.FETCH_REQUEST,e)},g),m=o.privacyConfig,y=o.interactionConfig,b=o.loggingConfig,S=(null==y?void 0:y.enabled)?{mouseInteraction:this.eventsManager&&(null===(i=this.clickHandler)||void 0===i?void 0:i.createHook({eventsManager:this.eventsManager,sessionId:v,deviceIdFn:this.getDeviceId.bind(this),mirror:h.mirror,ugcFilterRules:null!==(a=y.ugcFilterRules)&&void 0!==a?a:[],performanceOptions:null===(c=o.performanceConfig)||void 0===c?void 0:c.interaction})),scroll:this.scrollHook}:{},I=(null==y?void 0:y.enabled)&&y.ugcFilterRules?y.ugcFilterRules:[],this.loggerProvider.log("Session Replay capture beginning for ".concat(v,".")),s.label=3;case 3:return s.trys.push([3,5,,6]),w=this,C=h,k={emit:function(e){if(E.shouldOptOut())return E.loggerProvider.log("Opting session ".concat(v," out of recording due to optOut config.")),E.stopRecordingEvents(),void E.sendEvents();e.type===ke.Meta&&(e.data.href=Se(e.data.href,I)),E.eventCompressor&&E.eventCompressor.enqueueEvent(e,v)},inlineStylesheet:o.shouldInlineStylesheet,hooks:S,maskAllInputs:!0,maskTextClass:oe,blockClass:"amp-block",blockSelector:this.getBlockSelectors(),applyBackgroundColorToBlockedElements:o.applyBackgroundColorToBlockedElements,maskInputFn:fe("input",m,function(){return E.currentPageUrl}),maskTextFn:fe("text",m,function(){return E.currentPageUrl}),maskAttributeFn:pe(m,function(){return E.currentPageUrl}),maskTextSelector:this.getMaskTextSelectors(),recordCanvas:!1,captureAdoptedStyleSheets:o.captureAdoptedStyleSheets,slimDOMOptions:{script:null===(l=o.omitElementTags)||void 0===l?void 0:l.script,comment:null===(u=o.omitElementTags)||void 0===u?void 0:u.comment},errorHandler:function(e){var t=e;if(t.message.includes("insertRule")&&t.message.includes("CSSStyleSheet"))throw t;if(t._external_)throw t;return E.loggerProvider.warn("Error while capturing replay: ",t.toString()),!0}},[4,this.getRecordingPlugins(b)];case 4:return w.recordCancelCallback=C.apply(void 0,[(k.plugins=s.sent(),k)]),this.addCustomRRWebEvent(Y.DEBUG_INFO),e&&this.addCustomRRWebEvent(Y.METADATA,this.metadata),[3,6];case 5:return P=s.sent(),this.loggerProvider.warn("Failed to initialize session replay:",P),[3,6];case 6:return[2]}})})},e.prototype.getDeviceId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.deviceId},e.prototype.getSessionId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.sessionId},e.prototype.flush=function(e){var t;return void 0===e&&(e=!1),o(this,void 0,void 0,function(){return s(this,function(n){return[2,null===(t=this.eventsManager)||void 0===t?void 0:t.flush(e)]})})},e.prototype.shutdown=function(){var e;null===(e=this.urlChangeCleanup)||void 0===e||e.call(this),this.teardownEventListeners(!0),this.stopRecordingEvents(),this.sendEvents()},e.prototype.mapSDKType=function(e){return"plugin"===e?"@amplitude/plugin-session-replay-browser":"segment"===e?"@amplitude/segment-session-replay-plugin":null},e.prototype.setMetadata=function(e,t,n,r,i,o,s){var a=(null==e?void 0:e.toString())?N(e.toString()):void 0;this.metadata={joinedConfig:t,localConfig:n,remoteConfig:r,sessionId:e,hashValue:a,sampleRate:t.sampleRate,replaySDKType:this.mapSDKType(s),replaySDKVersion:i,standaloneSDKType:"@amplitude/session-replay-browser",standaloneSDKVersion:o}},e.prototype.initializeNetworkObservers=function(){var e,t,n;return o(this,void 0,void 0,function(){var r,i;return s(this,function(o){switch(o.label){case 0:if(!(null===(n=null===(t=null===(e=this.config)||void 0===e?void 0:e.loggingConfig)||void 0===t?void 0:t.network)||void 0===n?void 0:n.enabled)||this.networkObservers)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,import("./observers-min.js")];case 2:return r=o.sent().NetworkObservers,this.networkObservers=new r,[3,4];case 3:return i=o.sent(),this.loggerProvider.warn("Failed to import or instantiate NetworkObservers:",i),[3,4];case 4:return[2]}})})},e}(),on=function(e){return function(){var t=e.config||Ce();return{logger:t.loggerProvider,logLevel:t.logLevel}}},sn=function(){var e=new rn;return{init:P(e.init.bind(e),"init",on(e)),evaluateTargetingAndCapture:P(e.evaluateTargetingAndCapture.bind(e),"evaluateTargetingAndRecord",on(e)),setSessionId:P(e.setSessionId.bind(e),"setSessionId",on(e)),getSessionId:P(e.getSessionId.bind(e),"getSessionId",on(e)),getSessionReplayProperties:P(e.getSessionReplayProperties.bind(e),"getSessionReplayProperties",on(e)),flush:P(e.flush.bind(e),"flush",on(e)),shutdown:P(e.shutdown.bind(e),"shutdown",on(e))}}(),an=sn.init,cn=sn.setSessionId,ln=sn.getSessionId,un=sn.getSessionReplayProperties,dn=sn.flush,vn=sn.shutdown,hn=sn.evaluateTargetingAndCapture;!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"}(en||(en={})),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"}(tn||(tn={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(nn||(nn={}));const gn=[en.SET,en.SET_ONCE,en.ADD,en.APPEND,en.PREPEND,en.POSTINSERT],fn="1.28.0";class pn{constructor(e){this.name=pn.pluginName,this.type="enrichment",this.config=null,this.sessionReplay={flush:dn,getSessionId:ln,getSessionReplayProperties:un,init:an,setSessionId:cn,shutdown:vn,evaluateTargetingAndCapture:hn},this.options=Object.assign({forceSessionTracking:!1},e),this.srInitOptions=this.options}setup(e,t){return o(this,void 0,void 0,function*(){var t,n,r,i,o,s,a,c,l;try{null==e||e.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${fn}.`),this.config=e,this.options.forceSessionTracking&&("boolean"==typeof e.defaultTracking?!1===e.defaultTracking&&(e.defaultTracking={pageViews:!1,formInteractions:!1,fileDownloads:!1,sessions:!0}):e.defaultTracking=Object.assign(Object.assign({},e.defaultTracking),{sessions:!0}));const u=(l=this.config.instanceName,void 0===l&&(l="$default_instance"),F.getInstance(l)).identityStore.getIdentity().userProperties;this.srInitOptions={instanceName:this.config.instanceName,deviceId:null!==(t=this.options.deviceId)&&void 0!==t?t:this.config.deviceId,optOut:this.config.optOut,sessionId:this.options.customSessionId?void 0:this.config.sessionId,loggerProvider:this.config.loggerProvider,logLevel:this.config.logLevel,flushMaxRetries:this.config.flushMaxRetries,serverZone:this.config.serverZone,configServerUrl:this.options.configServerUrl||(null===(n=this.config.remoteConfig)||void 0===n?void 0:n.serverUrl),trackServerUrl:this.options.trackServerUrl,sampleRate:this.options.sampleRate,privacyConfig:{blockSelector:null===(r=this.options.privacyConfig)||void 0===r?void 0:r.blockSelector,maskSelector:null===(i=this.options.privacyConfig)||void 0===i?void 0:i.maskSelector,unmaskSelector:null===(o=this.options.privacyConfig)||void 0===o?void 0:o.unmaskSelector,defaultMaskLevel:null===(s=this.options.privacyConfig)||void 0===s?void 0:s.defaultMaskLevel},debugMode:this.options.debugMode,shouldInlineStylesheet:this.options.shouldInlineStylesheet,version:{type:"plugin",version:fn},performanceConfig:this.options.performanceConfig,storeType:this.options.storeType,useWebWorker:null!==(a=this.options.useWebWorker)&&void 0!==a?a:null===(c=this.options.experimental)||void 0===c?void 0:c.useWebWorker,userProperties:u,omitElementTags:this.options.omitElementTags,applyBackgroundColorToBlockedElements:this.options.applyBackgroundColorToBlockedElements,interactionConfig:this.options.interactionConfig,captureDocumentTitle:this.options.captureDocumentTitle,enableUrlChangePolling:this.options.enableUrlChangePolling,urlChangePollingInterval:this.options.urlChangePollingInterval,captureAdoptedStyleSheets:this.options.captureAdoptedStyleSheets},yield this.sessionReplay.init(e.apiKey,this.srInitOptions).promise}catch(t){null==e||e.loggerProvider.error(`Session Replay: Failed to initialize due to ${t.message}`)}})}onSessionIdChanged(e){return o(this,void 0,void 0,function*(){var t;null===(t=this.config)||void 0===t||t.loggerProvider.debug(`Analytics session id is changed to ${e}, SR session id is ${String(this.sessionReplay.getSessionId())}.`),yield this.sessionReplay.setSessionId(e).promise})}onOptOutChanged(e){return o(this,void 0,void 0,function*(){var t;null===(t=this.config)||void 0===t||t.loggerProvider.debug(`optOut is changed to ${String(e)}, calling ${e?"sessionReplay.shutdown()":"sessionReplay.init()"}.`),e?this.sessionReplay.shutdown():null!=this.config&&(yield this.sessionReplay.init(this.config.apiKey,this.srInitOptions).promise)})}execute(e){return o(this,void 0,void 0,function*(){var t,n,i;try{if(this.options.customSessionId){const t=this.options.customSessionId(e);if(t){t!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(t).promise);const n=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),n)}}else{const i=null===(t=this.config)||void 0===t?void 0:t.sessionId;if(i&&i!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(i).promise),i&&i===e.session_id){let t;e.event_type===r.IDENTIFY&&(t=(e=>{if(!e.user_properties)return;let t={};return Object.keys(e.user_properties).forEach(n=>{if(gn.includes(n)){const r=e.user_properties&&e.user_properties[n];t=Object.assign(Object.assign({},t),r)}}),t})(e));const i=g();yield this.sessionReplay.evaluateTargetingAndCapture({event:e,userProperties:t,page:null!=(null===(n=null==i?void 0:i.location)||void 0===n?void 0:n.href)?{url:i.location.href}:void 0});const o=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),o)}}return e.event_type===r.IDENTIFY&&e.event_properties&&delete e.event_properties["[Amplitude] Session Replay ID"],Promise.resolve(e)}catch(t){return null===(i=this.config)||void 0===i||i.loggerProvider.error(`Session Replay: Failed to enrich event due to ${t.message}`),Promise.resolve(e)}})}teardown(){return o(this,void 0,void 0,function*(){var e;try{this.sessionReplay.shutdown(),this.config=null}catch(t){null===(e=this.config)||void 0===e||e.loggerProvider.error(`Session Replay: teardown failed due to ${t.message}`)}})}getSessionReplayProperties(){return this.sessionReplay.getSessionReplayProperties()}}pn.pluginName="@amplitude/plugin-session-replay-browser";const mn=e=>new pn(e);export{pn as S,o as _,s as a,i as b,g,Je as o,mn as s};
1
+ 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,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((r=r.apply(e,t||[])).next())})}function s(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(l){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,l])}}}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 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 c(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"}(n||(n={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(r||(r={}));var u,d="$default_instance",h="https://api2.amplitude.com/2/httpapi";!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"}(u||(u={}));var v,g=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=c([],l(Array(256).keys()),!1).map(function(e){return e.toString(16).padStart(2,"0")}),p=function(e){var t,n=g();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,p)}(e);var r=n.crypto.getRandomValues(new Uint8Array(16));return r[6]=15&r[6]|64,r[8]=63&r[8]|128,c([],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("")},y=function(e){return{promise:e||Promise.resolve()}};!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"}(v||(v={}));var m="Amplitude Logger ",b=function(){function e(){this.logLevel=v.None}return e.prototype.disable=function(){this.logLevel=v.None},e.prototype.enable=function(e){void 0===e&&(e=v.Warn),this.logLevel=e},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<v.Verbose||console.log("".concat(m,"[Log]: ").concat(e.join(" ")))},e.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<v.Warn||console.warn("".concat(m,"[Warn]: ").concat(e.join(" ")))},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<v.Error||console.error("".concat(m,"[Error]: ").concat(e.join(" ")))},e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<v.Debug||console.log("".concat(m,"[Debug]: ").concat(e.join(" ")))},e}(),S=function(){return{flushMaxRetries:12,flushQueueSize:200,flushIntervalMillis:1e4,instanceName:d,logLevel:v.Warn,loggerProvider:new b,offline:!1,optOut:!1,serverUrl:h,serverZone:"US",useBatch:!1}},I=function(){function e(e){var t,n,r,i;this._optOut=!1;var o=S();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=C(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}(),w=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":h},C=function(e,t,n){if(void 0===e&&(e=""),void 0===t&&(t=S().serverZone),void 0===n&&(n=S().useBatch),e)return{serverUrl:e,serverZone:void 0};var r=["US","EU"].includes(t)?t:S().serverZone;return{serverZone:r,serverUrl:w(r,n)}};var k=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(),l=a.logger,c=a.logLevel;if(c&&c<v.Debug||!c||!l)return e.apply(i,o);var u,d={type:"invoke public method",name:t,args:o,stacktrace:(u=1,void 0===u&&(u=0),((new Error).stack||"").split("\n").slice(2+u).map(function(e){return e.trim()})),time:{start:(new Date).toISOString()},states:{}};r&&d.states&&(d.states.before=r());var h=e.apply(i,o);return h&&h.promise?h.promise.then(function(){r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),l.debug(JSON.stringify(d,null,2))}):(r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),l.debug(JSON.stringify(d,null,2))),h}},E=function(){function e(){}return e.prototype.getApplicationContext=function(){return{versionName:this.versionName,language:P(),platform:"Web",os:void 0,deviceModel:void 0}},e}(),P=function(){return"undefined"!=typeof navigator&&(navigator.languages&&navigator.languages[0]||navigator.language)||""},R=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}(),T=function(){return T=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},T.apply(this,arguments)};function M(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 x(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 _=function(e,t){var n,r,i=typeof e;if(i!==typeof t)return!1;try{for(var o=M(["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),l=Array.isArray(t);if(a!==l)return!1;if(!a||!l){var c=Object.keys(e).sort(),u=Object.keys(t).sort();if(!_(c,u))return!1;var d=!0;return Object.keys(e).forEach(function(n){_(e[n],t[n])||(d=!1)}),d}for(var h=0;h<e.length;h++)if(!_(e[h],t[h]))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 O,L=function(){function e(){this.identity={userProperties:{}},this.listeners=new Set}return e.prototype.editIdentity=function(){var e=this,t=T({},this.identity.userProperties),n=T(T({},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,l=n.userProperties||{};try{for(var c=M(Object.entries(e)),u=c.next();!u.done;u=c.next()){var d=x(u.value,2),h=d[0],v=d[1];switch(h){case"$set":try{for(var g=(i=void 0,M(Object.entries(v))),f=g.next();!f.done;f=g.next()){var p=x(f.value,2),y=p[0],m=p[1];l[y]=m}}catch(e){i={error:e}}finally{try{f&&!f.done&&(o=g.return)&&o.call(g)}finally{if(i)throw i.error}}break;case"$unset":try{for(var b=(s=void 0,M(Object.keys(v))),S=b.next();!S.done;S=b.next()){delete l[y=S.value]}}catch(e){s={error:e}}finally{try{S&&!S.done&&(a=b.return)&&a.call(b)}finally{if(s)throw s.error}}break;case"$clearAll":l={}}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(r=c.return)&&r.call(c)}finally{if(t)throw t.error}}return n.userProperties=l,this},commit:function(){return e.setIdentity(n),this}}},e.prototype.getIdentity=function(){return T({},this.identity)},e.prototype.setIdentity=function(e){var t=T({},this.identity);this.identity=T({},e),_(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}(),D="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self,F=function(){function e(){this.identityStore=new L,this.eventBridge=new R,this.applicationContextProvider=new E}return e.getInstance=function(t){return D.analyticsConnectorInstances||(D.analyticsConnectorInstances={}),D.analyticsConnectorInstances[t]||(D.analyticsConnectorInstances[t]=new e),D.analyticsConnectorInstances[t]},e}(),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},U=function(){function e(){}return e.prototype.send=function(e,t,n){return Promise.resolve(null)},e.prototype.buildResponse=function(e){var t,n,r,i,o,s,a,l,c,d,h,v,g,f,p,y,m,b,S,I,w,C;if("object"!=typeof e)return null;var k=e.code||0,E=this.buildStatus(k);switch(E){case u.Success:return{status:E,statusCode:k,body:{eventsIngested:null!==(t=e.events_ingested)&&void 0!==t?t:0,payloadSizeBytes:null!==(n=e.payload_size_bytes)&&void 0!==n?n:0,serverUploadTime:null!==(r=e.server_upload_time)&&void 0!==r?r:0}};case u.Invalid:return{status:E,statusCode:k,body:{error:null!==(i=e.error)&&void 0!==i?i:"",missingField:null!==(o=e.missing_field)&&void 0!==o?o:"",eventsWithInvalidFields:null!==(s=e.events_with_invalid_fields)&&void 0!==s?s:{},eventsWithMissingFields:null!==(a=e.events_with_missing_fields)&&void 0!==a?a:{},eventsWithInvalidIdLengths:null!==(l=e.events_with_invalid_id_lengths)&&void 0!==l?l:{},epsThreshold:null!==(c=e.eps_threshold)&&void 0!==c?c:0,exceededDailyQuotaDevices:null!==(d=e.exceeded_daily_quota_devices)&&void 0!==d?d:{},silencedDevices:null!==(h=e.silenced_devices)&&void 0!==h?h:[],silencedEvents:null!==(v=e.silenced_events)&&void 0!==v?v:[],throttledDevices:null!==(g=e.throttled_devices)&&void 0!==g?g:{},throttledEvents:null!==(f=e.throttled_events)&&void 0!==f?f:[]}};case u.PayloadTooLarge:return{status:E,statusCode:k,body:{error:null!==(p=e.error)&&void 0!==p?p:""}};case u.RateLimit:return{status:E,statusCode:k,body:{error:null!==(y=e.error)&&void 0!==y?y:"",epsThreshold:null!==(m=e.eps_threshold)&&void 0!==m?m:0,throttledDevices:null!==(b=e.throttled_devices)&&void 0!==b?b:{},throttledUsers:null!==(S=e.throttled_users)&&void 0!==S?S:{},exceededDailyQuotaDevices:null!==(I=e.exceeded_daily_quota_devices)&&void 0!==I?I:{},exceededDailyQuotaUsers:null!==(w=e.exceeded_daily_quota_users)&&void 0!==w?w:{},throttledEvents:null!==(C=e.throttled_events)&&void 0!==C?C:[]}};case u.Timeout:default:return{status:E,statusCode:k}}},e.prototype.buildStatus=function(e){return function(e){return e>=200&&e<300}(e)?u.Success:429===e?u.RateLimit:413===e?u.PayloadTooLarge:408===e?u.Timeout:e>=400&&e<500?u.Invalid:e>=500?u.Failed:u.Unknown},e}(),A=function(e){function n(t){void 0===t&&(t={});var n=e.call(this)||this;return n.customHeaders=t,n}return t(n,e),n.prototype.send=function(e,t){return o(this,void 0,void 0,function(){var n,r,o;return s(this,function(s){switch(s.label){case 0:if("undefined"==typeof fetch)throw new Error("FetchTransport is not supported");return n={headers:i({"Content-Type":"application/json",Accept:"*/*"},this.customHeaders),body:JSON.stringify(t),method:"POST"},[4,fetch(e,n)];case 1:return[4,(r=s.sent()).text()];case 2:o=s.sent();try{return[2,this.buildResponse(JSON.parse(o))]}catch(e){return[2,this.buildResponse({code:r.status})]}return[2]}})})},n}(U),q=function(){function e(e,t){this.key="AMP_remote_config_".concat(e.substring(0,10)),this.logger=t}return e.prototype.fetchConfig=function(){var e=null,t={remoteConfig:null,lastFetch:new Date};try{e=localStorage.getItem(this.key)}catch(e){return this.logger.debug("Remote config localstorage failed to access: ",e),Promise.resolve(t)}if(null===e)return this.logger.debug("Remote config localstorage gets null because the key does not exist"),Promise.resolve(t);try{var n=JSON.parse(e);return this.logger.debug("Remote config localstorage parsed successfully: ".concat(JSON.stringify(n))),Promise.resolve({remoteConfig:n.remoteConfig,lastFetch:new Date(n.lastFetch)})}catch(e){return this.logger.debug("Remote config localstorage failed to parse: ",e),localStorage.removeItem(this.key),Promise.resolve(t)}},e.prototype.setConfig=function(e){try{return localStorage.setItem(this.key,JSON.stringify(e)),this.logger.debug("Remote config localstorage set successfully."),Promise.resolve(!0)}catch(e){this.logger.debug("Remote config localstorage failed to set: ",e)}return Promise.resolve(!1)},e}(),j=401,B=403,W=429,z=function(){function e(e,t,n,r){void 0===n&&(n="US"),this.callbackInfos=[],this.lastSuccessfulFetch=null,this.fetchPromise=null,this.isLastFetchInvalidApiKey=!1,this.apiKey=e,this.serverUrl=r||("US"===n?"https://sr-client-cfg.amplitude.com/config":"https://sr-client-cfg.eu.amplitude.com/config"),this.logger=t,this.storage=new q(e,t)}return e.prototype.subscribe=function(e,t,n){var r=p(),i={id:r,key:e,deliveryMode:t,callback:n};return this.callbackInfos.push(i),"all"===t?this.subscribeAll(i):this.subscribeWaitForRemote(i,t.timeout),r},e.prototype.unsubscribe=function(e){var t=this.callbackInfos.findIndex(function(t){return t.id===e});return-1===t?(this.logger.debug("Remote config client unsubscribe failed because callback with id ".concat(e," doesn't exist.")),!1):(this.callbackInfos.splice(t,1),this.logger.debug("Remote config client unsubscribe succeeded removing callback with id ".concat(e,".")),!0)},e.prototype.updateConfigs=function(){return o(this,void 0,void 0,function(){var e,t=this;return s(this,function(n){switch(n.label){case 0:return this.lastSuccessfulFetch&&Date.now()-this.lastSuccessfulFetch<3e5?(this.logger.debug("Remote config client skipping updateConfigs: Too recent"),[2]):[4,this.getOrCreateFetchPromise()];case 1:return e=n.sent(),this.storage.setConfig(e),this.callbackInfos.forEach(function(n){t.sendCallback(n,e,"remote")}),[2]}})})},e.prototype.getOrCreateFetchPromise=function(){var e=this;return this.fetchPromise?this.fetchPromise:this.isLastFetchInvalidApiKey?(this.logger.debug("Remote config client skipping fetch: Invalid API key"),this.fetchPromise=Promise.resolve({remoteConfig:null,lastFetch:new Date}).finally(function(){e.fetchPromise=null}),this.fetchPromise):(this.fetchPromise=this.fetch().then(function(t){return null!==t.remoteConfig&&(e.lastSuccessfulFetch=Date.now()),t}).finally(function(){e.fetchPromise=null}),this.fetchPromise)},e.prototype.subscribeAll=function(e){return o(this,void 0,void 0,function(){var t,n,r,i=this;return s(this,function(o){switch(o.label){case 0:return t=this.getOrCreateFetchPromise().then(function(t){i.logger.debug("Remote config client subscription all mode fetched from remote: ".concat(JSON.stringify(t))),i.sendCallback(e,t,"remote"),i.storage.setConfig(t)}),n=this.storage.fetchConfig().then(function(e){return e}),[4,Promise.race([t,n])];case 1:return void 0!==(r=o.sent())&&(this.logger.debug("Remote config client subscription all mode fetched from cache: ".concat(JSON.stringify(r))),null!==r.remoteConfig?this.sendCallback(e,r,"cache"):this.logger.debug("Remote config client skips sending callback because cache is empty (first time user).")),[4,t];case 2:return o.sent(),[2]}})})},e.prototype.subscribeWaitForRemote=function(e,t){return o(this,void 0,void 0,function(){var n,r;return s(this,function(i){switch(i.label){case 0:n=new Promise(function(e,n){setTimeout(function(){n("Timeout exceeded")},t)}),i.label=1;case 1:return i.trys.push([1,3,,5]),[4,Promise.race([this.getOrCreateFetchPromise(),n])];case 2:return r=i.sent(),this.logger.debug("Remote config client subscription wait for remote mode returns from remote."),this.sendCallback(e,r,"remote"),this.storage.setConfig(r),[3,5];case 3:return i.sent(),this.logger.debug("Remote config client subscription wait for remote mode exceeded timeout. Try to fetch from cache."),[4,this.storage.fetchConfig()];case 4:return null!==(r=i.sent()).remoteConfig?(this.logger.debug("Remote config client subscription wait for remote mode returns a cached copy."),this.sendCallback(e,r,"cache")):(this.logger.debug("Remote config client subscription wait for remote mode failed to fetch cache."),this.sendCallback(e,r,"remote")),[3,5];case 5:return[2]}})})},e.prototype.sendCallback=function(e,t,n){var r;e.lastCallback=new Date,r=e.key?e.key.split(".").reduce(function(e,t){return null===e?e:t in e?e[t]:null},t.remoteConfig):t.remoteConfig,e.callback(r,n,t.lastFetch)},e.prototype.fetch=function(e,t){return void 0===e&&(e=3),void 0===t&&(t=1e3),o(this,void 0,void 0,function(){var n,r,i,o,a,l,c=this;return s(this,function(u){switch(u.label){case 0:n=t/e,r={remoteConfig:null,lastFetch:new Date},i=function(r){var i,a,l,u,d,h;return s(this,function(s){switch(s.label){case 0:i=!0,a=new AbortController,l=setTimeout(function(){return a.abort()},t),s.label=1;case 1:return s.trys.push([1,7,8,9]),[4,fetch(o.getUrlParams(),{method:"GET",headers:{Accept:"*/*"},signal:a.signal})];case 2:return(u=s.sent()).ok?[3,4]:[4,u.text()];case 3:return d=s.sent(),o.logger.debug("Remote config client fetch with retry time ".concat(e," failed with ").concat(u.status,": ").concat(d)),u.status===j||u.status===B?(o.logger.error("Remote config client fetch failed with ".concat(u.status,". Invalid API key; future fetches will be skipped.")),o.isLastFetchInvalidApiKey=!0,i=!1):u.status>=400&&u.status<500&&u.status!==W&&(i=!1),[3,6];case 4:return[4,u.json()];case 5:return[2,{value:{remoteConfig:s.sent(),lastFetch:new Date}}];case 6:return[3,9];case 7:return(h=s.sent())instanceof Error&&"AbortError"===h.name?o.logger.debug("Remote config client fetch with retry time ".concat(e," timed out after ").concat(t,"ms")):o.logger.debug("Remote config client fetch with retry time ".concat(e," is rejected because: "),h),[3,9];case 8:return clearTimeout(l),[7];case 9:return i?r<e-1?[4,new Promise(function(e){return setTimeout(e,c.getJitterDelay(n))})]:[3,11]:[2,"break"];case 10:s.sent(),s.label=11;case 11:return[2]}})},o=this,a=0,u.label=1;case 1:return a<e?[5,i(a)]:[3,4];case 2:if("object"==typeof(l=u.sent()))return[2,l.value];if("break"===l)return[3,4];u.label=3;case 3:return a++,[3,1];case 4:return[2,r]}})})},e.prototype.getJitterDelay=function(e){return Math.floor(Math.random()*e)},e.prototype.getUrlParams=function(){var t=encodeURIComponent(this.apiKey),n=new URLSearchParams;return n.append("config_group",e.CONFIG_GROUP),"".concat(this.serverUrl,"/").concat(t,"?").concat(n.toString())},e.CONFIG_GROUP="browser",e}();!function(e){e.US="US",e.EU="EU",e.STAGING="STAGING"}(O||(O={}));var K,$="https://app.amplitude.com",H={US:$,EU:"https://app.eu.amplitude.com",STAGING:"https://apps.stag2.amplitude.com"};var J="__AMPLITUDE_MESSENGER_INSTANCE__",Q="__AMPLITUDE_MESSENGER__",G=function(){function e(e){var t=(void 0===e?{}:e).origin,n=void 0===t?$:t;this[K]=!0,this.isSetup=!1,this.messageHandler=null,this.requestCallbacks={},this.actionHandlers=new Map,this.pendingMessages=new Map,this.scriptLoadPromises=new Map,this.endpoint=n}return e.prototype.notify=function(e){var t,n,r,i;null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message sent: ",JSON.stringify(e)),null===(i=null===(r=window.opener)||void 0===r?void 0:r.postMessage)||void 0===i||i.call(r,e,this.endpoint)},e.prototype.sendRequest=function(e,t,n){var r=this;void 0===n&&(n={timeout:15e3});var i="".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),o={id:i,action:e,args:t};return new Promise(function(t,s){r.requestCallbacks[i]={resolve:t,reject:s},r.notify(o),n.timeout>0&&setTimeout(function(){s(new Error("".concat(e," timed out (id: ").concat(i,")"))),delete r.requestCallbacks[i]},n.timeout)})},e.prototype.handleResponse=function(e){var t;this.requestCallbacks[e.id]?(this.requestCallbacks[e.id].resolve(e.responseData),delete this.requestCallbacks[e.id]):null===(t=this.logger)||void 0===t||t.warn("No callback found for request id: ".concat(e.id))},e.prototype.registerActionHandler=function(e,t){var n,r,i,o;this.actionHandlers.has(e)&&(null===(o=null===(i=this.logger)||void 0===i?void 0:i.warn)||void 0===o||o.call(i,"Overwriting existing action handler for: ".concat(e))),this.actionHandlers.set(e,t);var s=this.pendingMessages.get(e);if(s){this.pendingMessages.delete(e);try{for(var l=a(s),c=l.next();!c.done;c=l.next()){t(c.value)}}catch(e){n={error:e}}finally{try{c&&!c.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}}},e.prototype.loadScriptOnce=function(e){return o(this,void 0,void 0,function(){var t,n,r;return s(this,function(i){switch(i.label){case 0:if(t=this.scriptLoadPromises.get(e))return[2,t];n=function(e){return document.querySelector('script[src="'.concat(CSS.escape(e),'"]'))?Promise.resolve({status:!0}):new Promise(function(t,n){var r;try{var i=document.createElement("script");i.type="text/javascript",i.async=!0,i.src=e,i.addEventListener("load",function(){t({status:!0})},{once:!0}),i.addEventListener("error",function(){n({status:!1,message:"Failed to load the script ".concat(e)})}),null===(r=document.head)||void 0===r||r.appendChild(i)}catch(e){n(e)}})}(e).then(function(){}),this.scriptLoadPromises.set(e,n),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,n];case 2:return i.sent(),[3,4];case 3:throw r=i.sent(),this.scriptLoadPromises.delete(e),r;case 4:return[2]}})})},e.prototype.setup=function(e){var t,n,r=this,i=void 0===e?{}:e,o=i.logger,s=i.endpoint;o&&(this.logger=o),s&&this.endpoint===$&&(this.endpoint=s),this.isSetup||(this.isSetup=!0,null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Setting up messenger"),this.messageHandler=function(e){var t,n,i,o,s;if(null===(n=null===(t=r.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message received: ",JSON.stringify(e)),r.endpoint===e.origin){var a=e.data,l=null==a?void 0:a.action;if(l)if("id"in a&&a.id)null===(o=null===(i=r.logger)||void 0===i?void 0:i.debug)||void 0===o||o.call(i,"Received Response to previous request: ",JSON.stringify(e)),r.handleResponse(a);else{if("ping"===l)return void r.notify({action:"pong"});var c=r.actionHandlers.get(l);if(c)c(a.data);else{var u=null!==(s=r.pendingMessages.get(l))&&void 0!==s?s:[];u.push(a.data),r.pendingMessages.set(l,u)}}}},window.addEventListener("message",this.messageHandler),this.notify({action:"page-loaded"}))},e.prototype.destroy=function(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.isSetup=!1,this.actionHandlers.clear(),this.pendingMessages.clear(),this.requestCallbacks={},this.scriptLoadPromises.clear();var e=g();(null==e?void 0:e[Q])===this&&delete e[Q]},e}();function V(e){var t,n=g(),r=null==n?void 0:n[Q];if("object"==typeof(t=r)&&null!==t&&J in t&&!0===t[J])return r;var i=new G(e);return n&&(n[Q]=i),i}K=J;var Z="__AMPLITUDE_BACKGROUND_CAPTURE__";var Y,X="[Amplitude]",ee="".concat(X," Session Replay ID"),te=O.US,ne={enabled:!0},re=1e3,ie="".concat(X," Session Replay Debug"),oe="amp-mask",se="https://api-sr.amplitude.com/sessions/v2/track",ae="https://api-sr.eu.amplitude.com/sessions/v2/track",le="https://api-sr.stag2.amplitude.com/sessions/v2/track";!function(e){e.GET_SR_PROPS="get-sr-props",e.DEBUG_INFO="debug-info",e.FETCH_REQUEST="fetch-request",e.METADATA="metadata",e.TARGETING_DECISION="targeting-decision"}(Y||(Y={}));var ce=function(){function e(e){this.logger=e,this.log=this.getSafeMethod("log"),this.warn=this.getSafeMethod("warn"),this.error=this.getSafeMethod("error"),this.debug=this.getSafeMethod("debug")}return e.prototype.getSafeMethod=function(e){var t;if(!this.logger)return function(){};var n=this.logger[e];return"function"==typeof n?(null!==(t=n.__rrweb_original__)&&void 0!==t?t:n).bind(this.logger):function(){}},e.prototype.enable=function(e){this.logger.enable(e)},e.prototype.disable=function(){this.logger.disable()},e}(),ue="medium";function de(e,t){return t||("STAGING"===e?le:"EU"===e?ae:se)}var he=function(e,t,n){switch(t){case"light":if("input"!==e)return!0;var r=n?function(e){var t=e.type;return e.hasAttribute("data-rr-is-password")?"password":t?t.toLowerCase():null}(n):"";return!!r&&(!!["password","hidden","email","tel"].includes(r)||!!n.autocomplete.startsWith("cc-"));case"medium":case"conservative":return!0;default:return he(e,ue,n)}},ve=function(e,t){var n,r,i;if(e&&t.urlMaskLevels)try{for(var o=a(t.urlMaskLevels),s=o.next();!s.done;s=o.next()){var l=s.value;if(be(l.match).test(e))return l.maskLevel}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return null!==(i=t.defaultMaskLevel)&&void 0!==i?i:ue},ge=function(e,t,n,r){var i,o;if(void 0===t&&(t={defaultMaskLevel:ue}),n){if(n.closest("."+oe))return!0;var s=(null!==(i=t.maskSelector)&&void 0!==i?i:[]).some(function(e){return n.closest(e)});if(s)return!0;if(n.closest(".amp-unmask"))return!1;var a=(null!==(o=t.unmaskSelector)&&void 0!==o?o:[]).some(function(e){return n.closest(e)});if(a)return!1}return he(e,ve(r,t),n)},fe=function(e,t,n){return function(r,i){return ge(e,t,i,null==n?void 0:n())?r.replace(/[^\s]/g,"*"):r}},pe=function(e,t){return function(n,r,i){var o;return"style"===n?r:(null!==(o=null==e?void 0:e.maskAttributes)&&void 0!==o?o:[]).includes(n)&&ge("text",e,i,null==t?void 0:t())?r.replace(/[^\s]/g,"*"):r}},ye=function(){var e=g();return(null==e?void 0:e.location)?e.location.href:""},me=new Map,be=function(e){var t=me.get(e);if(t)return t;var n="\0TRAIL\0",r="\0MID\0",i="\0DS\0",o="\0ST\0",s="\0QU\0",a=e;a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=a.replace(/\/\*\*$/,n)).replace(/\/\*\*\//g,r)).replace(/\*\*/g,i)).replace(/\*/g,o)).replace(/\?/g,s)).replace(/[.+^${}()|[\]\\]/g,"\\$&")).split(n).join("(/.*)?")).split(r).join("/(.*\\/)?")).split(i).join(".*")).split(o).join(".*")).split(s).join(".");var l=new RegExp("^".concat(a,"$"));return me.set(e,l),l},Se=function(e,t){var n,r;try{for(var i=a(t),o=i.next();!o.done;o=i.next()){var s=o.value,l=be(s.selector);if(l.test(e))return e.replace(l,s.replacement)}}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(){return o(void 0,void 0,void 0,function(){var e,t,n,r,i,o,a;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),(e=g())?[4,e.navigator.storage.estimate()]:[3,2];case 1:return t=s.sent(),n=t.usage,r=t.quota,i=t.usageDetails,o=n?Math.round(n/1024):0,a=n&&r?Math.round(1e3*(n/r+Number.EPSILON))/1e3:0,[2,{totalStorageSize:o,percentOfQuota:a,usageDetails:JSON.stringify(i)}];case 2:return[3,4];case 3:return s.sent(),[3,4];case 4:return[2,{totalStorageSize:0,percentOfQuota:0,usageDetails:""}]}})})},we=function(e){var t=i({},e),n=t.apiKey;return t.apiKey="****".concat(n.substring(n.length-4)),t},Ce=function(){return{flushMaxRetries:2,logLevel:v.Warn,loggerProvider:new b,transportProvider:new A}},ke=function(e){function n(t,n){var r,o,s,a,l,c,u,d=this,h=Ce();if((d=e.call(this,i(i({transportProvider:h.transportProvider,loggerProvider:new ce(n.loggerProvider||h.loggerProvider)},n),{apiKey:t}))||this).flushMaxRetries=void 0!==n.flushMaxRetries&&n.flushMaxRetries<=h.flushMaxRetries?n.flushMaxRetries:h.flushMaxRetries,d.apiKey=t,d.sampleRate=n.sampleRate||0,d.serverZone=n.serverZone||te,d.configServerUrl=n.configServerUrl,d.trackServerUrl=n.trackServerUrl,d.shouldInlineStylesheet=n.shouldInlineStylesheet,d.version=n.version,d.performanceConfig=n.performanceConfig||ne,d.storeType=null!==(r=n.storeType)&&void 0!==r?r:"idb",d.applyBackgroundColorToBlockedElements=null!==(o=n.applyBackgroundColorToBlockedElements)&&void 0!==o&&o,d.enableUrlChangePolling=null!==(s=n.enableUrlChangePolling)&&void 0!==s&&s,d.urlChangePollingInterval=null!==(a=n.urlChangePollingInterval)&&void 0!==a?a:re,d.captureDocumentTitle=null!==(l=n.captureDocumentTitle)&&void 0!==l&&l,n.privacyConfig&&(d.privacyConfig=n.privacyConfig),n.interactionConfig&&(d.interactionConfig=n.interactionConfig,d.interactionConfig.ugcFilterRules&&function(e){if(!e.every(function(e){return"string"==typeof e.selector&&"string"==typeof e.replacement}))throw new Error("ugcFilterRules must be an array of objects with selector and replacement properties");if(!e.every(function(e){return"string"==typeof(t=e.selector)&&""!==t.trim()&&!!/^\/|^https?:\/\/[^\s]+$/.test(t);var t}))throw new Error("ugcFilterRules must be an array of objects with valid globs")}(d.interactionConfig.ugcFilterRules)),n.debugMode&&(d.debugMode=n.debugMode),void 0!==n.useWebWorker)d.useWebWorker=n.useWebWorker;else{var v=n;void 0!==(null===(c=v.experimental)||void 0===c?void 0:c.useWebWorker)&&(d.useWebWorker=v.experimental.useWebWorker)}return n.omitElementTags&&(d.omitElementTags=n.omitElementTags),d.captureAdoptedStyleSheets=null===(u=n.captureAdoptedStyleSheets)||void 0===u||u,d}return t(n,e),n}(I),Ee=(e=>(e[e.DomContentLoaded=0]="DomContentLoaded",e[e.Load=1]="Load",e[e.FullSnapshot=2]="FullSnapshot",e[e.IncrementalSnapshot=3]="IncrementalSnapshot",e[e.Meta=4]="Meta",e[e.Custom=5]="Custom",e[e.Plugin=6]="Plugin",e))(Ee||{}),Pe=(e=>(e[e.Mutation=0]="Mutation",e[e.MouseMove=1]="MouseMove",e[e.MouseInteraction=2]="MouseInteraction",e[e.Scroll=3]="Scroll",e[e.ViewportResize=4]="ViewportResize",e[e.Input=5]="Input",e[e.TouchMove=6]="TouchMove",e[e.MediaInteraction=7]="MediaInteraction",e[e.StyleSheetRule=8]="StyleSheetRule",e[e.CanvasMutation=9]="CanvasMutation",e[e.Font=10]="Font",e[e.Log=11]="Log",e[e.Drag=12]="Drag",e[e.StyleDeclaration=13]="StyleDeclaration",e[e.Selection=14]="Selection",e[e.AdoptedStyleSheet=15]="AdoptedStyleSheet",e[e.CustomElement=16]="CustomElement",e))(Pe||{}),Re=(e=>(e[e.MouseUp=0]="MouseUp",e[e.MouseDown=1]="MouseDown",e[e.Click=2]="Click",e[e.ContextMenu=3]="ContextMenu",e[e.DblClick=4]="DblClick",e[e.Focus=5]="Focus",e[e.Blur=6]="Blur",e[e.TouchStart=7]="TouchStart",e[e.TouchMove_Departed=8]="TouchMove_Departed",e[e.TouchEnd=9]="TouchEnd",e[e.TouchCancel=10]="TouchCancel",e))(Re||{}),Te=function(){function e(e,t){this.localConfig=t,this.remoteConfigClient=e}return e.prototype.generateJoinedConfig=function(){var e,t,n,r,u,d,h;return o(this,void 0,void 0,function(){var o,v,g,f,p,y,m,b,S,I,w,C,k,E,P,R,T,M=this;return s(this,function(s){switch(s.label){case 0:(o=i({},this.localConfig)).optOut=this.localConfig.optOut,o.captureEnabled=!0,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,new Promise(function(e,t){M.remoteConfigClient.subscribe("configs.sessionReplay","all",function(n,r){var i;if(M.localConfig.loggerProvider.debug("Session Replay remote configuration received from ".concat(r,":"),JSON.stringify(n,null,2)),n){var s=n,a=s.sr_sampling_config,l=s.sr_privacy_config,c=s.sr_targeting_config,u=null===(i=o.interactionConfig)||void 0===i?void 0:i.ugcFilterRules;o.interactionConfig=s.sr_interaction_config,o.interactionConfig&&u&&(o.interactionConfig.ugcFilterRules=u),o.loggingConfig=s.sr_logging_config,(a||l||c)&&(v={},a&&(v.sr_sampling_config=a),l&&(v.sr_privacy_config=l),c&&(v.sr_targeting_config=c)),e()}else t(new Error("No remote config received"))})})];case 2:return s.sent(),[3,4];case 3:return g=s.sent(),this.localConfig.loggerProvider.error("Failed to generate joined config: ",g),o.captureEnabled=!1,[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:void 0}];case 4:if(!v)return[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:v}];if(f=v.sr_sampling_config,p=v.sr_privacy_config,y=v.sr_targeting_config,f&&Object.keys(f).length>0?(Object.prototype.hasOwnProperty.call(f,"capture_enabled")?o.captureEnabled=f.capture_enabled:o.captureEnabled=!1,Object.prototype.hasOwnProperty.call(f,"sample_rate")&&(o.sampleRate=f.sample_rate)):(o.captureEnabled=!0,this.localConfig.loggerProvider.debug("Remote config successfully fetched, but no values set for project, Session Replay capture enabled.")),p){m=null!==(e=o.privacyConfig)&&void 0!==e?e:{},b={defaultMaskLevel:null!==(n=null!==(t=p.defaultMaskLevel)&&void 0!==t?t:m.defaultMaskLevel)&&void 0!==n?n:"medium",blockSelector:[],maskSelector:[],unmaskSelector:[],maskAttributes:c([],l(new Set(c(c([],l(null!==(r=m.maskAttributes)&&void 0!==r?r:[]),!1),l(null!==(u=p.maskAttributes)&&void 0!==u?u:[]),!1))),!1),urlMaskLevels:c(c([],l(null!==(d=p.urlMaskLevels)&&void 0!==d?d:[]),!1),l(null!==(h=m.urlMaskLevels)&&void 0!==h?h:[]),!1)},S=function(e){var t,n,r,i,o,s,l,c,u,d={};"string"==typeof e.blockSelector&&(e.blockSelector=[e.blockSelector]);try{for(var h=a(null!==(l=e.blockSelector)&&void 0!==l?l:[]),v=h.next();!v.done;v=h.next()){d[v.value]="block"}}catch(e){t={error:e}}finally{try{v&&!v.done&&(n=h.return)&&n.call(h)}finally{if(t)throw t.error}}try{for(var g=a(null!==(c=e.maskSelector)&&void 0!==c?c:[]),f=g.next();!f.done;f=g.next()){d[f.value]="mask"}}catch(e){r={error:e}}finally{try{f&&!f.done&&(i=g.return)&&i.call(g)}finally{if(r)throw r.error}}try{for(var p=a(null!==(u=e.unmaskSelector)&&void 0!==u?u:[]),y=p.next();!y.done;y=p.next()){d[y.value]="unmask"}}catch(e){o={error:e}}finally{try{y&&!y.done&&(s=p.return)&&s.call(p)}finally{if(o)throw o.error}}return d},I=i(i({},S(m)),S(p));try{for(w=a(Object.entries(I)),C=w.next();!C.done;C=w.next())k=l(C.value,2),E=k[0],"mask"===(P=k[1])?b.maskSelector.push(E):"block"===P?b.blockSelector.push(E):"unmask"===P&&b.unmaskSelector.push(E)}catch(e){R={error:e}}finally{try{C&&!C.done&&(T=w.return)&&T.call(w)}finally{if(R)throw R.error}}o.privacyConfig=(x=b,_=this.localConfig.loggerProvider,O=document.createDocumentFragment(),L=function(e){if(void 0===e&&(e=[]),"string"==typeof e&&(e=[e]),e=e.filter(function(e){try{O.querySelector(e)}catch(t){return _.warn('[session-replay-browser] omitting selector "'.concat(e,'" because it is invalid')),!1}return!0}),0!==e.length)return e},x.blockSelector=L(x.blockSelector),x.maskSelector=L(x.maskSelector),x.unmaskSelector=L(x.unmaskSelector),x)}return y&&Object.keys(y).length>0&&(o.targetingConfig=y),this.localConfig.loggerProvider.debug(JSON.stringify({name:"session replay joined config",config:we(o)},null,2)),[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:v}]}var x,_,O,L})})},e}(),Me=function(e,t){return o(void 0,void 0,void 0,function(){var n,r;return s(this,function(i){return n=new ke(e,t),r=new z(e,n.loggerProvider,n.serverZone,t.configServerUrl),[2,new Te(r,n)]})})};function xe(e){if(e.type!==Ee.IncrementalSnapshot)return!1;var t=e.data;return t.source===Pe.Mutation&&!t.isAttachIframe}function _e(e){var t,n,r,o,s=e[0],c=new Map,u=new Map,d=new Map,h=new Map,v=new Map;e.forEach(function(e,t){var n,r,i,o,s=e.data;try{for(var l=a(s.adds),g=l.next();!g.done;g=l.next()){var f=g.value;c.has(f.node.id)||c.set(f.node.id,t),u.set(f.node.id,t),v.set(f.node.id,f.parentId)}}catch(e){n={error:e}}finally{try{g&&!g.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}try{for(var p=a(s.removes),y=p.next();!y.done;y=p.next()){var m=y.value;d.has(m.id)||d.set(m.id,t),h.set(m.id,t)}}catch(e){i={error:e}}finally{try{y&&!y.done&&(o=p.return)&&o.call(p)}finally{if(i)throw i.error}}});var g=new Set,f=new Set;try{for(var p=a(c),y=p.next();!y.done;y=p.next()){var m=l(y.value,2),b=m[0],S=m[1],I=d.get(b);if(void 0!==I)u.get(b)>=h.get(b)||(S<I?g.add(b):I<S&&f.add(b))}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=p.return)&&n.call(p)}finally{if(t)throw t.error}}var w=new Set;if(g.size>0||f.size>0)for(var C=!0;C;){C=!1;try{for(var k=(r=void 0,a(v)),E=k.next();!E.done;E=k.next()){var P=l(E.value,2),R=P[0],T=P[1];if(!g.has(R)&&!f.has(R)&&!w.has(R)&&(g.has(T)||f.has(T)||w.has(T))){var M=d.get(R),x=c.get(R);void 0!==M&&void 0!==x&&M<x?f.add(R):void 0!==M&&void 0!==x&&M===x?w.add(R):g.add(R),C=!0}}}catch(e){r={error:e}}finally{try{E&&!E.done&&(o=k.return)&&o.call(k)}finally{if(r)throw r.error}}}var _=g.size>0||f.size>0||w.size>0,O=[];e.forEach(function(e,t){var n,r;try{for(var i=a(e.data.removes),o=i.next();!o.done;o=i.next()){var s=o.value;g.has(s.id)||(f.has(s.id)&&t>=c.get(s.id)||w.has(s.id)&&(g.has(s.parentId)||f.has(s.parentId)||w.has(s.parentId))||O.push(s))}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}});var L=e.flatMap(function(e){return e.data.adds}),D=e.flatMap(function(e){return e.data.texts}),F=e.flatMap(function(e){return e.data.attributes}),N={source:Pe.Mutation,removes:O,adds:_?L.filter(function(e){return!g.has(e.node.id)&&!f.has(e.node.id)&&!w.has(e.node.id)}):L,texts:_?D.filter(function(e){return!g.has(e.id)&&!f.has(e.id)&&!w.has(e.id)}):D,attributes:_?F.filter(function(e){return!g.has(e.id)&&!f.has(e.id)&&!w.has(e.id)}):F};return i(i({},s),{data:N})}function Oe(e){if(e.length<=1)return e;for(var t=[],n=0;n<e.length;)if(xe(e[n])){for(var r=n+1;r<e.length&&xe(e[r]);)r++;t.push(r>n+1?_e(e.slice(n,r)):e[n]),n=r}else t.push(e[n]),n++;return t}var Le=function(){function e(e,t,n,r,i){var o,s=this;this.taskQueue=[],this.pendingQueue=[],this.isProcessing=!1,this.compressEvent=function(e){var t=e,n=t.type,r=t.timestamp,i=t.delay,o=t.data;return null!=i?JSON.stringify({type:n,timestamp:r,delay:i,data:o}):JSON.stringify({type:n,timestamp:r,data:o})},this.addCompressedEventToManager=function(e,t){s.eventsManager&&s.deviceId&&s.eventsManager.addEvent({event:{type:"replay",data:e},sessionId:t,deviceId:s.deviceId})},this.addCompressedEvent=function(e,t){if(s.worker)try{s.worker.postMessage({event:e,sessionId:t})}catch(n){"DataCloneError"===n.name?s.worker.postMessage(JSON.stringify({event:e,sessionId:t})):s.config.loggerProvider.warn("Unexpected error while posting message to worker:",n)}else{var n=s.compressEvent(e);s.addCompressedEventToManager(n,t)}},this.terminate=function(){var e;null===(e=s.worker)||void 0===e||e.terminate()};var a=g();if(this.canUseIdleCallback=a&&"requestIdleCallback"in a,this.eventsManager=e,this.config=t,this.deviceId=n,this.timeout=(null===(o=t.performanceConfig)||void 0===o?void 0:o.timeout)||2e3,this.onFullSnapshotProcessed=i,r){t.loggerProvider.log("Enabling web worker for compression");try{var l=new Blob([r],{type:"application/javascript"}),c=URL.createObjectURL(l),u=new Worker(c);u.onerror=function(e){e.preventDefault(),t.loggerProvider.error("Worker failed, falling back to non-worker compression: ".concat(e.message," (").concat(e.filename,":").concat(e.lineno,")")),u.terminate(),s.worker=void 0},u.onmessage=function(e){var t=e.data,n=t.compressedEvent,r=t.sessionId;s.addCompressedEventToManager(n,r)},this.worker=u}catch(e){t.loggerProvider.error("Failed to create worker, falling back to non-worker compression:",e)}}}return e.prototype.scheduleIdleProcessing=function(){var e=this;this.isProcessing||(this.isProcessing=!0,requestIdleCallback(function(t){e.processQueue(t)},{timeout:this.timeout}))},e.prototype.enqueueEvent=function(e,t){var n,r,i,o;if(e.type===Ee.FullSnapshot){if(this.config.loggerProvider.debug("Processing full snapshot immediately."),this.taskQueue.length>0||this.pendingQueue.length>0){var s=c(c([],l(this.taskQueue.splice(0)),!1),l(this.mergeMutationTasks(this.pendingQueue.splice(0))),!1);try{for(var u=a(s),d=u.next();!d.done;d=u.next()){var h=d.value,v=this.compressEvent(h.event);this.addCompressedEventToManager(v,h.sessionId)}}catch(e){n={error:e}}finally{try{d&&!d.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}this.isProcessing=!1}var g=this.compressEvent(e);return this.addCompressedEventToManager(g,t),void(null===(i=this.onFullSnapshotProcessed)||void 0===i||i.call(this))}this.canUseIdleCallback&&(null===(o=this.config.performanceConfig)||void 0===o?void 0:o.enabled)?(this.config.loggerProvider.debug("Enqueuing event for processing during idle time."),this.pendingQueue.push({event:e,sessionId:t}),this.scheduleIdleProcessing()):(this.config.loggerProvider.debug("Processing event without idle callback."),this.addCompressedEvent(e,t))},e.prototype.processQueue=function(e){var t,n=this;for(this.pendingQueue.length>0&&(t=this.taskQueue).push.apply(t,c([],l(this.mergeMutationTasks(this.pendingQueue.splice(0))),!1));this.taskQueue.length>0&&(e.timeRemaining()>0||e.didTimeout);){var r=this.taskQueue.shift();if(r){var i=r.event,o=r.sessionId;this.addCompressedEvent(i,o)}}this.taskQueue.length>0||this.pendingQueue.length>0?requestIdleCallback(function(e){n.processQueue(e)},{timeout:this.timeout}):this.isProcessing=!1},e.prototype.mergeMutationTasks=function(e){var t,n,r;if(!(null===(r=this.config.performanceConfig)||void 0===r?void 0:r.mergeMutations))return e;if(e.length<=1)return e;for(var i=[],o=0;o<e.length;){for(var s=e[o].sessionId,l=o+1;l<e.length&&e[l].sessionId===s;)l++;var c=Oe(e.slice(o,l).map(function(e){return e.event}));try{for(var u=(t=void 0,a(c)),d=u.next();!d.done;d=u.next()){var h=d.value;i.push({event:h,sessionId:s})}}catch(e){t={error:e}}finally{try{d&&!d.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}o=l}return i},e}(),De="Session replay event batch rejected due to exceeded retry count",Fe="Failed to store session replay events in IndexedDB",Ne="1.39.0";function Ue(e,t){return o(this,void 0,void 0,function(){var n,r,i,l,c,u,d,h,v,g,f,p,y,m,b=this;return s(this,function(S){switch(S.label){case 0:return S.trys.push([0,4,,5]),n=t.CompressionStream,r=new n("gzip"),i=r.writable.getWriter(),l=r.readable.getReader(),c=[],u=o(b,void 0,void 0,function(){var e,t,n;return s(this,function(r){switch(r.label){case 0:return[4,l.read()];case 1:if(e=r.sent(),t=e.done,n=e.value,t)return[3,3];c.push(n),r.label=2;case 2:return[3,0];case 3:return[2]}})}),[4,i.write((new TextEncoder).encode(e))];case 1:return S.sent(),[4,i.close()];case 2:return S.sent(),[4,u];case 3:S.sent(),d=c.reduce(function(e,t){return e+t.length},0),h=new Uint8Array(d),v=0;try{for(g=a(c),f=g.next();!f.done;f=g.next())p=f.value,h.set(p,v),v+=p.length}catch(e){y={error:e}}finally{try{f&&!f.done&&(m=g.return)&&m.call(g)}finally{if(y)throw y.error}}return[2,h];case 4:return S.sent(),[2,null];case 5:return[2]}})})}var Ae=function(){function e(e){var t=e.trackServerUrl,n=e.loggerProvider,r=e.payloadBatcher,i=e.workerScript,o=this;if(this.storageKey="",this.retryTimeout=1e3,this.scheduled=null,this.queue=[],this.sendIdCounter=0,this.pendingWorkerRequests=new Map,this.loggerProvider=n,this.payloadBatcher=r||function(e){return e},this.trackServerUrl=t,i)try{var s=new Blob([i],{type:"application/javascript"}),c=URL.createObjectURL(s),u=new Worker(c);u.onerror=function(e){var t,r;e.preventDefault(),n.error("Track destination worker failed, falling back to main-thread sending: ".concat(e.message," (").concat(e.filename,":").concat(e.lineno,")")),u.terminate(),o.worker=void 0;try{for(var i=a(o.pendingWorkerRequests),s=i.next();!s.done;s=i.next()){var c=l(s.value,2)[1];n.warn("Session replay event send failed due to worker crash: ".concat(e.message)),c.resolve()}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}o.pendingWorkerRequests.clear()},u.onmessage=function(e){var t=e.data;if("log"===t.type)n.log(t.message);else if("warn"===t.type)n.warn(t.message);else if("complete"===t.type){var r=o.pendingWorkerRequests.get(t.id);r&&(o.completeRequest({context:r.context}),r.resolve(),o.pendingWorkerRequests.delete(t.id))}},this.worker=u}catch(e){n.error("Failed to create track destination worker, falling back to main-thread sending:",e)}}return e.prototype.sendEventsList=function(e){this.addToQueue(i(i({},e),{attempts:0,timeout:0}))},e.prototype.sendBeacon=function(e){var t,n,r=e.events,i=e.sessionId,o=e.deviceId,s=e.apiKey,a=e.serverZone,l=function(e){return new Blob([e]).size},c=r,u=JSON.stringify({version:2,events:c});if(l(u)>65536){for(var d=0,h=c.length;d<h;){var v=Math.floor((d+h+1)/2);l(JSON.stringify({version:2,events:c.slice(0,v)}))<=65536?d=v:h=v-1}c=c.slice(0,d),u=JSON.stringify({version:2,events:c}),this.loggerProvider.warn("sendBeacon payload exceeded 64 KB limit, trimmed from ".concat(r.length," to ").concat(c.length," events"))}if(0!==c.length){var f=new URLSearchParams({device_id:o,session_id:String(i),type:"replay",api_key:s}),p="".concat(de(a,this.trackServerUrl),"?").concat(f.toString()),y=g();try{var m=new Blob([u],{type:"application/json"});!1===(null===(n=null===(t=null==y?void 0:y.navigator)||void 0===t?void 0:t.sendBeacon)||void 0===n?void 0:n.call(t,p,m))&&this.loggerProvider.warn("sendBeacon failed to queue session replay payload")}catch(e){}}},e.prototype.addToQueue=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];t.filter(function(t){return t.attempts<(t.flushMaxRetries||0)?(t.attempts+=1,!0):(e.completeRequest({context:t,err:De}),!1)}).forEach(function(t){e.queue=e.queue.concat(t),e.schedule(0)})},e.prototype.schedule=function(e){var t=this;this.scheduled||(this.scheduled=setTimeout(function(){t.flush(!0).then(function(){t.queue.length>0&&t.schedule(e)})},e))},e.prototype.flush=function(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var t,n,r,i,o,l,c;return s(this,function(s){switch(s.label){case 0:t=this.queue,this.queue=[],this.scheduled&&(clearTimeout(this.scheduled),this.scheduled=null),s.label=1;case 1:s.trys.push([1,6,7,8]),n=a(t),r=n.next(),s.label=2;case 2:return r.done?[3,5]:(i=r.value,[4,this.send(i,e)]);case 3:s.sent(),s.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=s.sent(),l={error:o},[3,8];case 7:try{r&&!r.done&&(c=n.return)&&c.call(n)}finally{if(l)throw l.error}return[7];case 8:return[2]}})})},e.prototype.send=function(e,t){return void 0===t&&(t=!0),o(this,void 0,void 0,function(){var n,r,i,o;return s(this,function(s){return(n=e.apiKey)?(r=e.deviceId)?0===(i=this.payloadBatcher({version:1,events:e.events})).events.length?(this.completeRequest({context:e}),[2]):(o=this.worker)?[2,this.sendViaWorker(o,e,i,t)]:[2,this.sendOnMainThread(n,r,e,i,t)]:[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing device ID"})]:[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing api key"})]})})},e.prototype.sendViaWorker=function(e,t,n,r){return o(this,void 0,void 0,function(){var i,o=this;return s(this,function(s){return i="".concat(++this.sendIdCounter),[2,new Promise(function(s){var a;o.pendingWorkerRequests.set(i,{context:t,resolve:s}),e.postMessage({type:"send",id:i,payload:n,useRetry:r,context:{apiKey:t.apiKey,deviceId:t.deviceId,sessionId:t.sessionId,events:t.events,eventType:t.type,flushMaxRetries:null!==(a=t.flushMaxRetries)&&void 0!==a?a:0,sampleRate:t.sampleRate,serverZone:t.serverZone,trackServerUrl:o.trackServerUrl,version:t.version,currentUrl:ye(),sdkVersion:Ne}})})]})})},e.prototype.sendOnMainThread=function(e,t,n,r,a){var l,c,u,d;return o(this,void 0,void 0,function(){var o,h,v,f,p,y,m,b,S,I,w,C,k,E;return s(this,function(s){switch(s.label){case 0:o=ye(),h=Ne,v=n.sampleRate,f=new URLSearchParams({device_id:t,session_id:"".concat(n.sessionId),type:"".concat(n.type)}),p="".concat(null!==(c=null===(l=n.version)||void 0===l?void 0:l.type)&&void 0!==c?c:"standalone","/").concat(null!==(d=null===(u=n.version)||void 0===u?void 0:u.version)&&void 0!==d?d:h),s.label=1;case 1:return s.trys.push([1,9,,10]),y=JSON.stringify(r),(m=g())&&"CompressionStream"in m?[4,Ue(y,m)]:[3,3];case 2:return S=s.sent(),[3,4];case 3:S=null,s.label=4;case 4:return b=S,I={headers:i({"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(e),"X-Client-Version":h,"X-Client-Library":p,"X-Client-Url":o.substring(0,1e3),"X-Client-Sample-Rate":"".concat(v),"X-Sampling-Hash-Alg":"xxhash32"},b?{"Content-Encoding":"gzip"}:{}),body:null!=b?b:y,method:"POST"},w="".concat(de(n.serverZone,this.trackServerUrl),"?").concat(f.toString()),[4,fetch(w,I)];case 5:if(null===(C=s.sent()))return this.completeRequest({context:n,err:"Unexpected error occurred"}),[2];if(a)return[3,6];k="";try{k=JSON.stringify(C.body,null,2)}catch(e){}return this.completeRequest({context:n,success:"".concat(C.status,": ").concat(k)}),[3,8];case 6:return[4,this.handleReponse(C.status,n)];case 7:s.sent(),s.label=8;case 8:return[3,10];case 9:return E=s.sent(),this.completeRequest({context:n,err:E}),[3,10];case 10:return[2]}})})},e.prototype.handleReponse=function(e,t){return o(this,void 0,void 0,function(){var n;return s(this,function(r){switch(r.label){case 0:switch(n=(new U).buildStatus(e),n){case u.Success:return[3,1];case u.Failed:case u.Timeout:case u.RateLimit:return[3,2]}return[3,4];case 1:return this.handleSuccessResponse(t),[3,7];case 2:return[4,this.handleOtherResponse(t)];case 3:return r.sent(),[3,7];case 4:return 499!==e?[3,6]:[4,this.handleOtherResponse(t)];case 5:return r.sent(),[3,7];case 6:this.completeRequest({context:t,err:"Network error occurred, event batch rejected"}),r.label=7;case 7:return[2]}})})},e.prototype.handleSuccessResponse=function(e){var t=Math.round(new Blob(e.events).size/1024);this.completeRequest({context:e,success:"Session replay event batch tracked successfully for session id ".concat(e.sessionId,", size of events: ").concat(t," KB")})},e.prototype.handleOtherResponse=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=Math.random()*e.attempts*this.retryTimeout,e.attempts++,e.attempts>(e.flushMaxRetries||0)?(this.completeRequest({context:e,err:De}),[2]):[4,new Promise(function(e){return setTimeout(e,t)})];case 1:return n.sent(),[4,this.send(e,!0)];case 2:return n.sent(),[2]}})})},e.prototype.completeRequest=function(e){var t=e.context,n=e.err,r=e.success;t.onComplete(),n?this.loggerProvider.warn(n):r&&this.loggerProvider.log(r)},e}();const qe=(e,t)=>t.some(t=>e instanceof t);let je,Be;const We=new WeakMap,ze=new WeakMap,Ke=new WeakMap;let $e={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return We.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return Ge(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function He(e){$e=e($e)}function Je(e){return(Be||(Be=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(Ve(this),t),Ge(this.request)}:function(...t){return Ge(e.apply(Ve(this),t))}}function Qe(e){return"function"==typeof e?Je(e):(e instanceof IDBTransaction&&function(e){if(We.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",i),e.removeEventListener("error",o),e.removeEventListener("abort",o)},i=()=>{t(),r()},o=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",i),e.addEventListener("error",o),e.addEventListener("abort",o)});We.set(e,t)}(e),qe(e,je||(je=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,$e):e)}function Ge(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",i),e.removeEventListener("error",o)},i=()=>{t(Ge(e.result)),r()},o=()=>{n(e.error),r()};e.addEventListener("success",i),e.addEventListener("error",o)});return Ke.set(t,e),t}(e);if(ze.has(e))return ze.get(e);const t=Qe(e);return t!==e&&(ze.set(e,t),Ke.set(t,e)),t}const Ve=e=>Ke.get(e);function Ze(e,t,{blocked:n,upgrade:r,blocking:i,terminated:o}={}){const s=indexedDB.open(e,t),a=Ge(s);return r&&s.addEventListener("upgradeneeded",e=>{r(Ge(s.result),e.oldVersion,e.newVersion,Ge(s.transaction),e)}),n&&s.addEventListener("blocked",e=>n(e.oldVersion,e.newVersion,e)),a.then(e=>{o&&e.addEventListener("close",()=>o()),i&&e.addEventListener("versionchange",e=>i(e.oldVersion,e.newVersion,e))}).catch(()=>{}),a}const Ye=["get","getKey","getAll","getAllKeys","count"],Xe=["put","add","delete","clear"],et=new Map;function tt(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(et.get(t))return et.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,i=Xe.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!i&&!Ye.includes(n))return;const o=async function(e,...t){const o=this.transaction(e,i?"readwrite":"readonly");let s=o.store;return r&&(s=s.index(t.shift())),(await Promise.all([s[n](...t),i&&o.done]))[0]};return et.set(t,o),o}He(e=>({...e,get:(t,n,r)=>tt(t,n)||e.get(t,n,r),has:(t,n)=>!!tt(t,n)||e.has(t,n)}));const nt=["continue","continuePrimaryKey","advance"],rt={},it=new WeakMap,ot=new WeakMap,st={get(e,t){if(!nt.includes(t))return e[t];let n=rt[t];return n||(n=rt[t]=function(...e){it.set(this,ot.get(this)[t](...e))}),n}};async function*at(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,st);for(ot.set(n,t),Ke.set(n,Ve(t));t;)yield n,t=await(it.get(n)||t.continue()),it.delete(n)}function lt(e,t){return t===Symbol.asyncIterator&&qe(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&qe(e,[IDBIndex,IDBObjectStore])}He(e=>({...e,get:(t,n,r)=>lt(t,n)?at:e.get(t,n,r),has:(t,n)=>lt(t,n)||e.has(t,n)}));var ct,ut,dt,ht=function(){function e(e){var t,n,r,i=this;this.minInterval=500,this.maxInterval=1e4,this.maxPersistedEventsSize=1e6,this.interval=this.minInterval,this._timeAtLastSplit=Date.now(),this.shouldSplitEventsList=function(e,t){var n=i.getStringSize(t);return i.getEventsArraySize(e)+n>=i.maxPersistedEventsSize||!!(Date.now()-i.timeAtLastSplit>i.interval&&e.length)&&(i.interval=Math.min(i.maxInterval,i.interval+i.minInterval),i._timeAtLastSplit=Date.now(),!0)},this.loggerProvider=e.loggerProvider,this.minInterval=null!==(t=e.minInterval)&&void 0!==t?t:this.minInterval,this.maxInterval=null!==(n=e.maxInterval)&&void 0!==n?n:this.maxInterval,this.maxPersistedEventsSize=null!==(r=e.maxPersistedEventsSize)&&void 0!==r?r:this.maxPersistedEventsSize}return Object.defineProperty(e.prototype,"timeAtLastSplit",{get:function(){return this._timeAtLastSplit},enumerable:!1,configurable:!0}),e.prototype.getStringSize=function(e){return e.length},e.prototype.getEventsArraySize=function(e){var t,n,r=0;try{for(var i=a(e),o=i.next();!o.done;o=i.next()){var s=o.value;r+=this.getStringSize(s)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return r+(2+Math.max(0,e.length-1)+2*e.length)},e}(),vt=function(e,t,n){var r;"object"==typeof(r=n)&&null!==r&&"AbortError"===r.name?e.debug(t):e.warn(t)},gt="sessionCurrentSequence",ft="sequencesToSend",pt=function(e){var t,n;return e.objectStoreNames.contains(gt)||(n=e.createObjectStore(gt,{keyPath:"sessionId"})),e.objectStoreNames.contains(ft)||(t=e.createObjectStore(ft,{keyPath:"sequenceId",autoIncrement:!0})).createIndex("sessionId","sessionId"),{sequencesStore:t,currentSequenceStore:n}},yt=function(e){return o(void 0,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,Ze(e,1,{upgrade:pt})];case 1:return[2,t.sent()]}})})},mt=function(e){function n(t){var n,r=this;return(r=e.call(this,t)||this).consecutiveFailures=0,r.hasTriggeredFallback=!1,r.getSequencesToSend=function(){return o(r,void 0,void 0,function(){var e,t,n,r,i,o,a,l,c=this;return s(this,function(s){switch(s.label){case 0:e=!1,s.label=1;case 1:return s.trys.push([1,6,,7]),t=[],(n=this.db.transaction("sequencesToSend")).done.catch(function(t){e||vt(c.loggerProvider,"".concat(Fe,": ").concat(t),t)}),[4,n.store.openCursor()];case 2:r=s.sent(),s.label=3;case 3:return r?(i=r.value,o=i.sessionId,a=i.events,t.push({events:a,sequenceId:r.key,sessionId:o}),[4,r.continue()]):[3,5];case 4:return r=s.sent(),[3,3];case 5:return this.recordSuccess(),[2,t];case 6:return l=s.sent(),e=!0,vt(this.loggerProvider,"".concat(Fe,": ").concat(l),l),this.recordFailure(),[3,7];case 7:return[2,void 0]}})})},r.storeCurrentSequence=function(e){return o(r,void 0,void 0,function(){var t,n,r;return s(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,this.db.get(gt,e)];case 1:return(t=o.sent())?[4,this.db.put(ft,{sessionId:e,events:t.events})]:(this.recordSuccess(),[2,void 0]);case 2:return n=o.sent(),[4,this.db.put(gt,{sessionId:e,events:[]})];case 3:return o.sent(),this.recordSuccess(),[2,i(i({},t),{sessionId:e,sequenceId:n})];case 4:return r=o.sent(),vt(this.loggerProvider,"".concat(Fe,": ").concat(r),r),this.recordFailure(),[3,5];case 5:return[2,void 0]}})})},r.addEventToCurrentSequence=function(e,t){return o(r,void 0,void 0,function(){var n,r,i,o,a,l,c=this;return s(this,function(s){switch(s.label){case 0:n=!1,s.label=1;case 1:return s.trys.push([1,9,,10]),(r=this.db.transaction([gt,ft],"readwrite")).done.catch(function(e){n||vt(c.loggerProvider,"".concat(Fe,": ").concat(e),e)}),[4,r.objectStore(gt).get(e)];case 2:return(i=s.sent())?[3,4]:[4,r.objectStore(gt).put({sessionId:e,events:[t]})];case 3:return s.sent(),this.recordSuccess(),[2,void 0];case 4:return this.shouldSplitEventsList(i.events,t)?[3,6]:[4,r.objectStore(gt).put({sessionId:e,events:i.events.concat(t)})];case 5:return s.sent(),this.recordSuccess(),[2,void 0];case 6:return o=i.events,[4,r.objectStore(gt).put({sessionId:e,events:[t]})];case 7:return s.sent(),[4,r.objectStore(ft).put({sessionId:e,events:o})];case 8:return a=s.sent(),this.recordSuccess(),[2,{events:o,sessionId:e,sequenceId:a}];case 9:return l=s.sent(),n=!0,vt(this.loggerProvider,"".concat(Fe,": ").concat(l),l),this.recordFailure(),[3,10];case 10:return[2,void 0]}})})},r.storeSendingEvents=function(e,t){return o(r,void 0,void 0,function(){var n,r;return s(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.db.put(ft,{sessionId:e,events:t})];case 1:return n=i.sent(),this.recordSuccess(),[2,n];case 2:return r=i.sent(),vt(this.loggerProvider,"".concat(Fe,": ").concat(r),r),this.recordFailure(),[3,3];case 3:return[2,void 0]}})})},r.cleanUpSessionEventsStore=function(e,t){return o(r,void 0,void 0,function(){var e;return s(this,function(n){switch(n.label){case 0:if(!t)return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.db.delete(ft,t)];case 2:return n.sent(),this.recordSuccess(),[3,4];case 3:return e=n.sent(),vt(this.loggerProvider,"".concat(Fe,": ").concat(e),e),this.recordFailure(),[3,4];case 4:return[2]}})})},r.db=t.db,r.onPersistentFailure=t.onPersistentFailure,r.consecutiveFailureThreshold=null!==(n=t.consecutiveFailureThreshold)&&void 0!==n?n:3,r}return t(n,e),n.prototype.recordFailure=function(){var e;this.consecutiveFailures++,!this.hasTriggeredFallback&&this.consecutiveFailures>=this.consecutiveFailureThreshold&&(this.hasTriggeredFallback=!0,null===(e=this.onPersistentFailure)||void 0===e||e.call(this))},n.prototype.recordSuccess=function(){this.consecutiveFailures=0},n.new=function(e,t){return o(this,void 0,void 0,function(){var r,o,a,l;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),r="replay"===e?"":"_".concat(e),o="".concat(t.apiKey.substring(0,10),"_amp_session_replay_events").concat(r),[4,yt(o)];case 1:return a=s.sent(),[2,new n(i(i({},t),{db:a}))];case 2:return l=s.sent(),vt(t.loggerProvider,"".concat(Fe,": ").concat(l),l),[3,3];case 3:return[2]}})})},n.prototype.getCurrentSequenceEvents=function(e){return o(this,void 0,void 0,function(){var t,n,r,i,o,l,c;return s(this,function(s){switch(s.label){case 0:return e?[4,this.db.get("sessionCurrentSequence",e)]:[3,2];case 1:return(i=s.sent())?[2,[i]]:[2,void 0];case 2:t=[],s.label=3;case 3:return s.trys.push([3,8,9,10]),[4,this.db.getAll("sessionCurrentSequence")];case 4:n=a.apply(void 0,[s.sent()]),r=n.next(),s.label=5;case 5:if(r.done)return[3,7];i=r.value,t.push(i),s.label=6;case 6:return r=n.next(),[3,5];case 7:return[3,10];case 8:return o=s.sent(),l={error:o},[3,10];case 9:try{r&&!r.done&&(c=n.return)&&c.call(n)}finally{if(l)throw l.error}return[7];case 10:return[2,t]}})})},n}(ht),bt=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.finalizedSequences={},t.sequences={},t.sequenceId=0,t}return t(n,e),n.prototype.resetCurrentSequence=function(e){this.sequences[e]=[]},n.prototype.addSequence=function(e){var t=this.sequenceId++,n=c([],l(this.sequences[e]),!1);return this.finalizedSequences[t]={sessionId:e,events:n},this.resetCurrentSequence(e),{sequenceId:t,events:n,sessionId:e}},n.prototype.getSequencesToSend=function(){return o(this,void 0,void 0,function(){return s(this,function(e){return[2,Object.entries(this.finalizedSequences).map(function(e){var t=l(e,2),n=t[0],r=t[1],i=r.sessionId,o=r.events;return{sequenceId:Number(n),sessionId:i,events:o}})]})})},n.prototype.storeCurrentSequence=function(e){return o(this,void 0,void 0,function(){return s(this,function(t){return this.sequences[e]?[2,this.addSequence(e)]:[2,void 0]})})},n.prototype.addEventToCurrentSequence=function(e,t){return o(this,void 0,void 0,function(){var n;return s(this,function(r){return this.sequences[e]||this.resetCurrentSequence(e),this.shouldSplitEventsList(this.sequences[e],t)&&(n=this.addSequence(e)),this.sequences[e].push(t),[2,n]})})},n.prototype.storeSendingEvents=function(e,t){return o(this,void 0,void 0,function(){return s(this,function(n){return this.finalizedSequences[this.sequenceId]={sessionId:e,events:t},[2,this.sequenceId++]})})},n.prototype.cleanUpSessionEventsStore=function(e,t){return o(this,void 0,void 0,function(){return s(this,function(e){return void 0!==t&&delete this.finalizedSequences[t],[2]})})},n}(ht),St=function(e){var t=e.config,n=e.minInterval,r=e.maxInterval,a=e.type,u=e.payloadBatcher,d=e.storeType,h=e.trackDestinationWorkerScript;return o(void 0,void 0,void 0,function(){function e(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){return s(this,function(t){return[2,v.flush(e)]})})}var v,g,f,p,y,m,b,S,I,w,C,k,E,P,R;return s(this,function(T){switch(T.label){case 0:return v=new Ae(i(i({},t),{loggerProvider:t.loggerProvider,payloadBatcher:u,workerScript:h})),g=function(){return new bt({loggerProvider:t.loggerProvider,maxInterval:r,minInterval:n})},p=!1,m=function(){return o(void 0,void 0,void 0,function(){var e,n,r;return s(this,function(i){switch(i.label){case 0:return p?(p=!1,t.loggerProvider.warn("IDB store is experiencing repeated failures; falling back to in-memory event store."),f?[4,y.getSequencesToSend()]:[3,2]):[2];case 1:return n=i.sent(),[3,3];case 2:n=void 0,i.label=3;case 3:return e=n,y=g(),e&&f&&(r=f,e.forEach(function(e){k({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:r})})),[2]}})})},b=function(){return o(void 0,void 0,void 0,function(){var e;return s(this,function(i){switch(i.label){case 0:return[4,mt.new(a,{loggerProvider:t.loggerProvider,minInterval:n,maxInterval:r,apiKey:t.apiKey,onPersistentFailure:function(){m()}})];case 1:return(e=i.sent())?(p=!0,[2,e]):(t.loggerProvider.log("Failed to initialize idb store, falling back to memory store."),[2,g()])}})})},"idb"!==d?[3,2]:[4,b()];case 1:return S=T.sent(),[3,3];case 2:S=g(),T.label=3;case 3:return y=S,I=[],w=0,C=function(e){if(!(e<=w)){var t=Math.min(e-w,I.length);t>0&&(I.splice(0,t),w=e)}},k=function(e){var n=e.events,r=e.sessionId,i=e.deviceId,l=e.sequenceId;t.debugMode&&Ie().then(function(e){var n=e.totalStorageSize,r=e.percentOfQuota,i=e.usageDetails;t.loggerProvider.debug("Total storage size: ".concat(n," KB, percentage of quota: ").concat(r,"%, usage details: ").concat(i))}).catch(function(){}),v.sendEventsList({events:n,sessionId:r,flushMaxRetries:t.flushMaxRetries,apiKey:t.apiKey,deviceId:i,sampleRate:t.sampleRate,serverZone:t.serverZone,version:t.version,type:a,onComplete:function(){return o(void 0,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,y.cleanUpSessionEventsStore(r,l)];case 1:return e.sent(),[2]}})})}})},E=function(e){var n=e.sessionId,r=e.deviceId;f=r;var i=w+I.length;y.storeCurrentSequence(n).then(function(e){e&&(C(i),k({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:r}))}).catch(function(e){t.loggerProvider.warn("Failed to get current sequence of session replay events for session:",e)})},P=function(e){var t=e.deviceId;return o(void 0,void 0,void 0,function(){var e;return s(this,function(n){switch(n.label){case 0:return f=t,[4,y.getSequencesToSend()];case 1:return(e=n.sent())&&e.forEach(function(e){k({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:t})}),[2]}})})},R=function(e){var n=e.event,r=e.sessionId,i=e.deviceId;f=i;var o=w+I.length;I.push(n.data),y.addEventToCurrentSequence(r,n.data).then(function(e){e&&(C(o),k({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:i}))}).catch(function(e){t.loggerProvider.warn("Failed to add event to session replay capture:",e)})},[2,{sendCurrentSequenceEvents:E,addEvent:R,sendStoredEvents:P,flush:e,getBeaconEvents:function(){return c([],l(I),!1)},trackDestination:v}]}})})},It=function(){function e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new Map;e.forEach(function(e){n.set(e.name,e.manager)}),this.managers=n}return e.prototype.sendStoredEvents=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.sendStoredEvents(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e.prototype.addEvent=function(e){var t,n=e.sessionId,r=e.event,i=e.deviceId;null===(t=this.managers.get(r.type))||void 0===t||t.addEvent({sessionId:n,event:r,deviceId:i})},e.prototype.sendCurrentSequenceEvents=function(e){var t=e.sessionId,n=e.deviceId;this.managers.forEach(function(e){e.sendCurrentSequenceEvents({sessionId:t,deviceId:n})})},e.prototype.flush=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.flush(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e}();function wt(e,t){if(dt=new Date,e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";var n={root:document.body,idName:function(e){return!0},className:function(e){return!0},tagName:function(e){return!0},attr:function(e,t){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4,timeoutMs:void 0};ct=i(i({},n),t),ut=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(ct.root,n);var r=Ct(e,"all",function(){return Ct(e,"two",function(){return Ct(e,"one",function(){return Ct(e,"none")})})});if(r){var o=Lt(Dt(r,e));return o.length>0&&(r=o[0]),Et(r)}throw new Error("Selector was not found.")}function Ct(e,t,n){for(var r=null,i=[],o=e,s=0,u=function(){var e,u,d=(new Date).getTime()-dt.getTime();if(void 0!==ct.timeoutMs&&d>ct.timeoutMs)throw new Error("Timeout: Can't find a unique selector after ".concat(d,"ms"));var h=xt(function(e){var t=e.getAttribute("id");if(t&&ct.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(o))||xt.apply(void 0,c([],l(function(e){var t=Array.from(e.attributes).filter(function(e){return ct.attr(e.name,e.value)});return t.map(function(e){return{name:"[".concat(CSS.escape(e.name),'="').concat(CSS.escape(e.value),'"]'),penalty:.5}})}(o)),!1))||xt.apply(void 0,c([],l(function(e){var t=Array.from(e.classList).filter(ct.className);return t.map(function(e){return{name:"."+CSS.escape(e),penalty:1}})}(o)),!1))||xt(function(e){var t=e.tagName.toLowerCase();if(ct.tagName(t))return{name:t,penalty:2};return null}(o))||[{name:"*",penalty:3}],v=function(e){var t=e.parentNode;if(!t)return null;var n=t.firstChild;if(!n)return null;var r=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&r++,n!==e);)n=n.nextSibling;return r}(o);if("all"==t)v&&(h=h.concat(h.filter(Mt).map(function(e){return Tt(e,v)})));else if("two"==t)h=h.slice(0,1),v&&(h=h.concat(h.filter(Mt).map(function(e){return Tt(e,v)})));else if("one"==t){var g=l(h=h.slice(0,1),1)[0];v&&Mt(g)&&(h=[Tt(g,v)])}else"none"==t&&(h=[{name:"*",penalty:3}],v&&(h=[Tt(h[0],v)]));try{for(var f=(e=void 0,a(h)),p=f.next();!p.done;p=f.next()){(g=p.value).level=s}}catch(t){e={error:t}}finally{try{p&&!p.done&&(u=f.return)&&u.call(f)}finally{if(e)throw e.error}}if(i.push(h),i.length>=ct.seedMinLength&&(r=kt(i,n)))return"break";o=o.parentElement,s++};o;){if("break"===u())break}return r||(r=kt(i,n)),!r&&n?n():r}function kt(e,t){var n,r,i=Lt(Ot(e));if(i.length>ct.threshold)return t?t():null;try{for(var o=a(i),s=o.next();!s.done;s=o.next()){var l=s.value;if(Rt(l))return l}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return null}function Et(e){for(var t=e[0],n=t.name,r=1;r<e.length;r++){var i=e[r].level||0;n=t.level===i-1?"".concat(e[r].name," > ").concat(n):"".concat(e[r].name," ").concat(n),t=e[r]}return n}function Pt(e){return e.map(function(e){return e.penalty}).reduce(function(e,t){return e+t},0)}function Rt(e){var t=Et(e);switch(ut.querySelectorAll(t).length){case 0:throw new Error("Can't select any node with this selector: ".concat(t));case 1:return!0;default:return!1}}function Tt(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function Mt(e){return"html"!==e.name&&!e.name.startsWith("#")}function xt(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(_t);return n.length>0?n:null}function _t(e){return null!=e}function Ot(e,t){var n,r,i,o,l,c;return void 0===t&&(t=[]),s(this,function(s){switch(s.label){case 0:if(!(e.length>0))return[3,9];s.label=1;case 1:s.trys.push([1,6,7,8]),n=a(e[0]),r=n.next(),s.label=2;case 2:return r.done?[3,5]:(i=r.value,[5,a(Ot(e.slice(1,e.length),t.concat(i)))]);case 3:s.sent(),s.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=s.sent(),l={error:o},[3,8];case 7:try{r&&!r.done&&(c=n.return)&&c.call(n)}finally{if(l)throw l.error}return[7];case 8:return[3,11];case 9:return[4,t];case 10:s.sent(),s.label=11;case 11:return[2]}})}function Lt(e){return c([],l(e),!1).sort(function(e,t){return Pt(e)-Pt(t)})}function Dt(e,t,n){var r,i,o;return void 0===n&&(n={counter:0,visited:new Map}),s(this,function(s){switch(s.label){case 0:if(!(e.length>2&&e.length>ct.optimizedMinLength))return[3,5];r=1,s.label=1;case 1:return r<e.length-1?n.counter>ct.maxNumberOfTries?[2]:(n.counter+=1,(i=c([],l(e),!1)).splice(r,1),o=Et(i),n.visited.has(o)?[2]:Rt(i)&&function(e,t){return ut.querySelector(Et(e))===t}(i,t)?[4,i]:[3,4]):[3,5];case 2:return s.sent(),n.visited.set(o,!0),[5,a(Dt(i,t,n))];case 3:s.sent(),s.label=4;case 4:return r++,[3,1];case 5:return[2]}})}var Ft=function(e){var t=e.version,n=e.events,r=[];return n.forEach(function(e){var t=JSON.parse(e);t.count=1,"click"===t.type&&r.push(t)}),{version:t,events:r}},Nt=function(e){var t=e.version,n=e.events,r=[];n.forEach(function(e){var t=JSON.parse(e);"click"===t.type&&r.push(t)});var o=r.reduce(function(e,t){var n=t.x,r=t.y,o=t.selector,s=t.timestamp,a=s-s%36e5,l="".concat(n,":").concat(r,":").concat(null!=o?o:"",":").concat(a);return e[l]?e[l].count+=1:e[l]=i(i({},t),{timestamp:a,count:1}),e},{});return{version:t,events:Object.values(o)}},Ut=function(e,t){var n=this;this.createHook=function(e){var t=e.eventsManager,r=e.sessionId,i=e.deviceIdFn,o=e.mirror,s=e.ugcFilterRules,a=e.performanceOptions;return function(e){if(e.type===Re.Click){var l=g();if(l){var c=l.location,u=l.innerHeight,d=l.innerWidth;if(c){var h=e.x,v=e.y;if(void 0!==h&&void 0!==v){var f,p=o.getNode(e.id);if(p)try{f=wt(p,a)}catch(e){n.logger.debug("error resolving selector from finder")}var y=Se(c.href,s),m={x:h+n.scrollWatcher.currentScrollX,y:v+n.scrollWatcher.currentScrollY,selector:f,viewportHeight:u,viewportWidth:d,pageUrl:y,timestamp:Date.now(),type:"click"},b=i();b&&t.addEvent({sessionId:r,event:{type:"interaction",data:JSON.stringify(m)},deviceId:b})}}}}}},this.logger=e,this.scrollWatcher=t};function At(){var e=g();return(null==e?void 0:e.innerHeight)||document.documentElement&&document.documentElement.clientHeight||0}function qt(){var e=g();return(null==e?void 0:e.innerWidth)||document.documentElement&&document.documentElement.clientWidth||0}var jt=function(){function e(e,t){var n=g();n&&n.navigator&&"function"==typeof n.navigator.sendBeacon?this.sendBeacon=function(e,t){try{if(n.navigator.sendBeacon(e,JSON.stringify(t)))return!0}catch(e){}return!1}:this.sendBeacon=function(){return!1},this.sendXhr=function(e,t){var n=new XMLHttpRequest;return n.open("POST",e,!0),n.setRequestHeader("Accept","*/*"),n.send(JSON.stringify(t)),!0},this.basePageUrl=de(t.serverZone,t.trackServerUrl),this.apiKey=t.apiKey,this.context=e}return e.prototype.send=function(e,t){var n=this.context,r=n.sessionId,i=n.type,o=new URLSearchParams({device_id:e,session_id:String(r),type:String(i),api_key:this.apiKey}),s="".concat(this.basePageUrl,"?").concat(o.toString());this.sendBeacon(s,t)||this.sendXhr(s,t)},e}(),Bt=function(){function e(e,t){var n=this;this.timestamp=Date.now(),this.hook=function(e){n.update(e)},this.send=function(e){return function(t){var r,i,o,s,a=e(),l=g();if(l&&a){var c=null!==(r=l.scrollX)&&void 0!==r?r:0,u=null!==(i=l.scrollY)&&void 0!==i?i:0;(c>0||u>0)&&n.update({id:1,x:c,y:u}),n.transport.send(a,{version:1,events:[{maxScrollX:n._maxScrollX,maxScrollY:n._maxScrollY,maxScrollWidth:n._maxScrollWidth,maxScrollHeight:n._maxScrollHeight,viewportHeight:At(),viewportWidth:qt(),pageUrl:Se(l.location.href,null!==(s=null===(o=n.config.interactionConfig)||void 0===o?void 0:o.ugcFilterRules)&&void 0!==s?s:[]),timestamp:n.timestamp,type:"scroll"}]})}}},this._maxScrollX=0,this._maxScrollY=0,this._currentScrollX=0,this._currentScrollY=0,this._maxScrollWidth=qt(),this._maxScrollHeight=At(),this.config=t,this.transport=e}return e.default=function(t,n){return new e(new jt(t,n),n)},Object.defineProperty(e.prototype,"maxScrollX",{get:function(){return this._maxScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollY",{get:function(){return this._maxScrollY},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollWidth",{get:function(){return this._maxScrollWidth},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollHeight",{get:function(){return this._maxScrollHeight},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollX",{get:function(){return this._currentScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollY",{get:function(){return this._currentScrollY},enumerable:!1,configurable:!0}),e.prototype.update=function(e){var t=Date.now();if(this._currentScrollX=e.x,this._currentScrollY=e.y,e.x>this._maxScrollX){var n=qt();this._maxScrollX=e.x;var r=e.x+n;r>this._maxScrollWidth&&(this._maxScrollWidth=r),this.timestamp=t}if(e.y>this._maxScrollY){var i=At();this._maxScrollY=e.y;var o=e.y+i;o>this._maxScrollHeight&&(this._maxScrollHeight=o),this.timestamp=t}},e}(),Wt=function(e){var t=e.sessionId,n=e.deviceId;this.deviceId=n,this.sessionId=t,t&&n&&(this.sessionReplayId=function(e,t){return"".concat(t,"/").concat(e)}(t,n))},zt=function(){var e=this;this.dbs={},this.createStore=function(t){return o(e,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,Ze(t,1,{upgrade:function(e){e.objectStoreNames.contains("sessionTargetingMatch")||e.createObjectStore("sessionTargetingMatch",{keyPath:"sessionId"})}})];case 1:return[2,e.sent()]}})})},this.openOrCreateDB=function(t){return o(e,void 0,void 0,function(){var e,n;return s(this,function(r){switch(r.label){case 0:return this.dbs&&this.dbs[t]?[2,this.dbs[t]]:(e="".concat(t.substring(0,10),"_amp_session_replay_targeting"),[4,this.createStore(e)]);case 1:return n=r.sent(),this.dbs[t]=n,[2,n]}})})},this.getTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId;return o(e,void 0,void 0,function(){var e,t,o,a;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,e.get("sessionTargetingMatch",t)];case 2:return[2,null==(o=s.sent())?void 0:o.targetingMatch];case 3:return a=s.sent(),vt(n,"Failed to get targeting match for session id ".concat(i,": ").concat(a),a),[3,4];case 4:return[2,void 0]}})})},this.storeTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId,a=t.targetingMatch;return o(e,void 0,void 0,function(){var e,t,o;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,e.put("sessionTargetingMatch",{targetingMatch:a,sessionId:t,lastUpdated:Date.now()})];case 2:return[2,s.sent()];case 3:return o=s.sent(),vt(n,"Failed to store targeting match for session id ".concat(i,": ").concat(o),o),[3,4];case 4:return[2,void 0]}})})},this.clearStoreOfOldSessions=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.currentSessionId;return o(e,void 0,void 0,function(){var e,t,o,a,l,c,u,d;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,8,,9]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,(o=e.transaction("sessionTargetingMatch","readwrite")).store.getAll()];case 2:a=s.sent(),l=0,s.label=3;case 3:return l<a.length?(c=a[l],u=Date.now()-c.lastUpdated,c.sessionId!==t&&u>1728e5?[4,o.store.delete(c.sessionId)]:[3,5]):[3,6];case 4:s.sent(),s.label=5;case 5:return l++,[3,3];case 6:return[4,o.done];case 7:return s.sent(),[3,9];case 8:return d=s.sent(),vt(n,"Failed to clear old targeting matches for sessions: ".concat(d),d),[3,9];case 9:return[2]}})})}},Kt=new zt,$t=function(e){var t=e.sessionId,n=e.targetingConfig,r=e.loggerProvider,a=e.apiKey,l=e.targetingParams,c=e.urlChange,u=void 0!==c&&c;return o(void 0,void 0,void 0,function(){var e,o,c,d,h,v;return s(this,function(s){switch(s.label){case 0:return[4,Kt.clearStoreOfOldSessions({loggerProvider:r,apiKey:a,currentSessionId:t})];case 1:return s.sent(),[4,Kt.getTargetingMatchForSession({loggerProvider:r,apiKey:a,sessionId:t})];case 2:if(!0===s.sent()&&!u)return[2,!0];e=!0,s.label=3;case 3:return s.trys.push([3,6,,7]),[4,import("./index-min3.js")];case 4:return o=s.sent().evaluateTargeting,c=i(i({},l),{flag:n,sessionId:"string"==typeof t?parseInt(t,10):t,apiKey:a,loggerProvider:r}),[4,o(c)];case 5:return(d=s.sent())&&d.sr_targeting_config&&(e="on"===d.sr_targeting_config.key),Kt.storeTargetingMatchForSession({loggerProvider:r,apiKey:a,sessionId:t,targetingMatch:e}),[3,7];case 6:return h=s.sent(),v=h,r.warn(v.message),[3,7];case 7:return[2,e]}})})},Ht=2654435761,Jt=2246822519,Qt=3266489917,Gt=374761393;function Vt(e,t){return(e<<t|e>>>32-t)>>>0}function Zt(e,t){return e=Vt(e=e+Math.imul(t,Jt)>>>0,13),e=Math.imul(e,Ht)>>>0}function Yt(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function Xt(e,t){void 0===t&&(t=0);var n,r=function(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r>=55296&&r<=56319&&n+1<e.length){var i=e.charCodeAt(n+1);i>=56320&&i<=57343&&(r=i-56320+(r-55296<<10)+65536,n++)}r<128?t.push(r):r<2048?t.push(192|r>>6,128|63&r):r<65536?t.push(224|r>>12,128|r>>6&63,128|63&r):t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)}return new Uint8Array(t)}(e),i=r.length,o=0;if(i>=16){for(var s=t+Ht+Jt>>>0,a=t+Jt>>>0,l=t>>>0,c=t-Ht>>>0;o<=i-16;)s=Zt(s,Yt(r,o)),a=Zt(a,Yt(r,o+=4)),l=Zt(l,Yt(r,o+=4)),c=Zt(c,Yt(r,o+=4)),o+=4;n=Vt(s,1)+Vt(a,7)+Vt(l,12)+Vt(c,18)>>>0}else n=t+Gt>>>0;for(n=n+i>>>0;o<=i-4;)n=n+Math.imul(Yt(r,o),Qt)>>>0,n=Math.imul(Vt(n,17),668265263)>>>0,o+=4;for(;o<i;)n=n+Math.imul(r[o],Gt)>>>0,n=Math.imul(Vt(n,11),Ht)>>>0,o++;return n^=n>>>15,n=Math.imul(n,Jt)>>>0,n^=n>>>13,n=Math.imul(n,Qt)>>>0,(n^=n>>>16)>>>0}var en="__amplitude_url_tracking_patched__",tn=new WeakMap;function nn(e,t,n){if(void 0===n&&(n={}),!(null==e?void 0:e.location))return function(){};var r=n.enablePolling,i=void 0!==r&&r,o=n.pollingInterval,s=void 0===o?re:o;if(i){var a=function(){var t;return null!==(t=e.location.href)&&void 0!==t?t:""},l=a(),c=e.setInterval(function(){var e=a();e!==l&&(l=e,t(e))},s);return function(){null!=c&&e.clearInterval(c)}}var u=tn.get(e);if(!u){var d=void 0,h=new Set,v=function(){var t=function(){var t;return null!==(t=e.location.href)&&void 0!==t?t:""}();void 0!==d&&t===d||(d=t,h.forEach(function(e){return e(t)}))},g=function(e){var t=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=e.apply(this,t);return v(),r};return t[en]=!0,t},f=e.history;if(null==f?void 0:f.pushState){var p=Reflect.get(f,"pushState");p[en]||(f.pushState=g(p))}if(null==f?void 0:f.replaceState){var y=Reflect.get(f,"replaceState");y[en]||(f.replaceState=g(y))}u={callbacks:h,notify:v,onPopStateOrHashChange:function(){return v()},listenersAttached:!1},tn.set(e,u)}var m=u;return m.listenersAttached||(e.addEventListener("popstate",m.onPopStateOrHashChange),e.addEventListener("hashchange",m.onPopStateOrHashChange),m.listenersAttached=!0),m.callbacks.add(t),function(){m.callbacks.delete(t),0===m.callbacks.size&&m.listenersAttached&&(e.removeEventListener("popstate",m.onPopStateOrHashChange),e.removeEventListener("hashchange",m.onPopStateOrHashChange),m.listenersAttached=!1)}}function rn(e){return void 0===e&&(e={}),{name:"amplitude/url-tracking@1",observer:function(t,n,r){var o,s,a,l=i(i({},e),r),c=l.ugcFilterRules||[],u=null!==(o=l.enablePolling)&&void 0!==o&&o,d=null!==(s=l.pollingInterval)&&void 0!==s?s:re,h=null!==(a=l.captureDocumentTitle)&&void 0!==a&&a;if(!n)return function(){};var v=void 0,g=function(){return n.location&&n.location.href||""},f=function(){var e=g();if(void 0===v||e!==v){v=e;var r=function(){var e=n.innerHeight,t=n.innerWidth,r=n.document,i=g(),o="";return h&&(o=(null==r?void 0:r.title)||""),{href:c.length>0?Se(i,c):i,title:o,viewportHeight:e,viewportWidth:t,type:"url-change-event"}}();t(r)}},p=nn(n,function(){return f()},u?{enablePolling:!0,pollingInterval:d}:{});return f(),function(){return p()}},options:e}}rn();var on,sn,an,ln=function(){function e(){var e=this;this.name="@amplitude/session-replay-browser",this.recordCancelCallback=null,this.eventCount=0,this.sessionTargetingMatch=!1,this.pageLeaveFns=[],this.recordFunction=null,this.recordEventsInFlight=!1,this.currentPageUrl="",this.recordEventsPendingShouldLogMetadata=null,this.urlChangeCleanup=null,this.latestUrlChangeTargetingEvaluationId=0,this.teardownEventListeners=function(t){var n=g();n&&(n.removeEventListener("blur",e.blurListener),n.removeEventListener("focus",e.focusListener),!t&&n.addEventListener("blur",e.blurListener),!t&&n.addEventListener("focus",e.focusListener),n.self&&"onpagehide"in n.self?(n.removeEventListener("pagehide",e.pageLeaveListener),!t&&n.addEventListener("pagehide",e.pageLeaveListener)):(n.removeEventListener("beforeunload",e.pageLeaveListener),!t&&n.addEventListener("beforeunload",e.pageLeaveListener)))},this.blurListener=function(){e.sendEvents()},this.focusListener=function(){if(e.recordCancelCallback&&e.recordFunction)try{e.recordFunction.takeFullSnapshot(!0)}catch(t){e.loggerProvider.warn("Failed to take full snapshot on focus:",t)}else e.recordEventsInFlight||e.recordEvents(!1)},this.pageLeaveListener=function(t){e.pageLeaveFns.forEach(function(e){e(t)})},this.evaluateTargetingAndCapture=function(t,n,i,a){return void 0===n&&(n=!1),void 0===i&&(i=!1),void 0===a&&(a=!1),o(e,void 0,void 0,function(){var e,o,l,c,u,d,h,v,f,p,y,m;return s(this,function(s){switch(s.label){case 0:if(!this.identifiers||!this.identifiers.sessionId||!this.config)return this.identifiers&&!this.identifiers.sessionId?this.loggerProvider.log("Session ID has not been set yet, cannot evaluate targeting for Session Replay."):this.loggerProvider.warn("Session replay init has not been called, cannot evaluate targeting."),[2];if(!this.config.targetingConfig){if(!n)return this.loggerProvider.log("No targeting config set, skipping initialization/recording for event."),[2];this.loggerProvider.log("Targeting config has not been set yet, cannot evaluate targeting.")}return this.lastTargetingParams=t,e=this.config.targetingConfig,e&&!this.sessionTargetingMatch?(o=a?this.latestUrlChangeTargetingEvaluationId:void 0,(l=t.event)&&Object.values(r).includes(l.event_type)&&(l=void 0),c=null!==(y=null!==(v=null===(h=t.page)||void 0===h?void 0:h.url)&&void 0!==v?v:null===(p=null===(f=g())||void 0===f?void 0:f.location)||void 0===p?void 0:p.href)&&void 0!==y?y:"",u=null!==(m=t.page)&&void 0!==m?m:""!==c?{url:c}:void 0,[4,$t({sessionId:this.identifiers.sessionId,targetingConfig:e,loggerProvider:this.loggerProvider,apiKey:this.config.apiKey,targetingParams:{userProperties:t.userProperties,event:l,page:u},urlChange:a})]):[3,2];case 1:if(d=s.sent(),a&&void 0!==o&&o!==this.latestUrlChangeTargetingEvaluationId)return this.loggerProvider.debug("Ignoring stale URL-change targeting result #".concat(o,"; latest is #").concat(this.latestUrlChangeTargetingEvaluationId,".")),[2];this.sessionTargetingMatch=this.sessionTargetingMatch||d,this.loggerProvider.debug(JSON.stringify({name:"targeted replay capture config",sessionTargetingMatch:this.sessionTargetingMatch,event:l,targetingParams:t},null,2)),s.label=2;case 2:return n?(this.initialize(!0),[3,5]):[3,3];case 3:return!i&&this.recordCancelCallback?[3,5]:(this.loggerProvider.log("Recording events for session due to forceRestart or no ongoing recording."),[4,this.recordEvents()]);case 4:s.sent(),s.label=5;case 5:return[2]}})})},this.addCustomRRWebEvent=function(t,n,r){return void 0===n&&(n={}),void 0===r&&(r=!0),o(e,void 0,void 0,function(){var e,o,a,l;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),e=void 0,(o=this.config)&&t!==Y.METADATA?(e={config:we(o),version:Ne},r?[4,Ie()]:[3,2]):[3,2];case 1:a=s.sent(),e=i(i({},a),e),s.label=2;case 2:return this.recordCancelCallback&&this.recordFunction?this.recordFunction.addCustomEvent(t,i(i({},n),e)):this.loggerProvider.debug("Not able to add custom replay capture event ".concat(t," due to no ongoing recording.")),[3,4];case 3:return l=s.sent(),this.loggerProvider.debug("Error while adding custom replay capture event: ",l),[3,4];case 4:return[2]}})})},this.stopRecordingEvents=function(){var t;try{e.loggerProvider.log("Session Replay capture stopping."),e.recordCancelCallback&&e.recordCancelCallback(),e.recordCancelCallback=null,null===(t=e.networkObservers)||void 0===t||t.stop()}catch(t){var n=t;e.loggerProvider.warn("Error occurred while stopping replay capture: ".concat(n.toString()))}},this.loggerProvider=new ce(new b)}return e.prototype.init=function(e,t){return y(this._init(e,t))},e.prototype.setupUrlChangeListener=function(){var e,t,n=this;null===(e=this.urlChangeCleanup)||void 0===e||e.call(this);var r=g();if(null==r?void 0:r.location){var i=!!(null===(t=this.config)||void 0===t?void 0:t.targetingConfig),o=nn(r,function(e){if(n.currentPageUrl=e,i){var t=++n.latestUrlChangeTargetingEvaluationId;n.evaluateTargetingAndCapture({userProperties:{},event:void 0,page:{url:e}},!1,!1,!0),n.loggerProvider.debug("Queued URL-change targeting re-evaluation #".concat(t," for ").concat(e,"."))}});this.urlChangeCleanup=function(){o(),n.urlChangeCleanup=null}}},e.prototype.getCurrentPageForTargeting=function(){var e,t,n=null===(t=null===(e=g())||void 0===e?void 0:e.location)||void 0===t?void 0:t.href;return null!=n?{url:n}:void 0},e.prototype._init=function(e,t){var n,r,a,u,d,h,v,f,p,y,m;return o(this,void 0,void 0,function(){var o,S,I,w,C,k,E,P,R,T,M,x,_,O,L,D,F,N,U,A,q,j=this;return s(this,function(s){switch(s.label){case 0:return null===(n=this.urlChangeCleanup)||void 0===n||n.call(this),this.loggerProvider=new ce(t.loggerProvider||new b),Object.prototype.hasOwnProperty.call(t,"logLevel")&&this.loggerProvider.enable(t.logLevel),this.currentPageUrl=ye(),this.identifiers=new Wt({sessionId:t.sessionId,deviceId:t.deviceId}),o=this,[4,Me(e,t)];case 1:return o.joinedConfigGenerator=s.sent(),[4,this.joinedConfigGenerator.generateJoinedConfig()];case 2:return S=s.sent(),I=S.joinedConfig,w=S.localConfig,C=S.remoteConfig,this.config=I,this.setMetadata(t.sessionId,I,w,C,null===(r=t.version)||void 0===r?void 0:r.version,Ne,null===(a=t.version)||void 0===a?void 0:a.type),this.pageLeaveFns=[],t.sessionId&&(null===(u=this.config.interactionConfig)||void 0===u?void 0:u.enabled)&&(k=Bt.default({sessionId:t.sessionId,type:"interaction"},this.config),this.pageLeaveFns=[k.send(this.getDeviceId.bind(this)).bind(k)],this.scrollHook=k.hook.bind(k),this.clickHandler=new Ut(this.loggerProvider,k)),E=[],"idb"!==(P=this.config.storeType)||(null===(d=g())||void 0===d?void 0:d.indexedDB)||(P="memory",this.loggerProvider.warn("Could not use preferred indexedDB storage, reverting to in memory option.")),this.loggerProvider.log("Using ".concat(P," for event storage.")),M=g(),this.config.useWebWorker&&M&&M.Worker?[4,import("./index-min2.js")]:[3,4];case 3:x=s.sent(),_=x.compressionScript,O=x.trackDestinationScript,R=_,T=O,s.label=4;case 4:return s.trys.push([4,6,,7]),[4,St({config:this.config,type:"replay",storeType:P,trackDestinationWorkerScript:T})];case 5:return L=s.sent(),E.push({name:"replay",manager:L}),[3,7];case 6:return D=s.sent(),A=D,this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(A.toString())),[3,7];case 7:if(!(null===(h=this.config.interactionConfig)||void 0===h?void 0:h.enabled))return[3,11];F=this.config.interactionConfig.batch?Nt:Ft,s.label=8;case 8:return s.trys.push([8,10,,11]),[4,St({config:this.config,type:"interaction",minInterval:null!==(v=this.config.interactionConfig.trackEveryNms)&&void 0!==v?v:3e4,maxInterval:6e4,payloadBatcher:F,storeType:P,trackDestinationWorkerScript:T})];case 9:return N=s.sent(),E.push({name:"interaction",manager:N}),[3,11];case 10:return U=s.sent(),A=U,this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(A.toString())),[3,11];case 11:return this.eventsManager=new(It.bind.apply(It,c([void 0],l(E),!1))),this.eventCompressor&&this.eventCompressor.terminate(),this.eventCompressor=new Le(this.eventsManager,this.config,this.getDeviceId(),R,function(){return j.sendEvents()}),this.pageLeaveFns=c(c([],l(this.pageLeaveFns),!1),[function(){var e;if(j.config&&(null===(e=j.identifiers)||void 0===e?void 0:e.sessionId)&&L){var t=L.getBeaconEvents();if(t.length){var n=j.getDeviceId();n&&L.trackDestination.sendBeacon({events:t,sessionId:j.identifiers.sessionId,deviceId:n,apiKey:j.config.apiKey,serverZone:j.config.serverZone})}}}],!1),[4,this.initializeNetworkObservers()];case 12:return s.sent(),(null===(f=g())||void 0===f?void 0:f.opener)&&(function(e,t){var n,r=e;if(!0!==r[Z]){r[Z]=!0;var i=null!==(n=null==t?void 0:t.scriptUrl)&&void 0!==n?n:"https://cdn.amplitude.com/libs/background-capture-1.0.0-alpha.3.js.gz",o=null,s=function(t,n){var r,i;"background-capture-complete"===t&&(null===(i=null===(r=e.logger)||void 0===r?void 0:r.debug)||void 0===i||i.call(r,"Background capture complete"),e.notify({action:"background-capture-complete",data:n}))};e.registerActionHandler("initialize-background-capture",function(){var t,n;null===(n=null===(t=e.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Initializing background capture (external script)");var r=new URL(i,e.endpoint).toString();e.loadScriptOnce(r).then(function(){var t,n,r;null===(n=null===(t=e.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Background capture script loaded (external)"),o=null===(r=null===window||void 0===window?void 0:window.amplitudeBackgroundCapture)||void 0===r?void 0:r.call(window,{messenger:e,onBackgroundCapture:s}),e.notify({action:"background-capture-loaded"})}).catch(function(){var t;null===(t=e.logger)||void 0===t||t.warn("Failed to initialize background capture")})}),e.registerActionHandler("close-background-capture",function(){var e;null===(e=null==o?void 0:o.close)||void 0===e||e.call(o),o=null})}}(q=V()),q.setup(i({logger:this.loggerProvider},this.config.serverZone&&{endpoint:H[this.config.serverZone]}))),this.loggerProvider.log("Installing @amplitude/session-replay-browser."),this.teardownEventListeners(!1),[4,this.evaluateTargetingAndCapture({userProperties:t.userProperties,page:this.getCurrentPageForTargeting()},!0)];case 13:return s.sent(),(this.config.targetingConfig||(null!==(m=null===(y=null===(p=this.config.privacyConfig)||void 0===p?void 0:p.urlMaskLevels)||void 0===y?void 0:y.length)&&void 0!==m?m:0)>0)&&this.setupUrlChangeListener(),[2]}})})},e.prototype.setSessionId=function(e,t){return y(this.asyncSetSessionId(e,t))},e.prototype.asyncSetSessionId=function(e,t,n){var r;return o(this,void 0,void 0,function(){var i,o,a;return s(this,function(s){switch(s.label){case 0:return this.latestUrlChangeTargetingEvaluationId++,this.sessionTargetingMatch=!1,this.lastShouldRecordDecision=void 0,(i=this.identifiers&&this.identifiers.sessionId)&&this.sendEvents(i),o=t||this.getDeviceId(),this.identifiers=new Wt({sessionId:e,deviceId:o}),this.joinedConfigGenerator&&i?[4,this.joinedConfigGenerator.generateJoinedConfig()]:[3,2];case 1:a=s.sent().joinedConfig,this.config=a,s.label=2;case 2:return(null===(r=this.config)||void 0===r?void 0:r.targetingConfig)?[4,this.evaluateTargetingAndCapture({userProperties:null==n?void 0:n.userProperties,page:this.getCurrentPageForTargeting()},!1,!0)]:[3,4];case 3:return s.sent(),[3,6];case 4:return[4,this.recordEvents()];case 5:s.sent(),s.label=6;case 6:return[2]}})})},e.prototype.getSessionReplayProperties=function(){var e,t=this.config,n=this.identifiers;if(!t||!n)return this.loggerProvider.warn("Session replay init has not been called, cannot get session replay properties."),{};var r=this.getShouldRecord(),i={};return r&&((e={})[ee]=n.sessionReplayId?n.sessionReplayId:null,i=e,t.debugMode&&(i[ie]=JSON.stringify({appHash:N(t.apiKey).toString()}))),this.addCustomRRWebEvent(Y.GET_SR_PROPS,{shouldRecord:r,eventProperties:i},10===this.eventCount),10===this.eventCount&&(this.eventCount=0),this.eventCount++,i},e.prototype.sendEvents=function(e){var t,n=e||(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId),r=this.getDeviceId();this.eventsManager&&n&&r&&this.eventsManager.sendCurrentSequenceEvents({sessionId:n,deviceId:r})},e.prototype.initialize=function(e){var t;return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var n;return s(this,function(r){return(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId)?(n=this.getDeviceId())?(this.eventsManager&&e&&this.eventsManager.sendStoredEvents({deviceId:n}),[2,this.recordEvents()]):(this.loggerProvider.log("Session is not being recorded due to lack of device id."),[2,Promise.resolve()]):(this.loggerProvider.log("Session is not being recorded due to lack of session id."),[2,Promise.resolve()])})})},e.prototype.shouldOptOut=function(){var e,t,n,r;(null===(e=this.config)||void 0===e?void 0:e.instanceName)&&(n=(r=this.config.instanceName,void 0===r&&(r=d),F.getInstance(r)).identityStore.getIdentity().optOut);return void 0!==n?n:null===(t=this.config)||void 0===t?void 0:t.optOut},e.prototype.getShouldRecord=function(){if(!this.identifiers||!this.config||!this.identifiers.sessionId)return this.loggerProvider.warn("Session is not being recorded due to lack of config, please call sessionReplay.init."),!1;if(!this.config.captureEnabled)return this.loggerProvider.log("Session ".concat(this.identifiers.sessionId," not being captured due to capture being disabled for project or because the remote config could not be fetched.")),!1;if(this.shouldOptOut())return this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId," out of recording due to optOut config.")),!1;var e,t,n=!1,r="",i=!1;this.config.targetingConfig?this.sessionTargetingMatch?(r="Capturing replays for session ".concat(this.identifiers.sessionId," due to matching targeting conditions."),this.loggerProvider.log(r),n=!0,i=!0):(r="Not capturing replays for session ".concat(this.identifiers.sessionId," due to not matching targeting conditions."),this.loggerProvider.log(r),n=!1,i=!1):(e=this.identifiers.sessionId,t=this.config.sampleRate,Xt(e.toString())%1e6/1e6<t)?(n=!0,i=!0):(r="Opting session ".concat(this.identifiers.sessionId," out of recording due to sample rate."),this.loggerProvider.log(r),n=!1,i=!1);return this.lastShouldRecordDecision!==n&&this.config.targetingConfig&&(this.addCustomRRWebEvent(Y.TARGETING_DECISION,{message:r,sessionId:this.identifiers.sessionId,matched:i,targetingParams:this.lastTargetingParams}),this.lastShouldRecordDecision=n),n},e.prototype.getBlockSelectors=function(){var e,t,n,r=null!==(n=null===(t=null===(e=this.config)||void 0===e?void 0:e.privacyConfig)||void 0===t?void 0:t.blockSelector)&&void 0!==n?n:[];if(0!==r.length)return r},e.prototype.getMaskTextSelectors=function(){var e,t,n=null===(e=this.config)||void 0===e?void 0:e.privacyConfig;if("conservative"===(n?ve(this.currentPageUrl,n):void 0))return"*";if(null===(t=null==n?void 0:n.urlMaskLevels)||void 0===t?void 0:t.some(function(e){return"conservative"===e.maskLevel}))return"*";var r=null==n?void 0:n.urlMaskLevels;if("conservative"===(null==n?void 0:n.defaultMaskLevel)&&r&&r.length>0)return"*";var i=null==n?void 0:n.maskSelector;return i||void 0},e.prototype.getRecordingPlugins=function(e){var t,n,r,i,a,l;return o(this,void 0,void 0,function(){var o,c,u,d;return s(this,function(s){switch(s.label){case 0:o=[];try{c=rn({ugcFilterRules:(null===(n=null===(t=this.config)||void 0===t?void 0:t.interactionConfig)||void 0===n?void 0:n.ugcFilterRules)||[],enablePolling:(null===(r=this.config)||void 0===r?void 0:r.enableUrlChangePolling)||!1,pollingInterval:null===(i=this.config)||void 0===i?void 0:i.urlChangePollingInterval,captureDocumentTitle:null===(a=this.config)||void 0===a?void 0:a.captureDocumentTitle}),o.push(c)}catch(e){this.loggerProvider.warn("Failed to create URL tracking plugin:",e)}if(!(null===(l=null==e?void 0:e.console)||void 0===l?void 0:l.enabled))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,import("./console-plugin-min.js")];case 2:return u=s.sent().getRecordConsolePlugin,o.push(u({level:e.console.levels})),[3,4];case 3:return d=s.sent(),this.loggerProvider.warn("Failed to load console plugin:",d),[3,4];case 4:return[2,o.length>0?o:void 0]}})})},e.prototype.getRecordFunction=function(){return o(this,void 0,void 0,function(){var e,t;return s(this,function(n){switch(n.label){case 0:if(this.recordFunction)return[2,this.recordFunction];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,import("./rrweb-record-min.js")];case 2:return e=n.sent().record,this.recordFunction=e,[2,e];case 3:return t=n.sent(),this.loggerProvider.warn("Failed to load rrweb-record module:",t),[2,null];case 4:return[2]}})})},e.prototype.recordEvents=function(e){return void 0===e&&(e=!0),o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:if(this.recordEventsInFlight)return this.recordEventsPendingShouldLogMetadata=e,[2];this.recordEventsInFlight=!0,n.label=1;case 1:return n.trys.push([1,,6,7]),[4,this._recordEvents(e)];case 2:n.sent(),n.label=3;case 3:return null===this.recordEventsPendingShouldLogMetadata?[3,5]:(t=this.recordEventsPendingShouldLogMetadata,this.recordEventsPendingShouldLogMetadata=null,[4,this._recordEvents(t)]);case 4:return n.sent(),[3,3];case 5:return[3,7];case 6:return this.recordEventsInFlight=!1,this.recordEventsPendingShouldLogMetadata=null,[7];case 7:return[2]}})})},e.prototype._recordEvents=function(e){var t,n,r,i,a,l,c,u;return void 0===e&&(e=!0),o(this,void 0,void 0,function(){var o,d,h,v,g,f,p,y,m,b,S,I,w,C,k,E,P=this;return s(this,function(s){switch(s.label){case 0:return o=this.config,d=this.getShouldRecord(),h=null===(t=this.identifiers)||void 0===t?void 0:t.sessionId,d&&h&&o?(this.stopRecordingEvents(),[4,this.getRecordFunction()]):[2];case 1:return(v=s.sent())?[4,this.initializeNetworkObservers()]:[2];case 2:s.sent(),g=null===(n=o.loggingConfig)||void 0===n?void 0:n.network,f=de(o.serverZone,o.trackServerUrl),p=[se,ae,le,f],null===(r=this.networkObservers)||void 0===r||r.start(function(e){p.some(function(t){return e.url.startsWith(t)})||P.addCustomRRWebEvent(Y.FETCH_REQUEST,e)},g),y=o.privacyConfig,m=o.interactionConfig,b=o.loggingConfig,S=(null==m?void 0:m.enabled)?{mouseInteraction:this.eventsManager&&(null===(i=this.clickHandler)||void 0===i?void 0:i.createHook({eventsManager:this.eventsManager,sessionId:h,deviceIdFn:this.getDeviceId.bind(this),mirror:v.mirror,ugcFilterRules:null!==(a=m.ugcFilterRules)&&void 0!==a?a:[],performanceOptions:null===(l=o.performanceConfig)||void 0===l?void 0:l.interaction})),scroll:this.scrollHook}:{},I=(null==m?void 0:m.enabled)&&m.ugcFilterRules?m.ugcFilterRules:[],this.loggerProvider.log("Session Replay capture beginning for ".concat(h,".")),s.label=3;case 3:return s.trys.push([3,5,,6]),w=this,C=v,E={emit:function(e){if(P.shouldOptOut())return P.loggerProvider.log("Opting session ".concat(h," out of recording due to optOut config.")),P.stopRecordingEvents(),void P.sendEvents();e.type===Ee.Meta&&(e.data.href=Se(e.data.href,I)),P.eventCompressor&&P.eventCompressor.enqueueEvent(e,h)},inlineStylesheet:o.shouldInlineStylesheet,hooks:S,maskAllInputs:!0,maskTextClass:oe,blockClass:"amp-block",blockSelector:this.getBlockSelectors(),applyBackgroundColorToBlockedElements:o.applyBackgroundColorToBlockedElements,maskInputFn:fe("input",y,function(){return P.currentPageUrl}),maskTextFn:fe("text",y,function(){return P.currentPageUrl}),maskAttributeFn:pe(y,function(){return P.currentPageUrl}),maskTextSelector:this.getMaskTextSelectors(),recordCanvas:!1,captureAdoptedStyleSheets:o.captureAdoptedStyleSheets,slimDOMOptions:{script:null===(c=o.omitElementTags)||void 0===c?void 0:c.script,comment:null===(u=o.omitElementTags)||void 0===u?void 0:u.comment},errorHandler:function(e){var t=e;if(t.message.includes("insertRule")&&t.message.includes("CSSStyleSheet"))throw t;if(t._external_)throw t;return P.loggerProvider.warn("Error while capturing replay: ",t.toString()),!0}},[4,this.getRecordingPlugins(b)];case 4:return w.recordCancelCallback=C.apply(void 0,[(E.plugins=s.sent(),E)]),this.addCustomRRWebEvent(Y.DEBUG_INFO),e&&this.addCustomRRWebEvent(Y.METADATA,this.metadata),[3,6];case 5:return k=s.sent(),this.loggerProvider.warn("Failed to initialize session replay:",k),[3,6];case 6:return[2]}})})},e.prototype.getDeviceId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.deviceId},e.prototype.getSessionId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.sessionId},e.prototype.flush=function(e){var t;return void 0===e&&(e=!1),o(this,void 0,void 0,function(){return s(this,function(n){return[2,null===(t=this.eventsManager)||void 0===t?void 0:t.flush(e)]})})},e.prototype.shutdown=function(){var e;null===(e=this.urlChangeCleanup)||void 0===e||e.call(this),this.teardownEventListeners(!0),this.stopRecordingEvents(),this.sendEvents()},e.prototype.mapSDKType=function(e){return"plugin"===e?"@amplitude/plugin-session-replay-browser":"segment"===e?"@amplitude/segment-session-replay-plugin":null},e.prototype.setMetadata=function(e,t,n,r,i,o,s){var a=(null==e?void 0:e.toString())?N(e.toString()):void 0;this.metadata={joinedConfig:t,localConfig:n,remoteConfig:r,sessionId:e,hashValue:a,sampleRate:t.sampleRate,replaySDKType:this.mapSDKType(s),replaySDKVersion:i,standaloneSDKType:"@amplitude/session-replay-browser",standaloneSDKVersion:o}},e.prototype.initializeNetworkObservers=function(){var e,t,n;return o(this,void 0,void 0,function(){var r,i;return s(this,function(o){switch(o.label){case 0:if(!(null===(n=null===(t=null===(e=this.config)||void 0===e?void 0:e.loggingConfig)||void 0===t?void 0:t.network)||void 0===n?void 0:n.enabled)||this.networkObservers)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,import("./observers-min.js")];case 2:return r=o.sent().NetworkObservers,this.networkObservers=new r,[3,4];case 3:return i=o.sent(),this.loggerProvider.warn("Failed to import or instantiate NetworkObservers:",i),[3,4];case 4:return[2]}})})},e}(),cn=function(e){return function(){var t=e.config||Ce();return{logger:t.loggerProvider,logLevel:t.logLevel}}},un=function(){var e=new ln;return{init:k(e.init.bind(e),"init",cn(e)),evaluateTargetingAndCapture:k(e.evaluateTargetingAndCapture.bind(e),"evaluateTargetingAndRecord",cn(e)),setSessionId:k(e.setSessionId.bind(e),"setSessionId",cn(e)),getSessionId:k(e.getSessionId.bind(e),"getSessionId",cn(e)),getSessionReplayProperties:k(e.getSessionReplayProperties.bind(e),"getSessionReplayProperties",cn(e)),flush:k(e.flush.bind(e),"flush",cn(e)),shutdown:k(e.shutdown.bind(e),"shutdown",cn(e))}}(),dn=un.init,hn=un.setSessionId,vn=un.getSessionId,gn=un.getSessionReplayProperties,fn=un.flush,pn=un.shutdown,yn=un.evaluateTargetingAndCapture;!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"}(on||(on={})),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"}(sn||(sn={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(an||(an={}));const mn=[on.SET,on.SET_ONCE,on.ADD,on.APPEND,on.PREPEND,on.POSTINSERT],bn="1.28.1";class Sn{constructor(e){this.name=Sn.pluginName,this.type="enrichment",this.config=null,this.sessionReplay={flush:fn,getSessionId:vn,getSessionReplayProperties:gn,init:dn,setSessionId:hn,shutdown:pn,evaluateTargetingAndCapture:yn},this.options=Object.assign({forceSessionTracking:!1},e),this.srInitOptions=this.options}setup(e,t){return o(this,void 0,void 0,function*(){var t,n,r,i,o,s,a,l,c;try{null==e||e.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${bn}.`),this.config=e,this.options.forceSessionTracking&&("boolean"==typeof e.defaultTracking?!1===e.defaultTracking&&(e.defaultTracking={pageViews:!1,formInteractions:!1,fileDownloads:!1,sessions:!0}):e.defaultTracking=Object.assign(Object.assign({},e.defaultTracking),{sessions:!0}));const u=(c=this.config.instanceName,void 0===c&&(c="$default_instance"),F.getInstance(c)).identityStore.getIdentity().userProperties;this.srInitOptions={instanceName:this.config.instanceName,deviceId:null!==(t=this.options.deviceId)&&void 0!==t?t:this.config.deviceId,optOut:this.config.optOut,sessionId:this.options.customSessionId?void 0:this.config.sessionId,loggerProvider:this.config.loggerProvider,logLevel:this.config.logLevel,flushMaxRetries:this.config.flushMaxRetries,serverZone:this.config.serverZone,configServerUrl:this.options.configServerUrl||(null===(n=this.config.remoteConfig)||void 0===n?void 0:n.serverUrl),trackServerUrl:this.options.trackServerUrl,sampleRate:this.options.sampleRate,privacyConfig:{blockSelector:null===(r=this.options.privacyConfig)||void 0===r?void 0:r.blockSelector,maskSelector:null===(i=this.options.privacyConfig)||void 0===i?void 0:i.maskSelector,unmaskSelector:null===(o=this.options.privacyConfig)||void 0===o?void 0:o.unmaskSelector,defaultMaskLevel:null===(s=this.options.privacyConfig)||void 0===s?void 0:s.defaultMaskLevel},debugMode:this.options.debugMode,shouldInlineStylesheet:this.options.shouldInlineStylesheet,version:{type:"plugin",version:bn},performanceConfig:this.options.performanceConfig,storeType:this.options.storeType,useWebWorker:null!==(a=this.options.useWebWorker)&&void 0!==a?a:null===(l=this.options.experimental)||void 0===l?void 0:l.useWebWorker,userProperties:u,omitElementTags:this.options.omitElementTags,applyBackgroundColorToBlockedElements:this.options.applyBackgroundColorToBlockedElements,interactionConfig:this.options.interactionConfig,captureDocumentTitle:this.options.captureDocumentTitle,enableUrlChangePolling:this.options.enableUrlChangePolling,urlChangePollingInterval:this.options.urlChangePollingInterval,captureAdoptedStyleSheets:this.options.captureAdoptedStyleSheets},yield this.sessionReplay.init(e.apiKey,this.srInitOptions).promise}catch(t){null==e||e.loggerProvider.error(`Session Replay: Failed to initialize due to ${t.message}`)}})}onSessionIdChanged(e){return o(this,void 0,void 0,function*(){var t;null===(t=this.config)||void 0===t||t.loggerProvider.debug(`Analytics session id is changed to ${e}, SR session id is ${String(this.sessionReplay.getSessionId())}.`),yield this.sessionReplay.setSessionId(e).promise})}onOptOutChanged(e){return o(this,void 0,void 0,function*(){var t;null===(t=this.config)||void 0===t||t.loggerProvider.debug(`optOut is changed to ${String(e)}, calling ${e?"sessionReplay.shutdown()":"sessionReplay.init()"}.`),e?this.sessionReplay.shutdown():null!=this.config&&(yield this.sessionReplay.init(this.config.apiKey,this.srInitOptions).promise)})}execute(e){return o(this,void 0,void 0,function*(){var t,n,i;try{if(this.options.customSessionId){const t=this.options.customSessionId(e);if(t){t!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(t).promise);const n=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),n)}}else{const i=null===(t=this.config)||void 0===t?void 0:t.sessionId;if(i&&i!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(i).promise),i&&i===e.session_id){let t;e.event_type===r.IDENTIFY&&(t=(e=>{if(!e.user_properties)return;let t={};return Object.keys(e.user_properties).forEach(n=>{if(mn.includes(n)){const r=e.user_properties&&e.user_properties[n];t=Object.assign(Object.assign({},t),r)}}),t})(e));const i=g();yield this.sessionReplay.evaluateTargetingAndCapture({event:e,userProperties:t,page:null!=(null===(n=null==i?void 0:i.location)||void 0===n?void 0:n.href)?{url:i.location.href}:void 0});const o=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),o)}}return e.event_type===r.IDENTIFY&&e.event_properties&&delete e.event_properties["[Amplitude] Session Replay ID"],Promise.resolve(e)}catch(t){return null===(i=this.config)||void 0===i||i.loggerProvider.error(`Session Replay: Failed to enrich event due to ${t.message}`),Promise.resolve(e)}})}teardown(){return o(this,void 0,void 0,function*(){var e;try{this.sessionReplay.shutdown(),this.config=null}catch(t){null===(e=this.config)||void 0===e||e.loggerProvider.error(`Session Replay: teardown failed due to ${t.message}`)}})}getSessionReplayProperties(){return this.sessionReplay.getSessionReplayProperties()}}Sn.pluginName="@amplitude/plugin-session-replay-browser";const In=e=>new Sn(e);export{Sn as S,o as _,s as a,i as b,g,Ze as o,In as s};
2
2
  //# sourceMappingURL=index-min.js.map
Binary file