@amplitude/plugin-session-replay-browser 1.27.8 → 1.27.9
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.
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/index-min.js +1 -1
- package/lib/scripts/index-min.js.gz +0 -0
- package/lib/scripts/index-min.js.map +1 -1
- package/lib/scripts/plugin-session-replay-browser-min.js +1 -1
- package/lib/scripts/plugin-session-replay-browser-min.js.gz +0 -0
- package/lib/scripts/plugin-session-replay-browser-min.js.map +1 -1
- package/package.json +3 -3
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.27.
|
|
1
|
+
export declare const VERSION = "1.27.9";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/cjs/version.js
CHANGED
package/lib/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `pnpm version-file`. DO NOT EDIT\nexport const VERSION = '1.27.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `pnpm version-file`. DO NOT EDIT\nexport const VERSION = '1.27.9';\n"]}
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.27.
|
|
1
|
+
export declare const VERSION = "1.27.9";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/esm/version.js
CHANGED
package/lib/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `pnpm version-file`. DO NOT EDIT\nexport const VERSION = '1.27.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `pnpm version-file`. DO NOT EDIT\nexport const VERSION = '1.27.9';\n"]}
|
package/lib/scripts/index-min.js
CHANGED
|
@@ -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}},w=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}(),I=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:I(r,n)}};var E=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: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 _(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,D=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}(),L="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self,N=function(){function e(){this.identityStore=new D,this.eventBridge=new R,this.applicationContextProvider=new k}return e.getInstance=function(t){return L.analyticsConnectorInstances||(L.analyticsConnectorInstances={}),L.analyticsConnectorInstances[t]||(L.analyticsConnectorInstances[t]=new e),L.analyticsConnectorInstances[t]},e}(),U=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},q=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,w,I,C;if("object"!=typeof e)return null;var E=e.code||0,k=this.buildStatus(E);switch(k){case u.Success:return{status:k,statusCode:E,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:E,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:E,body:{error:null!==(p=e.error)&&void 0!==p?p:""}};case u.RateLimit:return{status:k,statusCode:E,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!==(w=e.exceeded_daily_quota_devices)&&void 0!==w?w:{},exceededDailyQuotaUsers:null!==(I=e.exceeded_daily_quota_users)&&void 0!==I?I:{},throttledEvents:null!==(C=e.throttled_events)&&void 0!==C?C:[]}};case u.Timeout:default:return{status:k,statusCode:E}}},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}(q),F=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 F(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:$,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?$:t;this[H]=!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===$&&(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}H=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,n){var r,i,o;if(void 0===t&&(t={defaultMaskLevel:ue}),n){if(n.closest("."+oe))return!0;var s=(null!==(r=t.maskSelector)&&void 0!==r?r:[]).some(function(e){return n.closest(e)});if(s)return!0;if(n.closest(".amp-unmask"))return!1;var a=(null!==(i=t.unmaskSelector)&&void 0!==i?i:[]).some(function(e){return n.closest(e)});if(a)return!1}return ve(e,null!==(o=t.defaultMaskLevel)&&void 0!==o?o:ue,n)},ge=function(e,t){return function(n,r){return he(e,t,r)?n.replace(/[^\s]/g,"*"):n}},fe=function(e){return function(t,n,r){var i;return"style"===t?n:(null!==(i=null==e?void 0:e.maskAttributes)&&void 0!==i?i:[]).includes(t)&&he("text",e,r)?n.replace(/[^\s]/g,"*"):n}},pe=function(){var e=g();return(null==e?void 0:e.location)?e.location.href:""},me=function(e){var t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp("^".concat(t,"$"))},ye=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=me(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},be=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:""}]}})})},Se=function(e){var t=i({},e),n=t.apiKey;return t.apiKey="****".concat(n.substring(n.length-4)),t},we=function(){return{flushMaxRetries:2,logLevel:h.Warn,loggerProvider:new b,transportProvider:new A}},Ie=function(e){function n(t,n){var r,o,s,a,c,l,u=this,d=we();if((u=e.call(this,i(i({transportProvider:d.transportProvider,loggerProvider:new le(n.loggerProvider||d.loggerProvider)},n),{apiKey:t}))||this).flushMaxRetries=void 0!==n.flushMaxRetries&&n.flushMaxRetries<=d.flushMaxRetries?n.flushMaxRetries:d.flushMaxRetries,u.apiKey=t,u.sampleRate=n.sampleRate||0,u.serverZone=n.serverZone||te,u.configServerUrl=n.configServerUrl,u.trackServerUrl=n.trackServerUrl,u.shouldInlineStylesheet=n.shouldInlineStylesheet,u.version=n.version,u.performanceConfig=n.performanceConfig||ne,u.storeType=null!==(r=n.storeType)&&void 0!==r?r:"idb",u.applyBackgroundColorToBlockedElements=null!==(o=n.applyBackgroundColorToBlockedElements)&&void 0!==o&&o,u.enableUrlChangePolling=null!==(s=n.enableUrlChangePolling)&&void 0!==s&&s,u.urlChangePollingInterval=null!==(a=n.urlChangePollingInterval)&&void 0!==a?a:re,u.captureDocumentTitle=null!==(c=n.captureDocumentTitle)&&void 0!==c&&c,n.privacyConfig&&(u.privacyConfig=n.privacyConfig),n.interactionConfig&&(u.interactionConfig=n.interactionConfig,u.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")}(u.interactionConfig.ugcFilterRules)),n.debugMode&&(u.debugMode=n.debugMode),void 0!==n.useWebWorker)u.useWebWorker=n.useWebWorker;else{var v=n;void 0!==(null===(l=v.experimental)||void 0===l?void 0:l.useWebWorker)&&(u.useWebWorker=v.experimental.useWebWorker)}return n.omitElementTags&&(u.omitElementTags=n.omitElementTags),u}return t(n,e),n}(w),Ce=(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))(Ce||{}),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||{}),ke=function(){function e(e,t){this.localConfig=t,this.remoteConfigClient=e}return e.prototype.generateJoinedConfig=function(){var e,t,n,r,u;return o(this,void 0,void 0,function(){var o,d,v,h,g,f,p,m,y,b,S,w,I,C,E,k,P,R=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){R.remoteConfigClient.subscribe("configs.sessionReplay","all",function(n,r){var i;if(R.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)&&(d={},a&&(d.sr_sampling_config=a),c&&(d.sr_privacy_config=c),l&&(d.sr_targeting_config=l)),e()}else t(new Error("No remote config received"))})})];case 2:return s.sent(),[3,4];case 3:return v=s.sent(),this.localConfig.loggerProvider.error("Failed to generate joined config: ",v),o.captureEnabled=!1,[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:void 0}];case 4:if(!d)return[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:d}];if(h=d.sr_sampling_config,g=d.sr_privacy_config,f=d.sr_targeting_config,h&&Object.keys(h).length>0?(Object.prototype.hasOwnProperty.call(h,"capture_enabled")?o.captureEnabled=h.capture_enabled:o.captureEnabled=!1,Object.prototype.hasOwnProperty.call(h,"sample_rate")&&(o.sampleRate=h.sample_rate)):(o.captureEnabled=!0,this.localConfig.loggerProvider.debug("Remote config successfully fetched, but no values set for project, Session Replay capture enabled.")),g){p=null!==(e=o.privacyConfig)&&void 0!==e?e:{},m={defaultMaskLevel:null!==(n=null!==(t=g.defaultMaskLevel)&&void 0!==t?t:p.defaultMaskLevel)&&void 0!==n?n:"medium",blockSelector:[],maskSelector:[],unmaskSelector:[],maskAttributes:l([],c(new Set(l(l([],c(null!==(r=p.maskAttributes)&&void 0!==r?r:[]),!1),c(null!==(u=g.maskAttributes)&&void 0!==u?u:[]),!1))),!1)},y=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},b=i(i({},y(p)),y(g));try{for(S=a(Object.entries(b)),w=S.next();!w.done;w=S.next())I=c(w.value,2),C=I[0],"mask"===(E=I[1])?m.maskSelector.push(C):"block"===E?m.blockSelector.push(C):"unmask"===E&&m.unmaskSelector.push(C)}catch(e){k={error:e}}finally{try{w&&!w.done&&(P=S.return)&&P.call(S)}finally{if(k)throw k.error}}o.privacyConfig=(T=m,_=this.localConfig.loggerProvider,O=document.createDocumentFragment(),x=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},T.blockSelector=x(T.blockSelector),T.maskSelector=x(T.maskSelector),T.unmaskSelector=x(T.unmaskSelector),T)}return f&&Object.keys(f).length>0&&(o.targetingConfig=f),this.localConfig.loggerProvider.debug(JSON.stringify({name:"session replay joined config",config:Se(o)},null,2)),[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:d}]}var T,_,O,x})})},e}(),Pe=function(e,t){return o(void 0,void 0,void 0,function(){var n,r;return s(this,function(i){return n=new Ie(e,t),r=new K(e,n.loggerProvider,n.serverZone,t.configServerUrl),[2,new ke(r,n)]})})},Re=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===Ce.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}(),Te="Session replay event batch rejected due to exceeded retry count",_e="Failed to store session replay events in IndexedDB",Oe="1.36.1";function xe(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 Me=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:Te}),!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:pe(),sdkVersion:Oe}})})]})})},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,w,I,C,E,k;return s(this,function(s){switch(s.label){case 0:o=pe(),v=Oe,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,xe(m,y)]:[3,3];case 2:return S=s.sent(),[3,4];case 3:S=null,s.label=4;case 4:return b=S,w={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"},I="".concat(de(n.serverZone,this.trackServerUrl),"?").concat(f.toString()),[4,fetch(I,w)];case 5:if(null===(C=s.sent()))return this.completeRequest({context:n,err:"Unexpected error occurred"}),[2];if(a)return[3,6];E="";try{E=JSON.stringify(C.body,null,2)}catch(e){}return this.completeRequest({context:n,success:"".concat(C.status,": ").concat(E)}),[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 q).buildStatus(e),n){case u.Success:return[3,1];case u.Failed:return[3,2]}return[3,4];case 1:return this.handleSuccessResponse(t),[3,5];case 2:return[4,this.handleOtherResponse(t)];case 3:return r.sent(),[3,5];case 4:this.completeRequest({context:t,err:"Network error occurred, event batch rejected"}),r.label=5;case 5: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:Te}),[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 De=(e,t)=>t.some(t=>e instanceof t);let Le,Ne;const Ue=new WeakMap,qe=new WeakMap,Ae=new WeakMap;let Fe={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return Ue.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return Ke(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function je(e){Fe=e(Fe)}function Be(e){return(Ne||(Ne=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(He(this),t),Ke(this.request)}:function(...t){return Ke(e.apply(He(this),t))}}function We(e){return"function"==typeof e?Be(e):(e instanceof IDBTransaction&&function(e){if(Ue.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)});Ue.set(e,t)}(e),De(e,Le||(Le=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,Fe):e)}function Ke(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(Ke(e.result)),r()},o=()=>{n(e.error),r()};e.addEventListener("success",i),e.addEventListener("error",o)});return Ae.set(t,e),t}(e);if(qe.has(e))return qe.get(e);const t=We(e);return t!==e&&(qe.set(e,t),Ae.set(t,e)),t}const He=e=>Ae.get(e);function $e(e,t,{blocked:n,upgrade:r,blocking:i,terminated:o}={}){const s=indexedDB.open(e,t),a=Ke(s);return r&&s.addEventListener("upgradeneeded",e=>{r(Ke(s.result),e.oldVersion,e.newVersion,Ke(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 ze=["get","getKey","getAll","getAllKeys","count"],Je=["put","add","delete","clear"],Ge=new Map;function Ve(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(Ge.get(t))return Ge.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,i=Je.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!i&&!ze.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 Ge.set(t,o),o}je(e=>({...e,get:(t,n,r)=>Ve(t,n)||e.get(t,n,r),has:(t,n)=>!!Ve(t,n)||e.has(t,n)}));const Ze=["continue","continuePrimaryKey","advance"],Qe={},Ye=new WeakMap,Xe=new WeakMap,et={get(e,t){if(!Ze.includes(t))return e[t];let n=Qe[t];return n||(n=Qe[t]=function(...e){Ye.set(this,Xe.get(this)[t](...e))}),n}};async function*tt(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,et);for(Xe.set(n,t),Ae.set(n,He(t));t;)yield n,t=await(Ye.get(n)||t.continue()),Ye.delete(n)}function nt(e,t){return t===Symbol.asyncIterator&&De(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&De(e,[IDBIndex,IDBObjectStore])}je(e=>({...e,get:(t,n,r)=>nt(t,n)?tt:e.get(t,n,r),has:(t,n)=>nt(t,n)||e.has(t,n)}));var rt,it,ot,st=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}(),at=function(e,t,n){var r;"object"==typeof(r=n)&&null!==r&&"AbortError"===r.name?e.debug(t):e.warn(t)},ct="sessionCurrentSequence",lt="sequencesToSend",ut=function(e){var t,n;return e.objectStoreNames.contains(ct)||(n=e.createObjectStore(ct,{keyPath:"sessionId"})),e.objectStoreNames.contains(lt)||(t=e.createObjectStore(lt,{keyPath:"sequenceId",autoIncrement:!0})).createIndex("sessionId","sessionId"),{sequencesStore:t,currentSequenceStore:n}},dt=function(e){return o(void 0,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,$e(e,1,{upgrade:ut})];case 1:return[2,t.sent()]}})})},vt=function(e){function n(t){var n=e.call(this,t)||this;return n.getSequencesToSend=function(){return o(n,void 0,void 0,function(){var e,t,n,r,i,o;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),e=[],[4,this.db.transaction("sequencesToSend").store.openCursor()];case 1:t=s.sent(),s.label=2;case 2:return t?(n=t.value,r=n.sessionId,i=n.events,e.push({events:i,sequenceId:t.key,sessionId:r}),[4,t.continue()]):[3,4];case 3:return t=s.sent(),[3,2];case 4:return[2,e];case 5:return o=s.sent(),at(this.loggerProvider,"".concat(_e,": ").concat(o),o),[3,6];case 6:return[2,void 0]}})})},n.storeCurrentSequence=function(e){return o(n,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(ct,e)];case 1:return(t=o.sent())?[4,this.db.put(lt,{sessionId:e,events:t.events})]:[2,void 0];case 2:return n=o.sent(),[4,this.db.put(ct,{sessionId:e,events:[]})];case 3:return o.sent(),[2,i(i({},t),{sessionId:e,sequenceId:n})];case 4:return r=o.sent(),at(this.loggerProvider,"".concat(_e,": ").concat(r),r),[3,5];case 5:return[2,void 0]}})})},n.addEventToCurrentSequence=function(e,t){return o(n,void 0,void 0,function(){var n,r,i,o,a,c;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,10,,11]),[4,(n=this.db.transaction(ct,"readwrite")).store.get(e)];case 1:return(r=s.sent())?[3,3]:[4,n.store.put({sessionId:e,events:[t]})];case 2:return s.sent(),[2];case 3:return i=void 0,this.shouldSplitEventsList(r.events,t)?(i=r.events,[4,n.store.put({sessionId:e,events:[t]})]):[3,5];case 4:return s.sent(),[3,7];case 5:return o=r.events.concat(t),[4,n.store.put({sessionId:e,events:o})];case 6:s.sent(),s.label=7;case 7:return[4,n.done];case 8:return s.sent(),i?[4,this.storeSendingEvents(e,i)]:[2,void 0];case 9:return(a=s.sent())?[2,{events:i,sessionId:e,sequenceId:a}]:[2,void 0];case 10:return c=s.sent(),at(this.loggerProvider,"".concat(_e,": ").concat(c),c),[3,11];case 11:return[2,void 0]}})})},n.storeSendingEvents=function(e,t){return o(n,void 0,void 0,function(){var n;return s(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.db.put(lt,{sessionId:e,events:t})];case 1:return[2,r.sent()];case 2:return n=r.sent(),at(this.loggerProvider,"".concat(_e,": ").concat(n),n),[3,3];case 3:return[2,void 0]}})})},n.cleanUpSessionEventsStore=function(e,t){return o(n,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(lt,t)];case 2:return n.sent(),[3,4];case 3:return e=n.sent(),at(this.loggerProvider,"".concat(_e,": ").concat(e),e),[3,4];case 4:return[2]}})})},n.db=t.db,n}return t(n,e),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,dt(o)];case 1:return a=s.sent(),[2,new n(i(i({},t),{db:a}))];case 2:return c=s.sent(),at(t.loggerProvider,"".concat(_e,": ").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}(st),ht=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}(st),gt=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,w,I,C,E;return s(this,function(k){switch(k.label){case 0:return h=new Me(i(i({},t),{loggerProvider:t.loggerProvider,payloadBatcher:u,workerScript:v})),g=function(){return new ht({loggerProvider:t.loggerProvider,maxInterval:r,minInterval:n})},f=function(){return o(void 0,void 0,void 0,function(){var e;return s(this,function(i){switch(i.label){case 0:return[4,vt.new(a,{loggerProvider:t.loggerProvider,minInterval:n,maxInterval:r,apiKey:t.apiKey})];case 1:return(e=i.sent())?[2,e]:(t.loggerProvider.log("Failed to initialize idb store, falling back to memory store."),[2,g()])}})})},"idb"!==d?[3,2]:[4,f()];case 1:return m=k.sent(),[3,3];case 2:m=g(),k.label=3;case 3:return p=m,y=[],b=0,S=function(e){if(!(e<=b)){var t=Math.min(e-b,y.length);t>0&&(y.splice(0,t),b=e)}},w=function(e){var n=e.events,r=e.sessionId,i=e.deviceId,c=e.sequenceId;t.debugMode&&be().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,p.cleanUpSessionEventsStore(r,c)];case 1:return e.sent(),[2]}})})}})},I=function(e){var n=e.sessionId,r=e.deviceId,i=b+y.length;p.storeCurrentSequence(n).then(function(e){e&&(S(i),w({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)})},C=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[4,p.getSequencesToSend()];case 1:return(e=n.sent())&&e.forEach(function(e){w({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:t})}),[2]}})})},E=function(e){var n=e.event,r=e.sessionId,i=e.deviceId,o=b+y.length;y.push(n.data),p.addEventToCurrentSequence(r,n.data).then(function(e){e&&(S(o),w({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:I,addEvent:E,sendStoredEvents:C,flush:e,getBeaconEvents:function(){return l([],c(y),!1)},trackDestination:h}]}})})},ft=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 pt(e,t){if(ot=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};rt=i(i({},n),t),it=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(rt.root,n);var r=mt(e,"all",function(){return mt(e,"two",function(){return mt(e,"one",function(){return mt(e,"none")})})});if(r){var o=Rt(Tt(r,e));return o.length>0&&(r=o[0]),bt(r)}throw new Error("Selector was not found.")}function mt(e,t,n){for(var r=null,i=[],o=e,s=0,u=function(){var e,u,d=(new Date).getTime()-ot.getTime();if(void 0!==rt.timeoutMs&&d>rt.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&&rt.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 rt.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(rt.className);return t.map(function(e){return{name:"."+CSS.escape(e),penalty:1}})}(o)),!1))||Et(function(e){var t=e.tagName.toLowerCase();if(rt.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(Ct).map(function(e){return It(e,h)})));else if("two"==t)v=v.slice(0,1),h&&(v=v.concat(v.filter(Ct).map(function(e){return It(e,h)})));else if("one"==t){var g=c(v=v.slice(0,1),1)[0];h&&Ct(g)&&(v=[It(g,h)])}else"none"==t&&(v=[{name:"*",penalty:3}],h&&(v=[It(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>=rt.seedMinLength&&(r=yt(i,n)))return"break";o=o.parentElement,s++};o;){if("break"===u())break}return r||(r=yt(i,n)),!r&&n?n():r}function yt(e,t){var n,r,i=Rt(Pt(e));if(i.length>rt.threshold)return t?t():null;try{for(var o=a(i),s=o.next();!s.done;s=o.next()){var c=s.value;if(wt(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 bt(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 St(e){return e.map(function(e){return e.penalty}).reduce(function(e,t){return e+t},0)}function wt(e){var t=bt(e);switch(it.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 It(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function Ct(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(kt);return n.length>0?n:null}function kt(e){return null!=e}function Pt(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(Pt(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 Rt(e){return l([],c(e),!1).sort(function(e,t){return St(e)-St(t)})}function Tt(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>rt.optimizedMinLength))return[3,5];r=1,s.label=1;case 1:return r<e.length-1?n.counter>rt.maxNumberOfTries?[2]:(n.counter+=1,(i=l([],c(e),!1)).splice(r,1),o=bt(i),n.visited.has(o)?[2]:wt(i)&&function(e,t){return it.querySelector(bt(e))===t}(i,t)?[4,i]:[3,4]):[3,5];case 2:return s.sent(),n.visited.set(o,!0),[5,a(Tt(i,t,n))];case 3:s.sent(),s.label=4;case 4:return r++,[3,1];case 5:return[2]}})}var _t=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}},Ot=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)}},xt=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=pt(p,a)}catch(e){n.logger.debug("error resolving selector from finder")}var m=ye(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 Mt(){var e=g();return(null==e?void 0:e.innerHeight)||document.documentElement&&document.documentElement.clientHeight||0}function Dt(){var e=g();return(null==e?void 0:e.innerWidth)||document.documentElement&&document.documentElement.clientWidth||0}var Lt=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}(),Nt=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:Mt(),viewportWidth:Dt(),pageUrl:ye(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=Dt(),this._maxScrollHeight=Mt(),this.config=t,this.transport=e}return e.default=function(t,n){return new e(new Lt(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=Dt();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=Mt();this._maxScrollY=e.y;var o=e.y+i;o>this._maxScrollHeight&&(this._maxScrollHeight=o),this.timestamp=t}},e}(),Ut=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))},qt=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,$e(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(),at(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(),at(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(),at(n,"Failed to clear old targeting matches for sessions: ".concat(d),d),[3,9];case 9:return[2]}})})}},At=new qt,Ft=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,At.clearStoreOfOldSessions({loggerProvider:r,apiKey:a,currentSessionId:t})];case 1:return s.sent(),[4,At.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),At.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]}})})},jt=2654435761,Bt=2246822519,Wt=3266489917,Kt=374761393;function Ht(e,t){return(e<<t|e>>>32-t)>>>0}function $t(e,t){return e=Ht(e=e+Math.imul(t,Bt)>>>0,13),e=Math.imul(e,jt)>>>0}function zt(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function Jt(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+jt+Bt>>>0,a=t+Bt>>>0,c=t>>>0,l=t-jt>>>0;o<=i-16;)s=$t(s,zt(r,o)),a=$t(a,zt(r,o+=4)),c=$t(c,zt(r,o+=4)),l=$t(l,zt(r,o+=4)),o+=4;n=Ht(s,1)+Ht(a,7)+Ht(c,12)+Ht(l,18)>>>0}else n=t+Kt>>>0;for(n=n+i>>>0;o<=i-4;)n=n+Math.imul(zt(r,o),Wt)>>>0,n=Math.imul(Ht(n,17),668265263)>>>0,o+=4;for(;o<i;)n=n+Math.imul(r[o],Kt)>>>0,n=Math.imul(Ht(n,11),jt)>>>0,o++;return n^=n>>>15,n=Math.imul(n,Bt)>>>0,n^=n>>>13,n=Math.imul(n,Wt)>>>0,(n^=n>>>16)>>>0}var Gt="__amplitude_url_tracking_patched__",Vt=new WeakMap;function Zt(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=Vt.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[Gt]=!0,t},f=e.history;if(null==f?void 0:f.pushState){var p=Reflect.get(f,"pushState");p[Gt]||(f.pushState=g(p))}if(null==f?void 0:f.replaceState){var m=Reflect.get(f,"replaceState");m[Gt]||(f.replaceState=g(m))}u={callbacks:v,notify:h,onPopStateOrHashChange:function(){return h()},listenersAttached:!1},Vt.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 Qt(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?ye(i,l):i,title:o,viewportHeight:e,viewportWidth:t,type:"url-change-event"}}();t(r)}},p=Zt(n,function(){return f()},u?{enablePolling:!0,pollingInterval:d}:{});return f(),function(){return p()}},options:e}}Qt();var Yt,Xt,en,tn=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.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(){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,Ft({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:Se(o),version:Oe},r?[4,be()]:[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.setupUrlChangeListenerForTargeting=function(){var e,t=this;null===(e=this.urlChangeCleanup)||void 0===e||e.call(this);var n=g();if(null==n?void 0:n.location){var r=Zt(n,function(e){var n=++t.latestUrlChangeTargetingEvaluationId;t.evaluateTargetingAndCapture({userProperties:{},event:void 0,page:{url:e}},!1,!1,!0),t.loggerProvider.debug("Queued URL-change targeting re-evaluation #".concat(n," for ").concat(e,"."))});this.urlChangeCleanup=function(){r(),t.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;return o(this,void 0,void 0,function(){var o,p,m,y,S,w,I,C,E,k,P,R,T,_,O,x,M,D,L,N,U,q=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.identifiers=new Ut({sessionId:t.sessionId,deviceId:t.deviceId}),o=this,[4,Pe(e,t)];case 1:return o.joinedConfigGenerator=s.sent(),[4,this.joinedConfigGenerator.generateJoinedConfig()];case 2:return p=s.sent(),m=p.joinedConfig,y=p.localConfig,S=p.remoteConfig,this.config=m,this.setMetadata(t.sessionId,m,y,S,null===(r=t.version)||void 0===r?void 0:r.version,Oe,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)&&(w=Nt.default({sessionId:t.sessionId,type:"interaction"},this.config),this.pageLeaveFns=[w.send(this.getDeviceId.bind(this)).bind(w)],this.scrollHook=w.hook.bind(w),this.clickHandler=new xt(this.loggerProvider,w)),I=[],"idb"!==(C=this.config.storeType)||(null===(d=g())||void 0===d?void 0:d.indexedDB)||(C="memory",this.loggerProvider.warn("Could not use preferred indexedDB storage, reverting to in memory option.")),this.loggerProvider.log("Using ".concat(C," for event storage.")),P=g(),this.config.useWebWorker&&P&&P.Worker?[4,import("./index-min2.js")]:[3,4];case 3:R=s.sent(),T=R.compressionScript,_=R.trackDestinationScript,E=T,k=_,s.label=4;case 4:return s.trys.push([4,6,,7]),[4,gt({config:this.config,type:"replay",storeType:C,trackDestinationWorkerScript:k})];case 5:return O=s.sent(),I.push({name:"replay",manager:O}),[3,7];case 6:return x=s.sent(),N=x,this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(N.toString())),[3,7];case 7:if(!(null===(v=this.config.interactionConfig)||void 0===v?void 0:v.enabled))return[3,11];M=this.config.interactionConfig.batch?Ot:_t,s.label=8;case 8:return s.trys.push([8,10,,11]),[4,gt({config:this.config,type:"interaction",minInterval:null!==(h=this.config.interactionConfig.trackEveryNms)&&void 0!==h?h:3e4,maxInterval:6e4,payloadBatcher:M,storeType:C,trackDestinationWorkerScript:k})];case 9:return D=s.sent(),I.push({name:"interaction",manager:D}),[3,11];case 10:return L=s.sent(),N=L,this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(N.toString())),[3,11];case 11:return this.eventsManager=new(ft.bind.apply(ft,l([void 0],c(I),!1))),this.eventCompressor&&this.eventCompressor.terminate(),this.eventCompressor=new Re(this.eventsManager,this.config,this.getDeviceId(),E,function(){return q.sendEvents()}),this.pageLeaveFns=l(l([],c(this.pageLeaveFns),!1),[function(){var e;if(q.config&&(null===(e=q.identifiers)||void 0===e?void 0:e.sessionId)&&O){var t=O.getBeaconEvents();if(t.length){var n=q.getDeviceId();n&&O.trackDestination.sendBeacon({events:t,sessionId:q.identifiers.sessionId,deviceId:n,apiKey:q.config.apiKey,serverZone:q.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})}}(U=Z()),U.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&&this.setupUrlChangeListenerForTargeting(),[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 Ut({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:U(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),N.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,Jt(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,r;if("conservative"===(null===(t=null===(e=this.config)||void 0===e?void 0:e.privacyConfig)||void 0===t?void 0:t.defaultMaskLevel))return"*";var i=null===(r=null===(n=this.config)||void 0===n?void 0:n.privacyConfig)||void 0===r?void 0:r.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=Qt({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){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,w,I,C,E,k,P=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)})||P.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}:{},w=(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]),I=this,C=h,k={emit:function(e){if(P.shouldOptOut())return P.loggerProvider.log("Opting session ".concat(v," out of recording due to optOut config.")),P.stopRecordingEvents(),void P.sendEvents();e.type===Ce.Meta&&(e.data.href=ye(e.data.href,w)),P.eventCompressor&&P.eventCompressor.enqueueEvent(e,v)},inlineStylesheet:o.shouldInlineStylesheet,hooks:S,maskAllInputs:!0,maskTextClass:oe,blockClass:"amp-block",blockSelector:this.getBlockSelectors(),applyBackgroundColorToBlockedElements:o.applyBackgroundColorToBlockedElements,maskInputFn:ge("input",m),maskTextFn:ge("text",m),maskAttributeFn:fe(m),maskTextSelector:this.getMaskTextSelectors(),recordCanvas:!1,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 P.loggerProvider.warn("Error while capturing replay: ",t.toString()),!0}},[4,this.getRecordingPlugins(b)];case 4:return I.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 E=s.sent(),this.loggerProvider.warn("Failed to initialize session replay:",E),[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())?U(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}(),nn=function(e){return function(){var t=e.config||we();return{logger:t.loggerProvider,logLevel:t.logLevel}}},rn=function(){var e=new tn;return{init:E(e.init.bind(e),"init",nn(e)),evaluateTargetingAndCapture:E(e.evaluateTargetingAndCapture.bind(e),"evaluateTargetingAndRecord",nn(e)),setSessionId:E(e.setSessionId.bind(e),"setSessionId",nn(e)),getSessionId:E(e.getSessionId.bind(e),"getSessionId",nn(e)),getSessionReplayProperties:E(e.getSessionReplayProperties.bind(e),"getSessionReplayProperties",nn(e)),flush:E(e.flush.bind(e),"flush",nn(e)),shutdown:E(e.shutdown.bind(e),"shutdown",nn(e))}}(),on=rn.init,sn=rn.setSessionId,an=rn.getSessionId,cn=rn.getSessionReplayProperties,ln=rn.flush,un=rn.shutdown,dn=rn.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"}(Yt||(Yt={})),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"}(Xt||(Xt={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(en||(en={}));const vn=[Yt.SET,Yt.SET_ONCE,Yt.ADD,Yt.APPEND,Yt.PREPEND,Yt.POSTINSERT],hn="1.27.8";class gn{constructor(e){this.name=gn.pluginName,this.type="enrichment",this.config=null,this.sessionReplay={flush:ln,getSessionId:an,getSessionReplayProperties:cn,init:on,setSessionId:sn,shutdown:un,evaluateTargetingAndCapture:dn},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 ${hn}.`),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"),N.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:hn},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},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(vn.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()}}gn.pluginName="@amplitude/plugin-session-replay-browser";const fn=e=>new gn(e);export{gn as S,o as _,s as a,i as b,g,$e as o,fn 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{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}},w=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}(),I=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:I(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(),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}},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 _(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,D=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}(),L="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self,N=function(){function e(){this.identityStore=new D,this.eventBridge=new R,this.applicationContextProvider=new E}return e.getInstance=function(t){return L.analyticsConnectorInstances||(L.analyticsConnectorInstances={}),L.analyticsConnectorInstances[t]||(L.analyticsConnectorInstances[t]=new e),L.analyticsConnectorInstances[t]},e}(),U=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},q=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,w,I,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!==(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:E,statusCode:k,body:{error:null!==(p=e.error)&&void 0!==p?p:""}};case u.RateLimit:return{status:E,statusCode:k,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!==(w=e.exceeded_daily_quota_devices)&&void 0!==w?w:{},exceededDailyQuotaUsers:null!==(I=e.exceeded_daily_quota_users)&&void 0!==I?I:{},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}(q),F=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 F(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:$,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?$:t;this[H]=!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===$&&(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}H=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,n){var r,i,o;if(void 0===t&&(t={defaultMaskLevel:ue}),n){if(n.closest("."+oe))return!0;var s=(null!==(r=t.maskSelector)&&void 0!==r?r:[]).some(function(e){return n.closest(e)});if(s)return!0;if(n.closest(".amp-unmask"))return!1;var a=(null!==(i=t.unmaskSelector)&&void 0!==i?i:[]).some(function(e){return n.closest(e)});if(a)return!1}return ve(e,null!==(o=t.defaultMaskLevel)&&void 0!==o?o:ue,n)},ge=function(e,t){return function(n,r){return he(e,t,r)?n.replace(/[^\s]/g,"*"):n}},fe=function(e){return function(t,n,r){var i;return"style"===t?n:(null!==(i=null==e?void 0:e.maskAttributes)&&void 0!==i?i:[]).includes(t)&&he("text",e,r)?n.replace(/[^\s]/g,"*"):n}},pe=function(){var e=g();return(null==e?void 0:e.location)?e.location.href:""},me=function(e){var t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp("^".concat(t,"$"))},ye=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=me(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},be=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:""}]}})})},Se=function(e){var t=i({},e),n=t.apiKey;return t.apiKey="****".concat(n.substring(n.length-4)),t},we=function(){return{flushMaxRetries:2,logLevel:h.Warn,loggerProvider:new b,transportProvider:new A}},Ie=function(e){function n(t,n){var r,o,s,a,c,l,u=this,d=we();if((u=e.call(this,i(i({transportProvider:d.transportProvider,loggerProvider:new le(n.loggerProvider||d.loggerProvider)},n),{apiKey:t}))||this).flushMaxRetries=void 0!==n.flushMaxRetries&&n.flushMaxRetries<=d.flushMaxRetries?n.flushMaxRetries:d.flushMaxRetries,u.apiKey=t,u.sampleRate=n.sampleRate||0,u.serverZone=n.serverZone||te,u.configServerUrl=n.configServerUrl,u.trackServerUrl=n.trackServerUrl,u.shouldInlineStylesheet=n.shouldInlineStylesheet,u.version=n.version,u.performanceConfig=n.performanceConfig||ne,u.storeType=null!==(r=n.storeType)&&void 0!==r?r:"idb",u.applyBackgroundColorToBlockedElements=null!==(o=n.applyBackgroundColorToBlockedElements)&&void 0!==o&&o,u.enableUrlChangePolling=null!==(s=n.enableUrlChangePolling)&&void 0!==s&&s,u.urlChangePollingInterval=null!==(a=n.urlChangePollingInterval)&&void 0!==a?a:re,u.captureDocumentTitle=null!==(c=n.captureDocumentTitle)&&void 0!==c&&c,n.privacyConfig&&(u.privacyConfig=n.privacyConfig),n.interactionConfig&&(u.interactionConfig=n.interactionConfig,u.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")}(u.interactionConfig.ugcFilterRules)),n.debugMode&&(u.debugMode=n.debugMode),void 0!==n.useWebWorker)u.useWebWorker=n.useWebWorker;else{var v=n;void 0!==(null===(l=v.experimental)||void 0===l?void 0:l.useWebWorker)&&(u.useWebWorker=v.experimental.useWebWorker)}return n.omitElementTags&&(u.omitElementTags=n.omitElementTags),u}return t(n,e),n}(w),Ce=(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))(Ce||{}),ke=(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))(ke||{}),Ee=function(){function e(e,t){this.localConfig=t,this.remoteConfigClient=e}return e.prototype.generateJoinedConfig=function(){var e,t,n,r,u;return o(this,void 0,void 0,function(){var o,d,v,h,g,f,p,m,y,b,S,w,I,C,k,E,P,R=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){R.remoteConfigClient.subscribe("configs.sessionReplay","all",function(n,r){var i;if(R.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)&&(d={},a&&(d.sr_sampling_config=a),c&&(d.sr_privacy_config=c),l&&(d.sr_targeting_config=l)),e()}else t(new Error("No remote config received"))})})];case 2:return s.sent(),[3,4];case 3:return v=s.sent(),this.localConfig.loggerProvider.error("Failed to generate joined config: ",v),o.captureEnabled=!1,[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:void 0}];case 4:if(!d)return[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:d}];if(h=d.sr_sampling_config,g=d.sr_privacy_config,f=d.sr_targeting_config,h&&Object.keys(h).length>0?(Object.prototype.hasOwnProperty.call(h,"capture_enabled")?o.captureEnabled=h.capture_enabled:o.captureEnabled=!1,Object.prototype.hasOwnProperty.call(h,"sample_rate")&&(o.sampleRate=h.sample_rate)):(o.captureEnabled=!0,this.localConfig.loggerProvider.debug("Remote config successfully fetched, but no values set for project, Session Replay capture enabled.")),g){p=null!==(e=o.privacyConfig)&&void 0!==e?e:{},m={defaultMaskLevel:null!==(n=null!==(t=g.defaultMaskLevel)&&void 0!==t?t:p.defaultMaskLevel)&&void 0!==n?n:"medium",blockSelector:[],maskSelector:[],unmaskSelector:[],maskAttributes:l([],c(new Set(l(l([],c(null!==(r=p.maskAttributes)&&void 0!==r?r:[]),!1),c(null!==(u=g.maskAttributes)&&void 0!==u?u:[]),!1))),!1)},y=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},b=i(i({},y(p)),y(g));try{for(S=a(Object.entries(b)),w=S.next();!w.done;w=S.next())I=c(w.value,2),C=I[0],"mask"===(k=I[1])?m.maskSelector.push(C):"block"===k?m.blockSelector.push(C):"unmask"===k&&m.unmaskSelector.push(C)}catch(e){E={error:e}}finally{try{w&&!w.done&&(P=S.return)&&P.call(S)}finally{if(E)throw E.error}}o.privacyConfig=(T=m,_=this.localConfig.loggerProvider,O=document.createDocumentFragment(),x=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},T.blockSelector=x(T.blockSelector),T.maskSelector=x(T.maskSelector),T.unmaskSelector=x(T.unmaskSelector),T)}return f&&Object.keys(f).length>0&&(o.targetingConfig=f),this.localConfig.loggerProvider.debug(JSON.stringify({name:"session replay joined config",config:Se(o)},null,2)),[2,{localConfig:this.localConfig,joinedConfig:o,remoteConfig:d}]}var T,_,O,x})})},e}(),Pe=function(e,t){return o(void 0,void 0,void 0,function(){var n,r;return s(this,function(i){return n=new Ie(e,t),r=new K(e,n.loggerProvider,n.serverZone,t.configServerUrl),[2,new Ee(r,n)]})})},Re=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===Ce.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}(),Te="Session replay event batch rejected due to exceeded retry count",_e="Failed to store session replay events in IndexedDB",Oe="1.36.2";function xe(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 Me=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:Te}),!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:pe(),sdkVersion:Oe}})})]})})},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,w,I,C,k,E;return s(this,function(s){switch(s.label){case 0:o=pe(),v=Oe,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,xe(m,y)]:[3,3];case 2:return S=s.sent(),[3,4];case 3:S=null,s.label=4;case 4:return b=S,w={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"},I="".concat(de(n.serverZone,this.trackServerUrl),"?").concat(f.toString()),[4,fetch(I,w)];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 q).buildStatus(e),n){case u.Success:return[3,1];case u.Failed:return[3,2]}return[3,4];case 1:return this.handleSuccessResponse(t),[3,5];case 2:return[4,this.handleOtherResponse(t)];case 3:return r.sent(),[3,5];case 4:this.completeRequest({context:t,err:"Network error occurred, event batch rejected"}),r.label=5;case 5: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:Te}),[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 De=(e,t)=>t.some(t=>e instanceof t);let Le,Ne;const Ue=new WeakMap,qe=new WeakMap,Ae=new WeakMap;let Fe={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return Ue.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return Ke(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function je(e){Fe=e(Fe)}function Be(e){return(Ne||(Ne=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(He(this),t),Ke(this.request)}:function(...t){return Ke(e.apply(He(this),t))}}function We(e){return"function"==typeof e?Be(e):(e instanceof IDBTransaction&&function(e){if(Ue.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)});Ue.set(e,t)}(e),De(e,Le||(Le=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,Fe):e)}function Ke(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(Ke(e.result)),r()},o=()=>{n(e.error),r()};e.addEventListener("success",i),e.addEventListener("error",o)});return Ae.set(t,e),t}(e);if(qe.has(e))return qe.get(e);const t=We(e);return t!==e&&(qe.set(e,t),Ae.set(t,e)),t}const He=e=>Ae.get(e);function $e(e,t,{blocked:n,upgrade:r,blocking:i,terminated:o}={}){const s=indexedDB.open(e,t),a=Ke(s);return r&&s.addEventListener("upgradeneeded",e=>{r(Ke(s.result),e.oldVersion,e.newVersion,Ke(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 ze=["get","getKey","getAll","getAllKeys","count"],Je=["put","add","delete","clear"],Ge=new Map;function Ve(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(Ge.get(t))return Ge.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,i=Je.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!i&&!ze.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 Ge.set(t,o),o}je(e=>({...e,get:(t,n,r)=>Ve(t,n)||e.get(t,n,r),has:(t,n)=>!!Ve(t,n)||e.has(t,n)}));const Ze=["continue","continuePrimaryKey","advance"],Qe={},Ye=new WeakMap,Xe=new WeakMap,et={get(e,t){if(!Ze.includes(t))return e[t];let n=Qe[t];return n||(n=Qe[t]=function(...e){Ye.set(this,Xe.get(this)[t](...e))}),n}};async function*tt(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,et);for(Xe.set(n,t),Ae.set(n,He(t));t;)yield n,t=await(Ye.get(n)||t.continue()),Ye.delete(n)}function nt(e,t){return t===Symbol.asyncIterator&&De(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&De(e,[IDBIndex,IDBObjectStore])}je(e=>({...e,get:(t,n,r)=>nt(t,n)?tt:e.get(t,n,r),has:(t,n)=>nt(t,n)||e.has(t,n)}));var rt,it,ot,st=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}(),at=function(e,t,n){var r;"object"==typeof(r=n)&&null!==r&&"AbortError"===r.name?e.debug(t):e.warn(t)},ct="sessionCurrentSequence",lt="sequencesToSend",ut=function(e){var t,n;return e.objectStoreNames.contains(ct)||(n=e.createObjectStore(ct,{keyPath:"sessionId"})),e.objectStoreNames.contains(lt)||(t=e.createObjectStore(lt,{keyPath:"sequenceId",autoIncrement:!0})).createIndex("sessionId","sessionId"),{sequencesStore:t,currentSequenceStore:n}},dt=function(e){return o(void 0,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,$e(e,1,{upgrade:ut})];case 1:return[2,t.sent()]}})})},vt=function(e){function n(t){var n=e.call(this,t)||this;return n.getSequencesToSend=function(){return o(n,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||at(l.loggerProvider,"".concat(_e,": ").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[2,t];case 6:return c=s.sent(),e=!0,at(this.loggerProvider,"".concat(_e,": ").concat(c),c),[3,7];case 7:return[2,void 0]}})})},n.storeCurrentSequence=function(e){return o(n,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(ct,e)];case 1:return(t=o.sent())?[4,this.db.put(lt,{sessionId:e,events:t.events})]:[2,void 0];case 2:return n=o.sent(),[4,this.db.put(ct,{sessionId:e,events:[]})];case 3:return o.sent(),[2,i(i({},t),{sessionId:e,sequenceId:n})];case 4:return r=o.sent(),at(this.loggerProvider,"".concat(_e,": ").concat(r),r),[3,5];case 5:return[2,void 0]}})})},n.addEventToCurrentSequence=function(e,t){return o(n,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([ct,lt],"readwrite")).done.catch(function(e){n||at(l.loggerProvider,"".concat(_e,": ").concat(e),e)}),[4,r.objectStore(ct).get(e)];case 2:return(i=s.sent())?[3,4]:[4,r.objectStore(ct).put({sessionId:e,events:[t]})];case 3:return s.sent(),[2,void 0];case 4:return this.shouldSplitEventsList(i.events,t)?[3,6]:[4,r.objectStore(ct).put({sessionId:e,events:i.events.concat(t)})];case 5:return s.sent(),[2,void 0];case 6:return o=i.events,[4,r.objectStore(ct).put({sessionId:e,events:[t]})];case 7:return s.sent(),[4,r.objectStore(lt).put({sessionId:e,events:o})];case 8:return a=s.sent(),[2,{events:o,sessionId:e,sequenceId:a}];case 9:return c=s.sent(),n=!0,at(this.loggerProvider,"".concat(_e,": ").concat(c),c),[3,10];case 10:return[2,void 0]}})})},n.storeSendingEvents=function(e,t){return o(n,void 0,void 0,function(){var n;return s(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.db.put(lt,{sessionId:e,events:t})];case 1:return[2,r.sent()];case 2:return n=r.sent(),at(this.loggerProvider,"".concat(_e,": ").concat(n),n),[3,3];case 3:return[2,void 0]}})})},n.cleanUpSessionEventsStore=function(e,t){return o(n,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(lt,t)];case 2:return n.sent(),[3,4];case 3:return e=n.sent(),at(this.loggerProvider,"".concat(_e,": ").concat(e),e),[3,4];case 4:return[2]}})})},n.db=t.db,n}return t(n,e),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,dt(o)];case 1:return a=s.sent(),[2,new n(i(i({},t),{db:a}))];case 2:return c=s.sent(),at(t.loggerProvider,"".concat(_e,": ").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}(st),ht=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}(st),gt=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,w,I,C,k;return s(this,function(E){switch(E.label){case 0:return h=new Me(i(i({},t),{loggerProvider:t.loggerProvider,payloadBatcher:u,workerScript:v})),g=function(){return new ht({loggerProvider:t.loggerProvider,maxInterval:r,minInterval:n})},f=function(){return o(void 0,void 0,void 0,function(){var e;return s(this,function(i){switch(i.label){case 0:return[4,vt.new(a,{loggerProvider:t.loggerProvider,minInterval:n,maxInterval:r,apiKey:t.apiKey})];case 1:return(e=i.sent())?[2,e]:(t.loggerProvider.log("Failed to initialize idb store, falling back to memory store."),[2,g()])}})})},"idb"!==d?[3,2]:[4,f()];case 1:return m=E.sent(),[3,3];case 2:m=g(),E.label=3;case 3:return p=m,y=[],b=0,S=function(e){if(!(e<=b)){var t=Math.min(e-b,y.length);t>0&&(y.splice(0,t),b=e)}},w=function(e){var n=e.events,r=e.sessionId,i=e.deviceId,c=e.sequenceId;t.debugMode&&be().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,p.cleanUpSessionEventsStore(r,c)];case 1:return e.sent(),[2]}})})}})},I=function(e){var n=e.sessionId,r=e.deviceId,i=b+y.length;p.storeCurrentSequence(n).then(function(e){e&&(S(i),w({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)})},C=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[4,p.getSequencesToSend()];case 1:return(e=n.sent())&&e.forEach(function(e){w({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:t})}),[2]}})})},k=function(e){var n=e.event,r=e.sessionId,i=e.deviceId,o=b+y.length;y.push(n.data),p.addEventToCurrentSequence(r,n.data).then(function(e){e&&(S(o),w({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:I,addEvent:k,sendStoredEvents:C,flush:e,getBeaconEvents:function(){return l([],c(y),!1)},trackDestination:h}]}})})},ft=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 pt(e,t){if(ot=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};rt=i(i({},n),t),it=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(rt.root,n);var r=mt(e,"all",function(){return mt(e,"two",function(){return mt(e,"one",function(){return mt(e,"none")})})});if(r){var o=Rt(Tt(r,e));return o.length>0&&(r=o[0]),bt(r)}throw new Error("Selector was not found.")}function mt(e,t,n){for(var r=null,i=[],o=e,s=0,u=function(){var e,u,d=(new Date).getTime()-ot.getTime();if(void 0!==rt.timeoutMs&&d>rt.timeoutMs)throw new Error("Timeout: Can't find a unique selector after ".concat(d,"ms"));var v=kt(function(e){var t=e.getAttribute("id");if(t&&rt.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(o))||kt.apply(void 0,l([],c(function(e){var t=Array.from(e.attributes).filter(function(e){return rt.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))||kt.apply(void 0,l([],c(function(e){var t=Array.from(e.classList).filter(rt.className);return t.map(function(e){return{name:"."+CSS.escape(e),penalty:1}})}(o)),!1))||kt(function(e){var t=e.tagName.toLowerCase();if(rt.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(Ct).map(function(e){return It(e,h)})));else if("two"==t)v=v.slice(0,1),h&&(v=v.concat(v.filter(Ct).map(function(e){return It(e,h)})));else if("one"==t){var g=c(v=v.slice(0,1),1)[0];h&&Ct(g)&&(v=[It(g,h)])}else"none"==t&&(v=[{name:"*",penalty:3}],h&&(v=[It(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>=rt.seedMinLength&&(r=yt(i,n)))return"break";o=o.parentElement,s++};o;){if("break"===u())break}return r||(r=yt(i,n)),!r&&n?n():r}function yt(e,t){var n,r,i=Rt(Pt(e));if(i.length>rt.threshold)return t?t():null;try{for(var o=a(i),s=o.next();!s.done;s=o.next()){var c=s.value;if(wt(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 bt(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 St(e){return e.map(function(e){return e.penalty}).reduce(function(e,t){return e+t},0)}function wt(e){var t=bt(e);switch(it.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 It(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function Ct(e){return"html"!==e.name&&!e.name.startsWith("#")}function kt(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(Et);return n.length>0?n:null}function Et(e){return null!=e}function Pt(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(Pt(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 Rt(e){return l([],c(e),!1).sort(function(e,t){return St(e)-St(t)})}function Tt(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>rt.optimizedMinLength))return[3,5];r=1,s.label=1;case 1:return r<e.length-1?n.counter>rt.maxNumberOfTries?[2]:(n.counter+=1,(i=l([],c(e),!1)).splice(r,1),o=bt(i),n.visited.has(o)?[2]:wt(i)&&function(e,t){return it.querySelector(bt(e))===t}(i,t)?[4,i]:[3,4]):[3,5];case 2:return s.sent(),n.visited.set(o,!0),[5,a(Tt(i,t,n))];case 3:s.sent(),s.label=4;case 4:return r++,[3,1];case 5:return[2]}})}var _t=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}},Ot=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)}},xt=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===ke.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=pt(p,a)}catch(e){n.logger.debug("error resolving selector from finder")}var m=ye(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 Mt(){var e=g();return(null==e?void 0:e.innerHeight)||document.documentElement&&document.documentElement.clientHeight||0}function Dt(){var e=g();return(null==e?void 0:e.innerWidth)||document.documentElement&&document.documentElement.clientWidth||0}var Lt=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}(),Nt=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:Mt(),viewportWidth:Dt(),pageUrl:ye(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=Dt(),this._maxScrollHeight=Mt(),this.config=t,this.transport=e}return e.default=function(t,n){return new e(new Lt(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=Dt();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=Mt();this._maxScrollY=e.y;var o=e.y+i;o>this._maxScrollHeight&&(this._maxScrollHeight=o),this.timestamp=t}},e}(),Ut=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))},qt=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,$e(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(),at(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(),at(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(),at(n,"Failed to clear old targeting matches for sessions: ".concat(d),d),[3,9];case 9:return[2]}})})}},At=new qt,Ft=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,At.clearStoreOfOldSessions({loggerProvider:r,apiKey:a,currentSessionId:t})];case 1:return s.sent(),[4,At.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),At.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]}})})},jt=2654435761,Bt=2246822519,Wt=3266489917,Kt=374761393;function Ht(e,t){return(e<<t|e>>>32-t)>>>0}function $t(e,t){return e=Ht(e=e+Math.imul(t,Bt)>>>0,13),e=Math.imul(e,jt)>>>0}function zt(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function Jt(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+jt+Bt>>>0,a=t+Bt>>>0,c=t>>>0,l=t-jt>>>0;o<=i-16;)s=$t(s,zt(r,o)),a=$t(a,zt(r,o+=4)),c=$t(c,zt(r,o+=4)),l=$t(l,zt(r,o+=4)),o+=4;n=Ht(s,1)+Ht(a,7)+Ht(c,12)+Ht(l,18)>>>0}else n=t+Kt>>>0;for(n=n+i>>>0;o<=i-4;)n=n+Math.imul(zt(r,o),Wt)>>>0,n=Math.imul(Ht(n,17),668265263)>>>0,o+=4;for(;o<i;)n=n+Math.imul(r[o],Kt)>>>0,n=Math.imul(Ht(n,11),jt)>>>0,o++;return n^=n>>>15,n=Math.imul(n,Bt)>>>0,n^=n>>>13,n=Math.imul(n,Wt)>>>0,(n^=n>>>16)>>>0}var Gt="__amplitude_url_tracking_patched__",Vt=new WeakMap;function Zt(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=Vt.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[Gt]=!0,t},f=e.history;if(null==f?void 0:f.pushState){var p=Reflect.get(f,"pushState");p[Gt]||(f.pushState=g(p))}if(null==f?void 0:f.replaceState){var m=Reflect.get(f,"replaceState");m[Gt]||(f.replaceState=g(m))}u={callbacks:v,notify:h,onPopStateOrHashChange:function(){return h()},listenersAttached:!1},Vt.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 Qt(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?ye(i,l):i,title:o,viewportHeight:e,viewportWidth:t,type:"url-change-event"}}();t(r)}},p=Zt(n,function(){return f()},u?{enablePolling:!0,pollingInterval:d}:{});return f(),function(){return p()}},options:e}}Qt();var Yt,Xt,en,tn=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.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(){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,Ft({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:Se(o),version:Oe},r?[4,be()]:[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.setupUrlChangeListenerForTargeting=function(){var e,t=this;null===(e=this.urlChangeCleanup)||void 0===e||e.call(this);var n=g();if(null==n?void 0:n.location){var r=Zt(n,function(e){var n=++t.latestUrlChangeTargetingEvaluationId;t.evaluateTargetingAndCapture({userProperties:{},event:void 0,page:{url:e}},!1,!1,!0),t.loggerProvider.debug("Queued URL-change targeting re-evaluation #".concat(n," for ").concat(e,"."))});this.urlChangeCleanup=function(){r(),t.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;return o(this,void 0,void 0,function(){var o,p,m,y,S,w,I,C,k,E,P,R,T,_,O,x,M,D,L,N,U,q=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.identifiers=new Ut({sessionId:t.sessionId,deviceId:t.deviceId}),o=this,[4,Pe(e,t)];case 1:return o.joinedConfigGenerator=s.sent(),[4,this.joinedConfigGenerator.generateJoinedConfig()];case 2:return p=s.sent(),m=p.joinedConfig,y=p.localConfig,S=p.remoteConfig,this.config=m,this.setMetadata(t.sessionId,m,y,S,null===(r=t.version)||void 0===r?void 0:r.version,Oe,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)&&(w=Nt.default({sessionId:t.sessionId,type:"interaction"},this.config),this.pageLeaveFns=[w.send(this.getDeviceId.bind(this)).bind(w)],this.scrollHook=w.hook.bind(w),this.clickHandler=new xt(this.loggerProvider,w)),I=[],"idb"!==(C=this.config.storeType)||(null===(d=g())||void 0===d?void 0:d.indexedDB)||(C="memory",this.loggerProvider.warn("Could not use preferred indexedDB storage, reverting to in memory option.")),this.loggerProvider.log("Using ".concat(C," for event storage.")),P=g(),this.config.useWebWorker&&P&&P.Worker?[4,import("./index-min2.js")]:[3,4];case 3:R=s.sent(),T=R.compressionScript,_=R.trackDestinationScript,k=T,E=_,s.label=4;case 4:return s.trys.push([4,6,,7]),[4,gt({config:this.config,type:"replay",storeType:C,trackDestinationWorkerScript:E})];case 5:return O=s.sent(),I.push({name:"replay",manager:O}),[3,7];case 6:return x=s.sent(),N=x,this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(N.toString())),[3,7];case 7:if(!(null===(v=this.config.interactionConfig)||void 0===v?void 0:v.enabled))return[3,11];M=this.config.interactionConfig.batch?Ot:_t,s.label=8;case 8:return s.trys.push([8,10,,11]),[4,gt({config:this.config,type:"interaction",minInterval:null!==(h=this.config.interactionConfig.trackEveryNms)&&void 0!==h?h:3e4,maxInterval:6e4,payloadBatcher:M,storeType:C,trackDestinationWorkerScript:E})];case 9:return D=s.sent(),I.push({name:"interaction",manager:D}),[3,11];case 10:return L=s.sent(),N=L,this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(N.toString())),[3,11];case 11:return this.eventsManager=new(ft.bind.apply(ft,l([void 0],c(I),!1))),this.eventCompressor&&this.eventCompressor.terminate(),this.eventCompressor=new Re(this.eventsManager,this.config,this.getDeviceId(),k,function(){return q.sendEvents()}),this.pageLeaveFns=l(l([],c(this.pageLeaveFns),!1),[function(){var e;if(q.config&&(null===(e=q.identifiers)||void 0===e?void 0:e.sessionId)&&O){var t=O.getBeaconEvents();if(t.length){var n=q.getDeviceId();n&&O.trackDestination.sendBeacon({events:t,sessionId:q.identifiers.sessionId,deviceId:n,apiKey:q.config.apiKey,serverZone:q.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})}}(U=Z()),U.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&&this.setupUrlChangeListenerForTargeting(),[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 Ut({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:U(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),N.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,Jt(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,r;if("conservative"===(null===(t=null===(e=this.config)||void 0===e?void 0:e.privacyConfig)||void 0===t?void 0:t.defaultMaskLevel))return"*";var i=null===(r=null===(n=this.config)||void 0===n?void 0:n.privacyConfig)||void 0===r?void 0:r.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=Qt({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){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,w,I,C,k,E,P=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)})||P.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}:{},w=(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]),I=this,C=h,E={emit:function(e){if(P.shouldOptOut())return P.loggerProvider.log("Opting session ".concat(v," out of recording due to optOut config.")),P.stopRecordingEvents(),void P.sendEvents();e.type===Ce.Meta&&(e.data.href=ye(e.data.href,w)),P.eventCompressor&&P.eventCompressor.enqueueEvent(e,v)},inlineStylesheet:o.shouldInlineStylesheet,hooks:S,maskAllInputs:!0,maskTextClass:oe,blockClass:"amp-block",blockSelector:this.getBlockSelectors(),applyBackgroundColorToBlockedElements:o.applyBackgroundColorToBlockedElements,maskInputFn:ge("input",m),maskTextFn:ge("text",m),maskAttributeFn:fe(m),maskTextSelector:this.getMaskTextSelectors(),recordCanvas:!1,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 P.loggerProvider.warn("Error while capturing replay: ",t.toString()),!0}},[4,this.getRecordingPlugins(b)];case 4:return I.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())?U(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}(),nn=function(e){return function(){var t=e.config||we();return{logger:t.loggerProvider,logLevel:t.logLevel}}},rn=function(){var e=new tn;return{init:k(e.init.bind(e),"init",nn(e)),evaluateTargetingAndCapture:k(e.evaluateTargetingAndCapture.bind(e),"evaluateTargetingAndRecord",nn(e)),setSessionId:k(e.setSessionId.bind(e),"setSessionId",nn(e)),getSessionId:k(e.getSessionId.bind(e),"getSessionId",nn(e)),getSessionReplayProperties:k(e.getSessionReplayProperties.bind(e),"getSessionReplayProperties",nn(e)),flush:k(e.flush.bind(e),"flush",nn(e)),shutdown:k(e.shutdown.bind(e),"shutdown",nn(e))}}(),on=rn.init,sn=rn.setSessionId,an=rn.getSessionId,cn=rn.getSessionReplayProperties,ln=rn.flush,un=rn.shutdown,dn=rn.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"}(Yt||(Yt={})),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"}(Xt||(Xt={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(en||(en={}));const vn=[Yt.SET,Yt.SET_ONCE,Yt.ADD,Yt.APPEND,Yt.PREPEND,Yt.POSTINSERT],hn="1.27.9";class gn{constructor(e){this.name=gn.pluginName,this.type="enrichment",this.config=null,this.sessionReplay={flush:ln,getSessionId:an,getSessionReplayProperties:cn,init:on,setSessionId:sn,shutdown:un,evaluateTargetingAndCapture:dn},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 ${hn}.`),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"),N.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:hn},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},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(vn.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()}}gn.pluginName="@amplitude/plugin-session-replay-browser";const fn=e=>new gn(e);export{gn as S,o as _,s as a,i as b,g,$e as o,fn as s};
|
|
2
2
|
//# sourceMappingURL=index-min.js.map
|
|
Binary file
|