UNPKG

@deriv-com/analytics

Version:

The analytics package contains all the utility functions used for tracking user events and sending them to the respective platform such as Rudderstack.

2 lines 196 kB
/*! For license information please see analytics.bundle.js.LICENSE.txt */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Analytics=t():e.Analytics=t()}(this,(()=>(()=>{var e={328:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GrowthBook=void 0,t.prefetchPayload=async function(e){const t=new c(e);await(0,a.refreshFeatures)({instance:t,skipCache:e.skipCache,allowStale:!1,backgroundSync:e.streaming}),t.destroy()};var n,i=(n=r(591))&&n.__esModule?n:{default:n},s=r(106),o=r(427),a=r(707);const l="undefined"!=typeof window&&"undefined"!=typeof document,u=(0,s.loadSDKVersion)();class c{constructor(e){if(e=e||{},this.version=u,this._ctx=this.context=e,this._renderer=e.renderer||null,this._trackedExperiments=new Set,this._completedChangeIds=new Set,this._trackedFeatures={},this.debug=!!e.debug,this._subscriptions=new Set,this._rtQueue=[],this._rtTimer=0,this.ready=!1,this._assigned=new Map,this._forcedFeatureValues=new Map,this._attributeOverrides={},this._activeAutoExperiments=new Map,this._triggeredExpKeys=new Set,this._initialized=!1,this._redirectedUrl="",this._deferredTrackingCalls=new Map,this._autoExperimentsAllowed=!e.disableExperimentsOnLoad,e.remoteEval){if(e.decryptionKey)throw new Error("Encryption is not available for remoteEval");if(!e.clientKey)throw new Error("Missing clientKey");let t=!1;try{t=!!new URL(e.apiHost||"").hostname.match(/growthbook\.io$/i)}catch(e){}if(t)throw new Error("Cannot use remoteEval on GrowthBook Cloud")}else if(e.cacheKeyAttributes)throw new Error("cacheKeyAttributes are only used for remoteEval");if(e.features&&(this.ready=!0),l&&e.enableDevMode&&(window._growthbook=this,document.dispatchEvent(new Event("gbloaded"))),e.experiments?(this.ready=!0,this._updateAllAutoExperiments()):e.antiFlicker&&this._setAntiFlicker(),this._ctx.stickyBucketService&&this._ctx.stickyBucketAssignmentDocs)for(const e in this._ctx.stickyBucketAssignmentDocs){const t=this._ctx.stickyBucketAssignmentDocs[e];t&&this._ctx.stickyBucketService.saveAssignments(t).catch((()=>{}))}this.ready&&this.refreshStickyBuckets(this.getPayload())}async setPayload(e){this._payload=e;const t=await this.decryptPayload(e);this._decryptedPayload=t,await this.refreshStickyBuckets(t),t.features&&(this._ctx.features=t.features),t.savedGroups&&(this._ctx.savedGroups=t.savedGroups),t.experiments&&(this._ctx.experiments=t.experiments,this._updateAllAutoExperiments()),this.ready=!0,this._render()}initSync(e){this._initialized=!0;const t=e.payload;if(t.encryptedExperiments||t.encryptedFeatures)throw new Error("initSync does not support encrypted payloads");if(this._ctx.stickyBucketService&&!this._ctx.stickyBucketAssignmentDocs)throw new Error("initSync requires you to pass stickyBucketAssignmentDocs into the GrowthBook constructor");if(this._payload=t,this._decryptedPayload=t,t.features&&(this._ctx.features=t.features),t.experiments&&(this._ctx.experiments=t.experiments,this._updateAllAutoExperiments()),this.ready=!0,e.streaming){if(!this._ctx.clientKey)throw new Error("Must specify clientKey to enable streaming");(0,a.startAutoRefresh)(this,!0),(0,a.subscribe)(this)}return this}async init(e){if(this._initialized=!0,(e=e||{}).payload){if(await this.setPayload(e.payload),e.streaming){if(!this._ctx.clientKey)throw new Error("Must specify clientKey to enable streaming");(0,a.startAutoRefresh)(this,!0),(0,a.subscribe)(this)}return{success:!0,source:"init"}}{const{data:t,...r}=await this._refresh({...e,allowStale:!0});return e.streaming&&(0,a.subscribe)(this),await this.setPayload(t||{}),r}}async loadFeatures(e){this._initialized=!0,(e=e||{}).autoRefresh&&(this._ctx.subscribeToChanges=!0);const{data:t}=await this._refresh({...e,allowStale:!0});await this.setPayload(t||{}),this._canSubscribe()&&(0,a.subscribe)(this)}async refreshFeatures(e){const t=await this._refresh({...e||{},allowStale:!1});t.data&&await this.setPayload(t.data)}getApiInfo(){return[this.getApiHosts().apiHost,this.getClientKey()]}getApiHosts(){const e=this._ctx.apiHost||"https://cdn.growthbook.io";return{apiHost:e.replace(/\/*$/,""),streamingHost:(this._ctx.streamingHost||e).replace(/\/*$/,""),apiRequestHeaders:this._ctx.apiHostRequestHeaders,streamingHostRequestHeaders:this._ctx.streamingHostRequestHeaders}}getClientKey(){return this._ctx.clientKey||""}getPayload(){return this._payload||{features:this.getFeatures(),experiments:this.getExperiments()}}getDecryptedPayload(){return this._decryptedPayload||this.getPayload()}isRemoteEval(){return this._ctx.remoteEval||!1}getCacheKeyAttributes(){return this._ctx.cacheKeyAttributes}async _refresh(e){var t;let{timeout:r,skipCache:n,allowStale:i,streaming:s}=e;if(!this._ctx.clientKey)throw new Error("Missing clientKey");return(0,a.refreshFeatures)({instance:this,timeout:r,skipCache:n||this._ctx.disableCache,allowStale:i,backgroundSync:null===(t=null!=s?s:this._ctx.backgroundSync)||void 0===t||t})}_render(){if(this._renderer)try{this._renderer()}catch(e){console.error("Failed to render",e)}}setFeatures(e){this._ctx.features=e,this.ready=!0,this._render()}async setEncryptedFeatures(e,t,r){const n=await(0,s.decrypt)(e,t||this._ctx.decryptionKey,r);this.setFeatures(JSON.parse(n))}setExperiments(e){this._ctx.experiments=e,this.ready=!0,this._updateAllAutoExperiments()}async setEncryptedExperiments(e,t,r){const n=await(0,s.decrypt)(e,t||this._ctx.decryptionKey,r);this.setExperiments(JSON.parse(n))}async decryptPayload(e,t,r){if((e={...e}).encryptedFeatures){try{e.features=JSON.parse(await(0,s.decrypt)(e.encryptedFeatures,t||this._ctx.decryptionKey,r))}catch(e){console.error(e)}delete e.encryptedFeatures}if(e.encryptedExperiments){try{e.experiments=JSON.parse(await(0,s.decrypt)(e.encryptedExperiments,t||this._ctx.decryptionKey,r))}catch(e){console.error(e)}delete e.encryptedExperiments}if(e.encryptedSavedGroups){try{e.savedGroups=JSON.parse(await(0,s.decrypt)(e.encryptedSavedGroups,t||this._ctx.decryptionKey,r))}catch(e){console.error(e)}delete e.encryptedSavedGroups}return e}async setAttributes(e){this._ctx.attributes=e,this._ctx.stickyBucketService&&await this.refreshStickyBuckets(),this._ctx.remoteEval?await this._refreshForRemoteEval():(this._render(),this._updateAllAutoExperiments())}async updateAttributes(e){return this.setAttributes({...this._ctx.attributes,...e})}async setAttributeOverrides(e){this._attributeOverrides=e,this._ctx.stickyBucketService&&await this.refreshStickyBuckets(),this._ctx.remoteEval?await this._refreshForRemoteEval():(this._render(),this._updateAllAutoExperiments())}async setForcedVariations(e){this._ctx.forcedVariations=e||{},this._ctx.remoteEval?await this._refreshForRemoteEval():(this._render(),this._updateAllAutoExperiments())}setForcedFeatures(e){this._forcedFeatureValues=e,this._render()}async setURL(e){if(this._ctx.url=e,this._redirectedUrl="",this._ctx.remoteEval)return await this._refreshForRemoteEval(),void this._updateAllAutoExperiments(!0);this._updateAllAutoExperiments(!0)}getAttributes(){return{...this._ctx.attributes,...this._attributeOverrides}}getForcedVariations(){return this._ctx.forcedVariations||{}}getForcedFeatures(){return this._forcedFeatureValues||new Map}getStickyBucketAssignmentDocs(){return this._ctx.stickyBucketAssignmentDocs||{}}getUrl(){return this._ctx.url||""}getFeatures(){return this._ctx.features||{}}getExperiments(){return this._ctx.experiments||[]}getCompletedChangeIds(){return Array.from(this._completedChangeIds)}subscribe(e){return this._subscriptions.add(e),()=>{this._subscriptions.delete(e)}}_canSubscribe(){var e;return(null===(e=this._ctx.backgroundSync)||void 0===e||e)&&this._ctx.subscribeToChanges}async _refreshForRemoteEval(){if(!this._ctx.remoteEval)return;if(!this._initialized)return;const e=await this._refresh({allowStale:!1});e.data&&await this.setPayload(e.data)}getAllResults(){return new Map(this._assigned)}destroy(){this._subscriptions.clear(),this._assigned.clear(),this._trackedExperiments.clear(),this._completedChangeIds.clear(),this._deferredTrackingCalls.clear(),this._trackedFeatures={},this._rtQueue=[],this._payload=void 0,this._rtTimer&&clearTimeout(this._rtTimer),(0,a.unsubscribe)(this),l&&window._growthbook===this&&delete window._growthbook,this._activeAutoExperiments.forEach((e=>{e.undo()})),this._activeAutoExperiments.clear(),this._triggeredExpKeys.clear()}setRenderer(e){this._renderer=e}forceVariation(e,t){this._ctx.forcedVariations=this._ctx.forcedVariations||{},this._ctx.forcedVariations[e]=t,this._ctx.remoteEval?this._refreshForRemoteEval():(this._updateAllAutoExperiments(),this._render())}run(e){const t=this._run(e,null);return this._fireSubscriptions(e,t),t}triggerExperiment(e){return this._triggeredExpKeys.add(e),this._ctx.experiments?this._ctx.experiments.filter((t=>t.key===e)).map((e=>this._runAutoExperiment(e))).filter((e=>null!==e)):null}triggerAutoExperiments(){this._autoExperimentsAllowed=!0,this._updateAllAutoExperiments(!0)}_runAutoExperiment(e,t){const r=this._activeAutoExperiments.get(e);if(e.manual&&!this._triggeredExpKeys.has(e.key)&&!r)return null;const n=this._isAutoExperimentBlockedByContext(e)?this._getResult(e,-1,!1,""):this.run(e),i=JSON.stringify(n.value);if(!t&&n.inExperiment&&r&&r.valueHash===i)return n;if(r&&this._undoActiveAutoExperiment(e),n.inExperiment){const t=(0,s.getAutoExperimentChangeType)(e);if("redirect"===t&&n.value.urlRedirect&&e.urlPatterns){const t=e.persistQueryString?(0,s.mergeQueryStrings)(this._getContextUrl(),n.value.urlRedirect):n.value.urlRedirect;if((0,s.isURLTargeted)(t,e.urlPatterns))return this.log("Skipping redirect because original URL matches redirect URL",{id:e.key}),n;this._redirectedUrl=t;const r=this._getNavigateFunction();var o;if(r)if(l)this._setAntiFlicker(),window.setTimeout((()=>{try{r(t)}catch(e){console.error(e)}}),null!==(o=this._ctx.navigateDelay)&&void 0!==o?o:100);else try{r(t)}catch(e){console.error(e)}}else if("visual"===t){const t=this._ctx.applyDomChangesCallback?this._ctx.applyDomChangesCallback(n.value):this._applyDOMChanges(n.value);t&&this._activeAutoExperiments.set(e,{undo:t,valueHash:i})}}return n}_undoActiveAutoExperiment(e){const t=this._activeAutoExperiments.get(e);t&&(t.undo(),this._activeAutoExperiments.delete(e))}_updateAllAutoExperiments(e){if(!this._autoExperimentsAllowed)return;const t=this._ctx.experiments||[],r=new Set(t);this._activeAutoExperiments.forEach(((e,t)=>{r.has(t)||(e.undo(),this._activeAutoExperiments.delete(t))}));for(const r of t){const t=this._runAutoExperiment(r,e);if(null!=t&&t.inExperiment&&"redirect"===(0,s.getAutoExperimentChangeType)(r))break}}_fireSubscriptions(e,t){const r=e.key,n=this._assigned.get(r);n&&n.result.inExperiment===t.inExperiment&&n.result.variationId===t.variationId||(this._assigned.set(r,{experiment:e,result:t}),this._subscriptions.forEach((r=>{try{r(e,t)}catch(e){console.error(e)}})))}_trackFeatureUsage(e,t){if("override"===t.source)return;const r=JSON.stringify(t.value);if(this._trackedFeatures[e]!==r){if(this._trackedFeatures[e]=r,this._ctx.onFeatureUsage)try{this._ctx.onFeatureUsage(e,t)}catch(e){}l&&window.fetch&&(this._rtQueue.push({key:e,on:t.on}),this._rtTimer||(this._rtTimer=window.setTimeout((()=>{this._rtTimer=0;const e=[...this._rtQueue];this._rtQueue=[],this._ctx.realtimeKey&&window.fetch("https://rt.growthbook.io/?key=".concat(this._ctx.realtimeKey,"&events=").concat(encodeURIComponent(JSON.stringify(e))),{cache:"no-cache",mode:"no-cors"}).catch((()=>{}))}),this._ctx.realtimeInterval||2e3)))}}_getFeatureResult(e,t,r,n,i,s){const o={value:t,on:!!t,off:!t,source:r,ruleId:n||""};return i&&(o.experiment=i),s&&(o.experimentResult=s),this._trackFeatureUsage(e,o),o}isOn(e){return this.evalFeature(e).on}isOff(e){return this.evalFeature(e).off}getFeatureValue(e,t){const r=this.evalFeature(e).value;return null===r?t:r}feature(e){return this.evalFeature(e)}evalFeature(e){return this._evalFeature(e)}_evalFeature(e,t){if((t=t||{evaluatedFeatures:new Set}).evaluatedFeatures.has(e))return this._getFeatureResult(e,null,"cyclicPrerequisite");if(t.evaluatedFeatures.add(e),t.id=e,this._forcedFeatureValues.has(e))return this._getFeatureResult(e,this._forcedFeatureValues.get(e),"override");if(!this._ctx.features||!this._ctx.features[e])return this._getFeatureResult(e,null,"unknownFeature");const r=this._ctx.features[e];if(r.rules)e:for(const n of r.rules){if(n.parentConditions)for(const r of n.parentConditions){const n=this._evalFeature(r.id,t);if("cyclicPrerequisite"===n.source)return this._getFeatureResult(e,null,"cyclicPrerequisite");const i={value:n.value};if(!(0,o.evalCondition)(i,r.condition||{})){if(r.gate)return this._getFeatureResult(e,null,"prerequisite");continue e}}if(n.filters&&this._isFilteredOut(n.filters))continue;if("force"in n){if(n.condition&&!this._conditionPasses(n.condition))continue;if(!this._isIncludedInRollout(n.seed||e,n.hashAttribute,this._ctx.stickyBucketService&&!n.disableStickyBucketing?n.fallbackAttribute:void 0,n.range,n.coverage,n.hashVersion))continue;return n.tracks&&n.tracks.forEach((e=>{this._track(e.experiment,e.result)})),this._getFeatureResult(e,n.force,"force",n.id)}if(!n.variations)continue;const r={variations:n.variations,key:n.key||e};"coverage"in n&&(r.coverage=n.coverage),n.weights&&(r.weights=n.weights),n.hashAttribute&&(r.hashAttribute=n.hashAttribute),n.fallbackAttribute&&(r.fallbackAttribute=n.fallbackAttribute),n.disableStickyBucketing&&(r.disableStickyBucketing=n.disableStickyBucketing),void 0!==n.bucketVersion&&(r.bucketVersion=n.bucketVersion),void 0!==n.minBucketVersion&&(r.minBucketVersion=n.minBucketVersion),n.namespace&&(r.namespace=n.namespace),n.meta&&(r.meta=n.meta),n.ranges&&(r.ranges=n.ranges),n.name&&(r.name=n.name),n.phase&&(r.phase=n.phase),n.seed&&(r.seed=n.seed),n.hashVersion&&(r.hashVersion=n.hashVersion),n.filters&&(r.filters=n.filters),n.condition&&(r.condition=n.condition);const i=this._run(r,e);if(this._fireSubscriptions(r,i),i.inExperiment&&!i.passthrough)return this._getFeatureResult(e,i.value,"experiment",n.id,r,i)}return this._getFeatureResult(e,void 0===r.defaultValue?null:r.defaultValue,"defaultValue")}_isIncludedInRollout(e,t,r,n,i,o){if(!n&&void 0===i)return!0;if(!n&&0===i)return!1;const{hashValue:a}=this._getHashAttribute(t,r);if(!a)return!1;const l=(0,s.hash)(e,a,o||1);return null!==l&&(n?(0,s.inRange)(l,n):void 0===i||l<=i)}_conditionPasses(e){return(0,o.evalCondition)(this.getAttributes(),e,this._ctx.savedGroups||{})}_isFilteredOut(e){return e.some((e=>{const{hashValue:t}=this._getHashAttribute(e.attribute);if(!t)return!0;const r=(0,s.hash)(e.seed,t,e.hashVersion||2);return null===r||!e.ranges.some((e=>(0,s.inRange)(r,e)))}))}_run(e,t){const r=e.key,n=e.variations.length;if(n<2)return this._getResult(e,-1,!1,t);if(!1===this._ctx.enabled)return this._getResult(e,-1,!1,t);if((e=this._mergeOverrides(e)).urlPatterns&&!(0,s.isURLTargeted)(this._getContextUrl(),e.urlPatterns))return this._getResult(e,-1,!1,t);const i=(0,s.getQueryStringOverride)(r,this._getContextUrl(),n);if(null!==i)return this._getResult(e,i,!1,t);if(this._ctx.forcedVariations&&r in this._ctx.forcedVariations){const n=this._ctx.forcedVariations[r];return this._getResult(e,n,!1,t)}if("draft"===e.status||!1===e.active)return this._getResult(e,-1,!1,t);const{hashAttribute:a,hashValue:l}=this._getHashAttribute(e.hashAttribute,this._ctx.stickyBucketService&&!e.disableStickyBucketing?e.fallbackAttribute:void 0);if(!l)return this._getResult(e,-1,!1,t);let u=-1,c=!1,d=!1;if(this._ctx.stickyBucketService&&!e.disableStickyBucketing){const{variation:t,versionIsBlocked:r}=this._getStickyBucketVariation({expKey:e.key,expBucketVersion:e.bucketVersion,expHashAttribute:e.hashAttribute,expFallbackAttribute:e.fallbackAttribute,expMinBucketVersion:e.minBucketVersion,expMeta:e.meta});c=t>=0,u=t,d=!!r}if(!c){if(e.filters){if(this._isFilteredOut(e.filters))return this._getResult(e,-1,!1,t)}else if(e.namespace&&!(0,s.inNamespace)(l,e.namespace))return this._getResult(e,-1,!1,t);if(e.include&&!(0,s.isIncluded)(e.include))return this._getResult(e,-1,!1,t);if(e.condition&&!this._conditionPasses(e.condition))return this._getResult(e,-1,!1,t);if(e.parentConditions)for(const r of e.parentConditions){const n=this._evalFeature(r.id);if("cyclicPrerequisite"===n.source)return this._getResult(e,-1,!1,t);const i={value:n.value};if(!(0,o.evalCondition)(i,r.condition||{}))return this._getResult(e,-1,!1,t)}if(e.groups&&!this._hasGroupOverlap(e.groups))return this._getResult(e,-1,!1,t)}if(e.url&&!this._urlIsValid(e.url))return this._getResult(e,-1,!1,t);const h=(0,s.hash)(e.seed||r,l,e.hashVersion||1);if(null===h)return this._getResult(e,-1,!1,t);if(!c){const t=e.ranges||(0,s.getBucketRanges)(n,void 0===e.coverage?1:e.coverage,e.weights);u=(0,s.chooseVariation)(h,t)}if(d)return this._getResult(e,-1,!1,t,void 0,!0);if(u<0)return this._getResult(e,-1,!1,t);if("force"in e)return this._getResult(e,void 0===e.force?-1:e.force,!1,t);if(this._ctx.qaMode)return this._getResult(e,-1,!1,t);if("stopped"===e.status)return this._getResult(e,-1,!1,t);const g=this._getResult(e,u,!0,t,h,c);if(this._ctx.stickyBucketService&&!e.disableStickyBucketing){const{changed:t,key:r,doc:n}=this._generateStickyBucketAssignmentDoc(a,(0,s.toString)(l),{[this._getStickyBucketExperimentKey(e.key,e.bucketVersion)]:g.key});t&&(this._ctx.stickyBucketAssignmentDocs=this._ctx.stickyBucketAssignmentDocs||{},this._ctx.stickyBucketAssignmentDocs[r]=n,this._ctx.stickyBucketService.saveAssignments(n))}return this._track(e,g),"changeId"in e&&e.changeId&&this._completedChangeIds.add(e.changeId),g}log(e,t){this.debug&&(this._ctx.log?this._ctx.log(e,t):console.log(e,t))}getDeferredTrackingCalls(){return Array.from(this._deferredTrackingCalls.values())}setDeferredTrackingCalls(e){this._deferredTrackingCalls=new Map(e.filter((e=>e&&e.experiment&&e.result)).map((e=>[this._getTrackKey(e.experiment,e.result),e])))}fireDeferredTrackingCalls(){this._ctx.trackingCallback&&(this._deferredTrackingCalls.forEach((e=>{e&&e.experiment&&e.result?this._track(e.experiment,e.result):console.error("Invalid deferred tracking call",{call:e})})),this._deferredTrackingCalls.clear())}setTrackingCallback(e){this._ctx.trackingCallback=e,this.fireDeferredTrackingCalls()}_getTrackKey(e,t){return t.hashAttribute+t.hashValue+e.key+t.variationId}_track(e,t){const r=this._getTrackKey(e,t);if(this._ctx.trackingCallback){if(!this._trackedExperiments.has(r)){this._trackedExperiments.add(r);try{this._ctx.trackingCallback(e,t)}catch(e){console.error(e)}}}else this._deferredTrackingCalls.has(r)||this._deferredTrackingCalls.set(r,{experiment:e,result:t})}_mergeOverrides(e){const t=e.key,r=this._ctx.overrides;return r&&r[t]&&"string"==typeof(e=Object.assign({},e,r[t])).url&&(e.url=(0,s.getUrlRegExp)(e.url)),e}_getHashAttribute(e,t){let r=e||"id",n="";return this._attributeOverrides[r]?n=this._attributeOverrides[r]:this._ctx.attributes?n=this._ctx.attributes[r]||"":this._ctx.user&&(n=this._ctx.user[r]||""),!n&&t&&(this._attributeOverrides[t]?n=this._attributeOverrides[t]:this._ctx.attributes?n=this._ctx.attributes[t]||"":this._ctx.user&&(n=this._ctx.user[t]||""),n&&(r=t)),{hashAttribute:r,hashValue:n}}_getResult(e,t,r,n,i,s){let o=!0;(t<0||t>=e.variations.length)&&(t=0,o=!1);const{hashAttribute:a,hashValue:l}=this._getHashAttribute(e.hashAttribute,this._ctx.stickyBucketService&&!e.disableStickyBucketing?e.fallbackAttribute:void 0),u=e.meta?e.meta[t]:{},c={key:u.key||""+t,featureId:n,inExperiment:o,hashUsed:r,variationId:t,value:e.variations[t],hashAttribute:a,hashValue:l,stickyBucketUsed:!!s};return u.name&&(c.name=u.name),void 0!==i&&(c.bucket=i),u.passthrough&&(c.passthrough=u.passthrough),c}_getContextUrl(){return this._ctx.url||(l?window.location.href:"")}_urlIsValid(e){const t=this._getContextUrl();if(!t)return!1;const r=t.replace(/^https?:\/\//,"").replace(/^[^/]*\//,"/");return!!e.test(t)||!!e.test(r)}_hasGroupOverlap(e){const t=this._ctx.groups||{};for(let r=0;r<e.length;r++)if(t[e[r]])return!0;return!1}_isAutoExperimentBlockedByContext(e){const t=(0,s.getAutoExperimentChangeType)(e);if("visual"===t){if(this._ctx.disableVisualExperiments)return!0;if(this._ctx.disableJsInjection&&e.variations.some((e=>e.js)))return!0}else{if("redirect"!==t)return!0;if(this._ctx.disableUrlRedirectExperiments)return!0;try{const t=new URL(this._getContextUrl());for(const r of e.variations){if(!r||!r.urlRedirect)continue;const e=new URL(r.urlRedirect);if(this._ctx.disableCrossOriginUrlRedirectExperiments){if(e.protocol!==t.protocol)return!0;if(e.host!==t.host)return!0}}}catch(t){return this.log("Error parsing current or redirect URL",{id:e.key,error:t}),!0}}return!(!e.changeId||!(this._ctx.blockedChangeIds||[]).includes(e.changeId))}getRedirectUrl(){return this._redirectedUrl}_getNavigateFunction(){return this._ctx.navigate?this._ctx.navigate:l?e=>{window.location.replace(e)}:null}_setAntiFlicker(){if(this._ctx.antiFlicker&&l)try{var e;const t=document.createElement("style");t.innerHTML=".gb-anti-flicker { opacity: 0 !important; pointer-events: none; }",document.head.appendChild(t),document.documentElement.classList.add("gb-anti-flicker"),setTimeout((()=>{document.documentElement.classList.remove("gb-anti-flicker")}),null!==(e=this._ctx.antiFlickerTimeout)&&void 0!==e?e:3500)}catch(e){console.error(e)}}_applyDOMChanges(e){if(!l)return;const t=[];if(e.css){const r=document.createElement("style");r.innerHTML=e.css,document.head.appendChild(r),t.push((()=>r.remove()))}if(e.js){const r=document.createElement("script");r.innerHTML=e.js,this._ctx.jsInjectionNonce&&(r.nonce=this._ctx.jsInjectionNonce),document.head.appendChild(r),t.push((()=>r.remove()))}return e.domMutations&&e.domMutations.forEach((e=>{t.push(i.default.declarative(e).revert)})),()=>{t.forEach((e=>e()))}}_deriveStickyBucketIdentifierAttributes(e){const t=new Set,r=e&&e.features?e.features:this.getFeatures(),n=e&&e.experiments?e.experiments:this.getExperiments();return Object.keys(r).forEach((e=>{const n=r[e];if(n.rules)for(const e of n.rules)e.variations&&(t.add(e.hashAttribute||"id"),e.fallbackAttribute&&t.add(e.fallbackAttribute))})),n.map((e=>{t.add(e.hashAttribute||"id"),e.fallbackAttribute&&t.add(e.fallbackAttribute)})),Array.from(t)}async refreshStickyBuckets(e){if(this._ctx.stickyBucketService){const t=this._getStickyBucketAttributes(e);this._ctx.stickyBucketAssignmentDocs=await this._ctx.stickyBucketService.getAllAssignments(t)}}_getStickyBucketAssignments(e,t){if(!this._ctx.stickyBucketAssignmentDocs)return{};const{hashAttribute:r,hashValue:n}=this._getHashAttribute(e),i="".concat(r,"||").concat((0,s.toString)(n)),{hashAttribute:o,hashValue:a}=this._getHashAttribute(t),l=a?"".concat(o,"||").concat((0,s.toString)(a)):null,u={};return l&&this._ctx.stickyBucketAssignmentDocs[l]&&Object.assign(u,this._ctx.stickyBucketAssignmentDocs[l].assignments||{}),this._ctx.stickyBucketAssignmentDocs[i]&&Object.assign(u,this._ctx.stickyBucketAssignmentDocs[i].assignments||{}),u}_getStickyBucketVariation(e){let{expKey:t,expBucketVersion:r,expHashAttribute:n,expFallbackAttribute:i,expMinBucketVersion:s,expMeta:o}=e;r=r||0,s=s||0,n=n||"id",o=o||[];const a=this._getStickyBucketExperimentKey(t,r),l=this._getStickyBucketAssignments(n,i);if(s>0)for(let e=0;e<=s;e++)if(void 0!==l[this._getStickyBucketExperimentKey(t,e)])return{variation:-1,versionIsBlocked:!0};const u=l[a];if(void 0===u)return{variation:-1};const c=o.findIndex((e=>e.key===u));return c<0?{variation:-1}:{variation:c}}_getStickyBucketExperimentKey(e,t){return t=t||0,"".concat(e,"__").concat(t)}_getStickyBucketAttributes(e){const t={};return this._ctx.stickyBucketIdentifierAttributes=this._ctx.stickyBucketIdentifierAttributes?this._ctx.stickyBucketIdentifierAttributes:this._deriveStickyBucketIdentifierAttributes(e),this._ctx.stickyBucketIdentifierAttributes.forEach((e=>{const{hashValue:r}=this._getHashAttribute(e);t[e]=(0,s.toString)(r)})),t}_generateStickyBucketAssignmentDoc(e,t,r){const n="".concat(e,"||").concat(t),i=this._ctx.stickyBucketAssignmentDocs&&this._ctx.stickyBucketAssignmentDocs[n]&&this._ctx.stickyBucketAssignmentDocs[n].assignments||{},s={...i,...r};return{key:n,doc:{attributeName:e,attributeValue:t,assignments:s},changed:JSON.stringify(i)!==JSON.stringify(s)}}}t.GrowthBook=c},707:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.clearCache=async function(){u.clear(),c.clear(),I(),l=!1,await p()},t.configureCache=function(e){Object.assign(i,e),i.backgroundSync||I()},t.helpers=void 0,t.onHidden=g,t.onVisible=f,t.refreshFeatures=async function(e){let{instance:t,timeout:r,skipCache:n,allowStale:a,backgroundSync:c}=e;return c||(i.backgroundSync=!1),async function(e){let{instance:t,allowStale:r,timeout:n,skipCache:a}=e;const c=v(t),d=y(t),g=new Date,f=new Date(g.getTime()-i.maxAge+i.staleTTL);await async function(){if(!l){l=!0;try{if(s.localStorage){const e=await s.localStorage.getItem(i.cacheKey);if(!i.disableCache&&e){const t=JSON.parse(e);t&&Array.isArray(t)&&t.forEach((e=>{let[t,r]=e;u.set(t,{...r,staleAt:new Date(r.staleAt)})})),m()}}}catch(e){}if(!i.disableIdleStreams){const e=o.startIdleListener();e&&(o.stopIdleListener=e)}}}();const p=i.disableCache||a?void 0:u.get(d);if(p&&(r||p.staleAt>g)&&p.staleAt>f)return p.sse&&h.add(c),p.staleAt<g?_(t):k(t),{data:p.data,success:!0,source:"cache"};{const e=await function(e,t){return new Promise((r=>{let n,i=!1;const s=e=>{i||(i=!0,n&&clearTimeout(n),r(e||null))};t&&(n=setTimeout((()=>s()),t)),e.then((e=>s(e))).catch((()=>s()))}))}(_(t),n);return e||{data:null,success:!1,source:"timeout",error:new Error("Timeout")}}}({instance:t,allowStale:a,timeout:r,skipCache:n})},t.setPolyfills=function(e){Object.assign(s,e)},t.startAutoRefresh=k,t.subscribe=function(e){const t=v(e),r=a.get(t)||new Set;r.add(e),a.set(t,r)},t.unsubscribe=function(e){a.forEach((t=>t.delete(e)))};var n=r(106);const i={staleTTL:6e4,maxAge:864e5,cacheKey:"gbFeaturesCache",backgroundSync:!0,maxEntries:10,disableIdleStreams:!1,idleStreamInterval:2e4,disableCache:!1},s=(0,n.getPolyfills)(),o={fetchFeaturesCall:e=>{let{host:t,clientKey:r,headers:n}=e;return s.fetch("".concat(t,"/api/features/").concat(r),{headers:n})},fetchRemoteEvalCall:e=>{let{host:t,clientKey:r,payload:n,headers:i}=e;const o={method:"POST",headers:{"Content-Type":"application/json",...i},body:JSON.stringify(n)};return s.fetch("".concat(t,"/api/eval/").concat(r),o)},eventSourceCall:e=>{let{host:t,clientKey:r,headers:n}=e;return n?new s.EventSource("".concat(t,"/sub/").concat(r),{headers:n}):new s.EventSource("".concat(t,"/sub/").concat(r))},startIdleListener:()=>{let e;if("undefined"==typeof window||"undefined"==typeof document)return;const t=()=>{"visible"===document.visibilityState?(window.clearTimeout(e),f()):"hidden"===document.visibilityState&&(e=window.setTimeout(g,i.idleStreamInterval))};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},stopIdleListener:()=>{}};t.helpers=o;try{globalThis.localStorage&&(s.localStorage=globalThis.localStorage)}catch(e){}const a=new Map;let l=!1;const u=new Map,c=new Map,d=new Map,h=new Set;function g(){d.forEach((e=>{e&&(e.state="idle",w(e))}))}function f(){d.forEach((e=>{e&&"idle"===e.state&&A(e)}))}async function p(){try{if(!s.localStorage)return;await s.localStorage.setItem(i.cacheKey,JSON.stringify(Array.from(u.entries())))}catch(e){}}function v(e){const[t,r]=e.getApiInfo();return"".concat(t,"||").concat(r)}function y(e){const t=v(e);if(!e.isRemoteEval())return t;const r=e.getAttributes(),n=e.getCacheKeyAttributes()||Object.keys(e.getAttributes()),i={};n.forEach((e=>{i[e]=r[e]}));const s=e.getForcedVariations(),o=e.getUrl();return"".concat(t,"||").concat(JSON.stringify({ca:i,fv:s,url:o}))}function m(){const e=Array.from(u.entries()).map((e=>{let[t,r]=e;return{key:t,staleAt:r.staleAt.getTime()}})).sort(((e,t)=>e.staleAt-t.staleAt)),t=Math.min(Math.max(0,u.size-i.maxEntries),u.size);for(let r=0;r<t;r++)u.delete(e[r].key)}function b(e,t,r){const n=r.dateUpdated||"",s=new Date(Date.now()+i.staleTTL),o=i.disableCache?void 0:u.get(t);if(o&&n&&o.version===n)return o.staleAt=s,void p();i.disableCache||(u.set(t,{data:r,version:n,staleAt:s,sse:h.has(e)}),m()),p();const l=a.get(e);l&&l.forEach((e=>async function(e,t){await e.setPayload(t||e.getPayload())}(e,r)))}async function _(e){const{apiHost:t,apiRequestHeaders:r}=e.getApiHosts(),n=e.getClientKey(),i=e.isRemoteEval(),s=v(e),a=y(e);let l=c.get(a);return l||(l=(i?o.fetchRemoteEvalCall({host:t,clientKey:n,payload:{attributes:e.getAttributes(),forcedVariations:e.getForcedVariations(),forcedFeatures:Array.from(e.getForcedFeatures().entries()),url:e.getUrl()},headers:r}):o.fetchFeaturesCall({host:t,clientKey:n,headers:r})).then((e=>{if(!e.ok)throw new Error("HTTP error: ".concat(e.status));return"enabled"===e.headers.get("x-sse-support")&&h.add(s),e.json()})).then((t=>(b(s,a,t),k(e),c.delete(a),{data:t,success:!0,source:"network"}))).catch((e=>(c.delete(a),{data:null,source:"error",success:!1,error:e}))),c.set(a,l)),l}function k(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const r=v(e),n=y(e),{streamingHost:o,streamingHostRequestHeaders:l}=e.getApiHosts(),u=e.getClientKey();if(t&&h.add(r),i.backgroundSync&&h.has(r)&&s.EventSource){if(d.has(r))return;const e={src:null,host:o,clientKey:u,headers:l,cb:t=>{try{if("features-updated"===t.type){const e=a.get(r);e&&e.forEach((e=>{_(e)}))}else if("features"===t.type){const e=JSON.parse(t.data);b(r,n,e)}e.errors=0}catch(t){S(e)}},errors:0,state:"active"};d.set(r,e),A(e)}}function S(e){if("idle"!==e.state&&(e.errors++,e.errors>3||e.src&&2===e.src.readyState)){const t=Math.pow(3,e.errors-3)*(1e3+1e3*Math.random());w(e),setTimeout((()=>{["idle","active"].includes(e.state)||A(e)}),Math.min(t,3e5))}}function w(e){e.src&&(e.src.onopen=null,e.src.onerror=null,e.src.close(),e.src=null,"active"===e.state&&(e.state="disabled"))}function A(e){e.src=o.eventSourceCall({host:e.host,clientKey:e.clientKey,headers:e.headers}),e.state="active",e.src.addEventListener("features",e.cb),e.src.addEventListener("features-updated",e.cb),e.src.onerror=()=>S(e),e.src.onopen=()=>{e.errors=0}}function E(e,t){w(e),d.delete(t)}function I(){h.clear(),d.forEach(E),a.clear(),o.stopIdleListener()}},200:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"BrowserCookieStickyBucketService",{enumerable:!0,get:function(){return s.BrowserCookieStickyBucketService}}),Object.defineProperty(t,"ExpressCookieStickyBucketService",{enumerable:!0,get:function(){return s.ExpressCookieStickyBucketService}}),Object.defineProperty(t,"GrowthBook",{enumerable:!0,get:function(){return i.GrowthBook}}),Object.defineProperty(t,"LocalStorageStickyBucketService",{enumerable:!0,get:function(){return s.LocalStorageStickyBucketService}}),Object.defineProperty(t,"RedisStickyBucketService",{enumerable:!0,get:function(){return s.RedisStickyBucketService}}),Object.defineProperty(t,"StickyBucketService",{enumerable:!0,get:function(){return s.StickyBucketService}}),Object.defineProperty(t,"clearCache",{enumerable:!0,get:function(){return n.clearCache}}),Object.defineProperty(t,"configureCache",{enumerable:!0,get:function(){return n.configureCache}}),Object.defineProperty(t,"evalCondition",{enumerable:!0,get:function(){return o.evalCondition}}),Object.defineProperty(t,"getAutoExperimentChangeType",{enumerable:!0,get:function(){return a.getAutoExperimentChangeType}}),Object.defineProperty(t,"getPolyfills",{enumerable:!0,get:function(){return a.getPolyfills}}),Object.defineProperty(t,"helpers",{enumerable:!0,get:function(){return n.helpers}}),Object.defineProperty(t,"isURLTargeted",{enumerable:!0,get:function(){return a.isURLTargeted}}),Object.defineProperty(t,"onHidden",{enumerable:!0,get:function(){return n.onHidden}}),Object.defineProperty(t,"onVisible",{enumerable:!0,get:function(){return n.onVisible}}),Object.defineProperty(t,"paddedVersionString",{enumerable:!0,get:function(){return a.paddedVersionString}}),Object.defineProperty(t,"prefetchPayload",{enumerable:!0,get:function(){return i.prefetchPayload}}),Object.defineProperty(t,"setPolyfills",{enumerable:!0,get:function(){return n.setPolyfills}});var n=r(707),i=r(328),s=r(350),o=r(427),a=r(106)},427:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.evalCondition=s;var n=r(106);const i={};function s(e,t,r){r=r||{};for(const[n,i]of Object.entries(t))switch(n){case"$or":if(!d(e,i,r))return!1;break;case"$nor":if(d(e,i,r))return!1;break;case"$and":if(!h(e,i,r))return!1;break;case"$not":if(s(e,i,r))return!1;break;default:if(!a(i,o(e,n),r))return!1}return!0}function o(e,t){const r=t.split(".");let n=e;for(let e=0;e<r.length;e++){if(!n||"object"!=typeof n||!(r[e]in n))return null;n=n[r[e]]}return n}function a(e,t,r){if("string"==typeof e)return t+""===e;if("number"==typeof e)return 1*t===e;if("boolean"==typeof e)return!!t===e;if(null===e)return null===t;if(Array.isArray(e)||!l(e))return JSON.stringify(t)===JSON.stringify(e);for(const n in e)if(!c(n,t,e[n],r))return!1;return!0}function l(e){const t=Object.keys(e);return t.length>0&&t.filter((e=>"$"===e[0])).length===t.length}function u(e,t){return Array.isArray(e)?e.some((e=>t.includes(e))):t.includes(e)}function c(e,t,r,o){switch(e){case"$veq":return(0,n.paddedVersionString)(t)===(0,n.paddedVersionString)(r);case"$vne":return(0,n.paddedVersionString)(t)!==(0,n.paddedVersionString)(r);case"$vgt":return(0,n.paddedVersionString)(t)>(0,n.paddedVersionString)(r);case"$vgte":return(0,n.paddedVersionString)(t)>=(0,n.paddedVersionString)(r);case"$vlt":return(0,n.paddedVersionString)(t)<(0,n.paddedVersionString)(r);case"$vlte":return(0,n.paddedVersionString)(t)<=(0,n.paddedVersionString)(r);case"$eq":return t===r;case"$ne":return t!==r;case"$lt":return t<r;case"$lte":return t<=r;case"$gt":return t>r;case"$gte":return t>=r;case"$exists":return r?null!=t:null==t;case"$in":return!!Array.isArray(r)&&u(t,r);case"$inGroup":return u(t,o[r]||[]);case"$notInGroup":return!u(t,o[r]||[]);case"$nin":return!!Array.isArray(r)&&!u(t,r);case"$not":return!a(r,t,o);case"$size":return!!Array.isArray(t)&&a(r,t.length,o);case"$elemMatch":return function(e,t,r){if(!Array.isArray(e))return!1;const n=l(t)?e=>a(t,e,r):e=>s(e,t,r);for(let t=0;t<e.length;t++)if(e[t]&&n(e[t]))return!0;return!1}(t,r,o);case"$all":if(!Array.isArray(t))return!1;for(let e=0;e<r.length;e++){let n=!1;for(let i=0;i<t.length;i++)if(a(r[e],t[i],o)){n=!0;break}if(!n)return!1}return!0;case"$regex":try{return(c=r,i[c]||(i[c]=new RegExp(c.replace(/([^\\])\//g,"$1\\/"))),i[c]).test(t)}catch(e){return!1}case"$type":return function(e){if(null===e)return"null";if(Array.isArray(e))return"array";const t=typeof e;return["string","number","boolean","object","undefined"].includes(t)?t:"unknown"}(t)===r;default:return console.error("Unknown operator: "+e),!1}var c}function d(e,t,r){if(!t.length)return!0;for(let n=0;n<t.length;n++)if(s(e,t[n],r))return!0;return!1}function h(e,t,r){for(let n=0;n<t.length;n++)if(!s(e,t[n],r))return!1;return!0}},350:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.StickyBucketService=t.RedisStickyBucketService=t.LocalStorageStickyBucketService=t.ExpressCookieStickyBucketService=t.BrowserCookieStickyBucketService=void 0;class r{async getAllAssignments(e){const t={};return(await Promise.all(Object.entries(e).map((e=>{let[t,r]=e;return this.getAssignments(t,r)})))).forEach((e=>{if(e){const r="".concat(e.attributeName,"||").concat(e.attributeValue);t[r]=e}})),t}}t.StickyBucketService=r,t.LocalStorageStickyBucketService=class extends r{constructor(e){e=e||{},super(),this.prefix=e.prefix||"gbStickyBuckets__";try{this.localStorage=e.localStorage||globalThis.localStorage}catch(e){}}async getAssignments(e,t){const r="".concat(e,"||").concat(t);let n=null;if(!this.localStorage)return n;try{const e=await this.localStorage.getItem(this.prefix+r)||"{}",t=JSON.parse(e);t.attributeName&&t.attributeValue&&t.assignments&&(n=t)}catch(e){}return n}async saveAssignments(e){const t="".concat(e.attributeName,"||").concat(e.attributeValue);if(this.localStorage)try{await this.localStorage.setItem(this.prefix+t,JSON.stringify(e))}catch(e){}}},t.ExpressCookieStickyBucketService=class extends r{constructor(e){let{prefix:t="gbStickyBuckets__",req:r,res:n,cookieAttributes:i={}}=e;super(),this.prefix=t,this.req=r,this.res=n,this.cookieAttributes=i}async getAssignments(e,t){const r="".concat(e,"||").concat(t);let n=null;if(!this.req)return n;try{const e=this.req.cookies[this.prefix+r]||"{}",t=JSON.parse(e);t.attributeName&&t.attributeValue&&t.assignments&&(n=t)}catch(e){}return n}async saveAssignments(e){const t="".concat(e.attributeName,"||").concat(e.attributeValue);if(!this.res)return;const r=JSON.stringify(e);this.res.cookie(encodeURIComponent(this.prefix+t),encodeURIComponent(r),this.cookieAttributes)}},t.BrowserCookieStickyBucketService=class extends r{constructor(e){let{prefix:t="gbStickyBuckets__",jsCookie:r,cookieAttributes:n={}}=e;super(),this.prefix=t,this.jsCookie=r,this.cookieAttributes=n}async getAssignments(e,t){const r="".concat(e,"||").concat(t);let n=null;if(!this.jsCookie)return n;try{const e=this.jsCookie.get(this.prefix+r),t=JSON.parse(e||"{}");t.attributeName&&t.attributeValue&&t.assignments&&(n=t)}catch(e){}return n}async saveAssignments(e){const t="".concat(e.attributeName,"||").concat(e.attributeValue);if(!this.jsCookie)return;const r=JSON.stringify(e);this.jsCookie.set(this.prefix+t,r,this.cookieAttributes)}},t.RedisStickyBucketService=class extends r{constructor(e){let{redis:t}=e;super(),this.redis=t}async getAllAssignments(e){const t={},r=Object.entries(e).map((e=>{let[t,r]=e;return"".concat(t,"||").concat(r)}));return this.redis?(await this.redis.mget(...r).then((e=>{e.forEach((e=>{try{const r=JSON.parse(e||"{}");if(r.attributeName&&r.attributeValue&&r.assignments){const e="".concat(r.attributeName,"||").concat(r.attributeValue);t[e]=r}}catch(e){}}))})),t):t}async getAssignments(e,t){return null}async saveAssignments(e){const t="".concat(e.attributeName,"||").concat(e.attributeValue);this.redis&&await this.redis.set(t,JSON.stringify(e))}}},106:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.chooseVariation=function(e,t){for(let r=0;r<t.length;r++)if(o(e,t[r]))return r;return-1},t.decrypt=async function(e,t,n){if(t=t||"",!(n=n||globalThis.crypto&&globalThis.crypto.subtle||r.SubtleCrypto))throw new Error("No SubtleCrypto implementation found");try{const r=await n.importKey("raw",u(t),{name:"AES-CBC",length:128},!0,["encrypt","decrypt"]),[i,s]=e.split("."),o=await n.decrypt({name:"AES-CBC",iv:u(i)},r,u(s));return(new TextDecoder).decode(o)}catch(e){throw new Error("Failed to decrypt")}},t.getAutoExperimentChangeType=function(e){return e.urlPatterns&&e.variations.some((e=>c(e)&&"urlRedirect"in e))?"redirect":e.variations.some((e=>c(e)&&(e.domMutations||"js"in e||"css"in e)))?"visual":"unknown"},t.getBucketRanges=function(e,t,r){(t=void 0===t?1:t)<0?t=0:t>1&&(t=1);const n=s(e);(r=r||n).length!==e&&(r=n);const i=r.reduce(((e,t)=>t+e),0);(i<.99||i>1.01)&&(r=n);let o=0;return r.map((e=>{const r=o;return o+=e,[r,r+t*e]}))},t.getEqualWeights=s,t.getPolyfills=function(){return r},t.getQueryStringOverride=function(e,t,r){if(!t)return null;const n=t.split("?")[1];if(!n)return null;const i=n.replace(/#.*/,"").split("&").map((e=>e.split("=",2))).filter((t=>{let[r]=t;return r===e})).map((e=>{let[,t]=e;return parseInt(t)}));return i.length>0&&i[0]>=0&&i[0]<r?i[0]:null},t.getUrlRegExp=a,t.hash=i,t.inNamespace=function(e,t){const r=i("__"+t[0],e,1);return null!==r&&r>=t[1]&&r<t[2]},t.inRange=o,t.isIncluded=function(e){try{return e()}catch(e){return console.error(e),!1}},t.isURLTargeted=function(e,t){if(!t.length)return!1;let r=!1,n=!1;for(let i=0;i<t.length;i++){const s=l(e,t[i].type,t[i].pattern);if(!1===t[i].include){if(s)return!1}else r=!0,s&&(n=!0)}return n||!r},t.loadSDKVersion=function(){let e;try{e="1.1.0"}catch(t){e=""}return e},t.mergeQueryStrings=function(e,t){let r,n;try{r=new URL(e),n=new URL(t)}catch(e){return console.error("Unable to merge query strings: ".concat(e)),t}return r.searchParams.forEach(((e,t)=>{n.searchParams.has(t)||n.searchParams.set(t,e)})),n.toString()},t.paddedVersionString=function(e){"number"==typeof e&&(e+=""),e&&"string"==typeof e||(e="0");const t=e.replace(/(^v|\+.*$)/g,"").split(/[-.]/);return 3===t.length&&t.push("~"),t.map((e=>e.match(/^[0-9]+$/)?e.padStart(5," "):e)).join("-")},t.toString=function(e){return"string"==typeof e?e:JSON.stringify(e)};const r={fetch:globalThis.fetch?globalThis.fetch.bind(globalThis):void 0,SubtleCrypto:globalThis.crypto?globalThis.crypto.subtle:void 0,EventSource:globalThis.EventSource};function n(e){let t=2166136261;const r=e.length;for(let n=0;n<r;n++)t^=e.charCodeAt(n),t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24);return t>>>0}function i(e,t,r){return 2===r?n(n(e+t)+"")%1e4/1e4:1===r?n(t+e)%1e3/1e3:null}function s(e){return e<=0?[]:new Array(e).fill(1/e)}function o(e,t){return e>=t[0]&&e<t[1]}function a(e){try{const t=e.replace(/([^\\])\//g,"$1\\/");return new RegExp(t)}catch(e){return void console.error(e)}}function l(e,t,r){try{const n=new URL(e,"https://_");if("regex"===t){const e=a(r);return!!e&&(e.test(n.href)||e.test(n.href.substring(n.origin.length)))}return"simple"===t&&function(e,t){try{const r=new URL(t.replace(/^([^:/?]*)\./i,"https://$1.").replace(/\*/g,"_____"),"https://_____"),n=[[e.host,r.host,!1],[e.pathname,r.pathname,!0]];return r.hash&&n.push([e.hash,r.hash,!1]),r.searchParams.forEach(((t,r)=>{n.push([e.searchParams.get(r)||"",t,!1])})),!n.some((e=>!function(e,t,r){try{let n=t.replace(/[*.+?^${}()|[\]\\]/g,"\\$&").replace(/_____/g,".*");return r&&(n="\\/?"+n.replace(/(^\/|\/$)/g,"")+"\\/?"),new RegExp("^"+n+"$","i").test(e)}catch(e){return!1}}(e[0],e[1],e[2])))}catch(e){return!1}}(n,r)}catch(e){return!1}}const u=e=>Uint8Array.from(atob(e),(e=>e.charCodeAt(0)));function c(e){return"object"==typeof e&&null!==e}},182:(e,t,r)=>{"use strict";function n(e){return null!=e&&"object"==typeof e&&!0===e["@@functional/placeholder"]}function i(e){return function t(r){return 0===arguments.length||n(r)?t:e.apply(this,arguments)}}function s(e){return function t(r,s){switch(arguments.length){case 0:return t;case 1:return n(r)?t:i((function(t){return e(r,t)}));default:return n(r)&&n(s)?t:n(r)?i((function(t){return e(t,s)})):n(s)?i((function(t){return e(r,t)})):e(r,s)}}}function o(e){return function t(r,o,a){switch(arguments.length){case 0:return t;case 1:return n(r)?t:s((function(t,n){return e(r,t,n)}));case 2:return n(r)&&n(o)?t:n(r)?s((function(t,r){return e(t,o,r)})):n(o)?s((function(t,n){return e(r,t,n)})):i((function(t){return e(r,o,t)}));default:return n(r)&&n(o)&&n(a)?t:n(r)&&n(o)?s((function(t,r){return e(t,r,a)})):n(r)&&n(a)?s((function(t,r){return e(t,o,r)})):n(o)&&n(a)?s((function(t,n){return e(r,t,n)})):n(r)?i((function(t){return e(t,o,a)})):n(o)?i((function(t){return e(r,t,a)})):n(a)?i((function(t){return e(r,o,t)})):e(r,o,a)}}}function a(e,t){return Object.prototype.hasOwnProperty.call(t,e)}Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var l=i((function(e){return null===e?"Null":void 0===e?"Undefined":Object.prototype.toString.call(e).slice(8,-1)}));function u(e){return"[object Object]"===Object.prototype.toString.call(e)}const c=Number.isInteger||function(e){return(0|e)===e};function d(e,t,r){if(r||(r=new h),function(e){var t=typeof e;return null==e||"object"!=t&&"function"!=t}(e))return e;var n,i=function(t){var n=r.get(e);if(n)return n;for(var i in r.set(e,t),e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=d(e[i],0,r));return t};switch(l(e)){case"Object":return i(Object.create(Object.getPrototypeOf(e)));case"Array":return i(Array(e.length));case"Date":return new Date(e.valueOf());case"RegExp":return n=e,new RegExp(n.source,n.flags?n.flags:(n.global?"g":"")+(n.ignoreCase?"i":"")+(n.multiline?"m":"")+(n.sticky?"y":"")+(n.unicode?"u":"")+(n.dotAll?"s":""));case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"BigInt64Array":case"BigUint64Array":return e.slice();default:return e}}var h=function(){function e(){this.map={},this.length=0}return e.prototype.set=function(e,t){var r=this.hash(e),n=this.map[r];n||(this.map[r]=n=[]),n.push([e,t]),this.length+=1},e.prototype.hash=function(e){var t=[];for(var r in e)t.push(Object.prototype.toString.call(e[r]));return t.join()},e.prototype.get=function(e){if(this.length<=180){for(var t in this.map)for(var r=this.map[t],n=0;n<r.length;n+=1)if((s=r[n])[0]===e)return s[1]}else{var i=this.hash(e);if(r=this.map[i])for(n=0;n<r.length;n+=1){var s;if((s=r[n])[0]===e)return s[1]}}},e}(),g=i((function(e){return null!=e&&"function"==typeof e.clone?e.clone():d(e)}));function f(e,t){for(var r=t,n=0;n<e.length;n+=1){if(null==r)return;var i=e[n];r=c(i)?(o=r,a=void 0,l=void 0,l=(s=i)<0?o.length+s:s,a=o,"[object String]"===Object.prototype.toString.call(a)?o.charAt(l):o[l]):r[i]}var s,o,a,l;return r}var p=o((function(e,t,r){var n,i={};for(n in r=r||{},t=t||{})a(n,t)&&(i[n]=a(n,r)?e(n,t[n],r[n]):t[n]);for(n in r)a(n,r)&&!a(n,i)&&(i[n]=r[n]);return i})),v=o((function e(t,r,n){return p((function(r,n,i){return u(n)&&u(i)?e(t,n,i):t(r,n,i)}),r,n)})),y=o((function(e,t,r){return v((function(t,r,n){return e(r,n)}),t,r)})),m=s(f),b=s((function(e,t){var r={};for(var n in t)e(t[n],n,t)&&(r[n]=t[n]);return r}));const _=e=>"function"==typeof e&&Boolean(e.constructor&&e.call&&e.apply),k=e=>"string"==typeof e,S=e=>null===e,w=e=>void 0===e,A=e=>S(e)||w(e),E=e=>!w(e),I=e=>!A(e),T=e=>e instanceof Error,P=(e,t)=>{const r=t.split(".");return m(r,e)},C=e=>!S(e)&&"object"==typeof e&&!Array.isArray(e),x=e=>!S(e)&&"[object Object]"===Object.prototype.toString.call(e),O=(e,t)=>{if(!Array.isArray(e)||!Array.isArray(t))return g(t);const r=g(e);return t.forEach(((e,t)=>{r[t]=Array.isArray(e)||C(e)?R(r[t],e):e})),r},R=(e,t)=>y(O,e,t),D=e=>x(e)&&Object.keys(e).length>0,B=e=>{const t=b(E,e);return Object.keys(t).forEach((e=>{const r=t[e];x(r)&&(t[e]=B(r))})),t},M=e=>{const t=b(I,e);return Object.keys(t).forEach((e=>{const r=t[e];x(r)&&(t[e]=M(r))})),t},$=e=>{let t=e;if(!k(e)&&!A(e))try{t=JSON.stringify(e)}catch(e){t=null}return t},j=(e,t,r,n,i)=>{const s={category:e,name:t,properties:r,options:n};return _(i)&&(s.callback=i),_(n)&&(s.category=e,s.name=t,s.properties=r,delete s.options,s.callback=n),_(r)&&(s.category=e,s.name=t,delete s.properties,delete s.options,s.callback=r),_(t)&&(s.category=e,delete s.name,delete s.properties,delete s.options,s.callback=t),_(e)&&(delete s.category,delete s.name,delete s.properties,delete s.options,s.callback=e),x(e)?(delete s.name,delete s.category,s.properties=e,s.options=t):x(t)&&(delete s.name,s.properties=t,s.options=_(r)?null:r),k(e)&&!k(t)&&(delete s.category,s.name=e),E(s.category)||delete s.category,E(s.name)||delete s.name,s.properties=s.properties?g(s.properties):{},E(s.options)?s.options=g(s.options):delete s.options,s.properties=R(x(s.properties)?s.properties:{},{name:k(s.name)?s.name:null,category:k(s.category)?s.category:null}),s},L=(e,t,r,n)=>{const i={name:e,properties:t,options:r};return _(n)&&(i.callback=n),_(r)&&(i.properties=t,delete i.options,i.callback=r),_(t)&&(delete i.properties,delete i.options,i.callback=t),i.properties=I(i.properties)?g(i.properties):{},E(i.options)?i.options=g(i.options):delete i.options,i},U=(e,t,r,n)=>{const i={userId:e,traits:t,options:r};return _(n)&&(i.callback=n),_(r)&&(i.userId=e,i.traits=t,delete i.options,i.callback=r),_(t)&&(i.userId=e,delete i.traits,delete i.options,i.callback=t),(x(e)||S(e))&&(i.userId=null,i.traits=e,i.options=t),E(i.userId)?i.userId=$(i.userId):delete i.userId,x(i.traits)?i.traits=g(i.traits):delete i.traits,E(i.options)?i.options=g(i.options):delete i.options,i},N=(e,t,r,n)=>{const i={to:e,from:t,options:r};return _(n)&&(i.callback=n),_(r)&&(i.to=e,i.from=t,delete i.options,i.callback=r),_(t)?(i.to=e,delete i.from,delete i.options,i.callback=t):(x(t)||S(t))&&(i.to=e,delete i.from,i.options=t),_(e)?(delete i.to,delete i.from,delete i.options,i.callback=e):(x(e)||S(e))&&(delete i.to,delete i.from,i.options=e),E(i.to)?i.to=$(i.to):delete i.to,E(i.from)?i.from=$(i.from):delete i.from,E(i.options)?i.options=g(i.options):delete i.options,i},F=(e,t,r,n)=>{const i={groupId:e,traits:t,options:r};return _(n)&&(i.callback=n),_(r)&&(i.groupId=e,i.traits=t,delete i.options,i.callback=r),_(t)&&(i.groupId=e,delete i.traits,delete i.options,i.callback=t),_(e)?(i.groupId=null,delete i.traits,delete i.options,i.callback=e):(x(e)||S(e))&&(i.groupId=null,i.traits=e,i.options=_(t)?null:t),E(i.groupId)?i.groupId=$(i.groupId):delete i.groupId,i.traits=x(i.traits)?g(i.traits):{},E(i.options)?i.options=g(i.options):delete i.options,i},V="CapabilitiesManager",H="ConfigManager",K="EventManager",G="PluginsManager",z="UserSessionManager",Q="ErrorHandler",J="PluginEngine",q="StoreManager",W="RudderStackApplication",Y="AnalyticsCore",Z="RudderLabs JavaScript SDK",X="3.5.1",ee="RudderJS-Initiated",te="preloadedEventsBuffer",re="ajs_aid",ne="ajs_uid",ie="ajs_event",se=18e5,oe=(e="app")=>{globalThis.RudderStackGlobals||(globalThis.RudderStackGlobals={}),globalThis.RudderStackGlobals[e]||(globalThis.RudderStackGlobals[e]={})},ae=(e,t,r="app")=>{oe(r),globalThis.RudderStackGlobals[r][e]=t},le=(e,t)=>{const r={};return e.forEach(((n,i)=>{if(i.startsWith(t)){const n=i.substring(t.length);r[n]=e.get(i)}})),r},ue=(e,t)=>{const r=e.shift();let n;if(_(t[r])){switch(r){case"page":n=j(...e);break;case"track":n=L(...e);break;case"identify":n=U(...e);break;case"alias":n=N(...e);break;case"group":n=F(...e);break;default:t[r](...e)}n&&t[r](n)}},ce=":: ",de=(e,t)=>`Failed to load the script with the id "${e}" from URL "${t}".`,he=(e,t,r)=>{const n=[];return function(i,s){if(!(t?.includes(i)||e&&A(s))){if("object"!=typeof s||S(