mirror of
https://github.com/rxliuli/apps.apple.com.git
synced 2025-11-09 18:50:32 +00:00
3 lines
49 KiB
JavaScript
3 lines
49 KiB
JavaScript
import{s as S,a as m,r as s,e as Ae,c as Ke,d as mt,n as _t,k as re}from"./mt-metricskit-utils-private.esm~DkzakSThTT.js";import{l as Ue}from"./mt-client-logger-core.esm~-rJfHcY8Zf.js";var X=function(){};X.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};X.prototype.localStorageObject=S.localStorageObject;X.prototype.sessionStorageObject=S.sessionStorageObject;X.prototype.platformIdentifier=function(e,r,n){};var St=function(){this.environment=new X,this.logger=Ue("mt-client-constraints")};function Se(t,e,r,n){if(!s.isDefined(t)||!s.isDefinedNonNullNonEmpty(e)||!s.isFunction(n))return t;var o=e.split(".");return Te(t,o,null,[],null,r,n)}function Te(t,e,r,n,o,i,a){if(s.isFunction(t))return o||t;if(n.push(r),e.length===0)return a(t,r,n.slice(1).join("."),o),o||t;if(!s.isDefined(t))return o||t;var c=i?t:{},p=e.shift();if(p.length>2&&p.indexOf("[]")===p.length-2){p=p.slice(0,-2),n.push(p),s.extend(c,t);var u=c[p];if(s.isDefinedNonNull(u)){var l=u.map(function(h,v){var N=i?u:u.slice();return Te(h,e.slice(),v,n,N,i,a),n.pop(),N[v]});c[p]=l}}else{var f=t[p];s.extend(c,t),c=Te(f,e,p,n,c,i,a)}return n.pop(),o?(o[r]=c,o):c}var Fe={all:{initMatchValue:!0,accumulateMatchResult:function(t,e){return t&&e}},any:{initMatchValue:!1,accumulateMatchResult:function(t,e){return t||e}}};function Tt(t){var e=Fe[t];return s.isDefinedNonNull(e)||(e=Fe.all),e}function It(t,e,r){if(!s.isObject(e)||!s.isObject(r))return!1;var n=r.matchType,o=r.matches;if(!s.isDefinedNonNullNonEmpty(o))return!1;var i=Tt(n),a=i.initMatchValue;return Se(e,t,!1,function(c,p,u,l){var f=Object.keys(o).every(function(h){var v=o[h];return s.isDefinedNonNull(R[h])?R[h](p,l,v):!1});a=i.accumulateMatchResult(a,f)}),!!a}function Et(t,e){return!!s.isObject(e)&&e.hasOwnProperty(t)&&s.isDefinedNonNullNonEmpty(e[t])}function bt(t,e,r){if(!s.isObject(e))return!1;var n=e[t];return e.hasOwnProperty(t)&&r.indexOf(n)>-1}function Dt(t,e,r){if(!s.isObject(e)||!s.isArray(r))return!1;var n=e[t];return e.hasOwnProperty(t)&&r.indexOf(n)===-1}var R={nonEmpty:Et,valueMatches:bt,nonValueMatches:Dt,nestedFieldMatches:It},ne={OVERRIDE_FIELD_VALUE:"overrideFieldValue"},Ne=function(){};Ne.prototype.constrainedValue=function(e,r,n){var o=e&&e.hasOwnProperty(n)?e[n]:null;return this.applyConstraintRules(o,r)};Ne.prototype.applyConstraintRules=function(e,r){var n=e;if(r){var o=r.denylisted||r.blacklisted;o?n=null:r.hasOwnProperty(ne.OVERRIDE_FIELD_VALUE)&&(n=r.overrideFieldValue)}return n};var At=m.exceptionString,b=function(e){this._constraintsInstance=e};b.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};b.prototype.constrainedValue=function(e,r,n,o){throw At("field_actions.Base","constrainedValue")};b.prototype.performAction=function(e,r,n,o){return s.isDefinedNonNull(o)&&!s.isEmptyObject(o)&&(e=this.constrainedValue(e,o,n,r)),e};function Ge(t){t=t||"";var e=Re(t).split("/"),r,n,o;return t.indexOf("//")===-1?r=e[0]:r=e[2],n=r.substring(r.indexOf("@")+1),o=n.split(":")[0],o}function Nt(t){var e=Ge(t).split("."),r=e[e.length-1],n=e[e.length-2],o=2;return r&&r.length===2&&n&&(n.length===2||n in wt())&&(o=3),e.slice(-1*o).join(".")}function wt(){var t={com:!0,org:!0,net:!0,edu:!0,gov:!0};return t}function Re(t,e){var r=t||"",n=r.split("?"),o=n[0],i=Ot(n[1]).split("&"),a=i.filter(function(c){var p=c.split("="),u=p[0],l=p[1];return s.isArray(e)?e.indexOf(u)!==-1:s.isObject(e)?s.isObject(e[u])&&s.isArray(e[u].allowedValues)&&e[u].allowedValues.indexOf(l)!==-1:!1}).join("&");return a.length>0?o+"?"+a:o}function Ot(t){var e=t||"";return e.split("#")[0]}function Pt(t,e){var r=t||"",n=e||[],o=n.reduce(function(i,a){var c=new RegExp(a.searchPattern,a.flags),p=a.replaceVal;return i.replace(c,p)},r);return o}var Ie="-",xt="z";function $e(t){if(!s.isDefinedNonNull(t)||!s.isInteger(t.idVersion))return"0";var e=m.uuid(),r=t.generatedIdSeparator||xt,n=Ft(t)+Ie+e||"",o=n.split(Ie).map(function(i){var a=parseInt(i,16);return m.convertNumberToBaseAlphabet(a,m.base61Alphabet)}).join(r);return o}function Ft(t){var e=[t.idVersion];return t.time&&e.push(t.time),e.map(function(r){return r.toString(16)}).join(Ie)}function ze(t,e,r,n){var o=this.storageKey(n,r,e),i=this._constraintsInstance.system.environment,a=S.objectFromStorage(i.localStorageObject(),o)||{};return a.value=this.idString(a,e),this.rulesHaveLifespan(e)&&(!s.isNumber(a.expirationTime)||this.timeExpired(a.expirationTime))&&(a.expirationTime=this.expirationTime(e.lifespan)),S.saveObjectToStorage(i.localStorageObject(),o,a),t=a.value,t}var Me={};function Mt(t,e,r,n){var o=this.storageKey(n,r,e),i=Me[o];return i||(i=ze.apply(this,arguments),Me[o]=i),i}var we="_",Vt="mtId",_=function(){b.apply(this,arguments)};_.prototype=Object.create(b.prototype);_.prototype.constructor=_;_.prototype.SCOPE_STRATEGIES={ALL:"all",MAIN_DOMAIN:"mainDomain"};_.prototype.rulesHaveLifespan=function(e){return e=e||{},s.isNumber(e.lifespan)};_.prototype.expirationTime=function(e){return e?Date.now()+e:null};_.prototype.storageKey=function(e,r,n){var o=this.scope(r,n);return this.storageKeyPrefix(n,e)+(o?we+o:"")};_.prototype.storageKeyPrefix=function(e,r){return e&&s.isString(e.storageKeyPrefix)&&e.storageKeyPrefix.length>0?e.storageKeyPrefix:Vt+we+r};_.prototype.scope=function(e,r){var n="";if(r&&(r.namespace&&(n+=r.namespace),r.scopeStrategy)){var o;switch(r.scopeStrategy){case this.SCOPE_STRATEGIES.MAIN_DOMAIN:var i=r.scopeFieldName;o=Nt(e[i])||"unknownDomain";break;case this.SCOPE_STRATEGIES.ALL:default:o=this.SCOPE_STRATEGIES.ALL;break}n.length&&(n+=we),n+=o}return n};_.prototype.idString=function(e,r){var n=e?e.value:null,o=n;return(!n||s.isNumber(e.expirationTime)&&this.timeExpired(e.expirationTime))&&(o=this.generateId(r)),o};_.prototype.generateId=function(e){return e=e||{},$e({idVersion:this.generatedIdVersion(),time:this.expirationTime(e.lifespan),generatedIdSeparator:this.generatedIdSeparator(e.tokenSeparator)})};_.prototype.generatedIdVersion=function(){return 4};_.prototype.idTokenSeparator=function(){return"-"};_.prototype.generatedIdSeparator=function(e){return e||"z"};_.prototype.timeExpired=function(e){return e<=Date.now()};_.prototype.constrainedValue=function(e,r,n,o){return n&&r&&!s.isEmptyObject(r)&&(r.persistIdForSession===!0?e=Mt.apply(this,arguments):e=ze.apply(this,arguments)),e};var Je=function(e,r){this._base=e,this._idAction=new _(r),this._idAction.setDelegate({storageKey:(function(o,i,a){return this.storageKeyPrefix()+"_"+this.scope(i,a)}).bind(this._idAction),storageKeyPrefix:function(){return"mtClientId"}})};Je.prototype.constrainedValue=function(e,r){var n=r;r&&s.isNumber(r.expirationPeriod)&&(n=s.extend({},r),n.lifespan=n.expirationPeriod,delete n.expirationPeriod);var o=e?e.clientId:null,i=this._idAction.performAction(o,"clientId",e,n);return this._base.applyConstraintRules(i,r)};var G=function(){b.apply(this,arguments)};G.prototype=Object.create(b.prototype);G.prototype.constructor=G;G.prototype.SCOPES={HOSTNAME:"hostname",FULL:"full",FULL_WITHOUT_PARAMS:"fullWithoutParams",FULL_WITH_REPLACEMENTS:"fullWithReplacements"};G.prototype.constrainedValue=function(e,r){if(e&&r&&r.scope)switch(r.scope){case this.SCOPES.HOSTNAME:e=Ge(e);break;case this.SCOPES.FULL_WITHOUT_PARAMS:e=Re(e,r.allowedParams);break;case this.SCOPES.FULL_WITH_REPLACEMENTS:e=Pt(e,r.replacements);break;case this.SCOPES.FULL:}return e};var Ye=function(e){this._base=e,this._urlAction=new G};Ye.prototype.constrainedValue=function(e,r){var n=e?e.parentPageUrl:null,o=this._urlAction.performAction(n,"parentPageUrl",e,r);return this._base.applyConstraintRules(o,r)};var Ct=function(t){this.base=new Ne,this.clientId=new Je(this.base,t),this.parentPageUrl=new Ye(this.base)},Oe=function(e){this._fieldHandlers=new Ct(e)};Oe.prototype.applyConstraints=function(e,r){return r&&r.fieldConstraints&&(e=this.applyFieldConstraints(e,r.fieldConstraints)),e};Oe.prototype.applyFieldConstraints=function(e,r){if(r){var n={},o,i,a;for(a in r)i=r[a],(e.hasOwnProperty(a)||i.generateValue===!0||i.hasOwnProperty(ne.OVERRIDE_FIELD_VALUE))&&(a in this._fieldHandlers?o=this._fieldHandlers[a].constrainedValue(e,i):o=this._fieldHandlers.base.constrainedValue(e,i,a),n[a]=o);for(a in n)e[a]=n[a];e=Ae.mergeAndCleanEventFields(e)}return e};function qe(t,e,r,n){var o=t||{};if(n=n||function(u,l,f){return u[f]||{}},e&&e[r]){var i,a,c=o[r]||{};o[r]=c;for(i in e[r]){var p=n(c,e[r],i);c[i]=p;for(a in e[r][i])p[a]=e[r][i][a]}}return o}var $=function(e){this.treatment=new Oe(e)};$.prototype.constraintsForEvent=function(e,r,n){if(!r)return Promise.resolve(null);var o=this;return Promise.resolve(r.constraintProfile(n)).then(function(i){if(!i)return null;var a="constraints.profiles."+i;return r.value(a,n)}).then(function(i){var a=null;return i&&i.precedenceOrderedRules&&(a=i.precedenceOrderedRules.reduce(function(c,p){return o.eventMatchesRule(e,p)&&(c=o.updateRules(c,p)),c},{})),a})};$.prototype.eventMatchesRule=function(e,r){var n=!1;return e&&r.filters&&(r.filters==="any"?n=!0:s.isObject(r.filters)&&(n=this.eventMatchesNonEmptyFields(e,r.filters.nonEmptyFields)&&this.eventMatchesFieldValues(e,r.filters.valueMatches))),n};$.prototype.eventMatchesNonEmptyFields=function(e,r){var n=!1;return e&&(!r||!s.isArray(r)?n=!0:n=r.every(function(o){return R.nonEmpty(o,e)})),n};$.prototype.eventMatchesFieldValues=function(e,r){var n=!1;return e&&(!r||!s.isObject(r)||s.isEmptyObject(r)?n=!0:n=Object.keys(r).every(function(o){var i=r[o];return R.valueMatches(o,e,i)})),n};$.prototype.updateRules=function(e,r){return qe(e,r,"fieldConstraints")};var We=function(){};We.prototype.performAction=function(e,r,n){return n!==!0?e:null};var Qe=function(){};Qe.prototype.performAction=function(e,r,n){return!e||!s.isArray(n)||s.isEmptyArray(n)?e:(e=s.extend({},e),n.forEach(function(o){delete e[o]}),s.isEmptyObject(e)?null:e)};var Xe=function(){};Xe.prototype.performAction=function(e,r,n){if(!e||!s.isArray(n)||s.isEmptyArray(n))return e;var o={};return n.forEach(function(i){s.isDefinedNonNull(e[i])&&(o[i]=e[i])}),s.isEmptyObject(o)?null:o};var kt="mtSessionization",Ze="_",Lt="-",he="sessionId",ye="sessionStartTime",j=function(e){this._constraintsInstance=e};j.prototype.performAction=function(e,r,n){if(!s.isDefinedNonNull(e)||!s.isDefined(n))return e;if(s.isDefinedNonNull(n.sessionResetOptions)){if(!s.isDefinedNonNull(n.sessionResetOptions.filters))throw new SyntaxError('sessionizationFields Action: unable to find the required config "filters"');var o=this._resetSession(e,r,n);if(o!==!0)return e}e=s.extend({},e);var i=this._storageKey(e,n),a=this._constraintsInstance.system.environment,c=S.objectFromStorage(a.localStorageObject(),i)||{};this._shouldCreateNewSession(r,c,n)&&(c.sessionId=this._generateSessionId(n),c.rawFirstEventTimeInSession=r.eventTime,c.firstEventTimeInSession=e.eventTime,c.eventCount=0),c.rawLastEventTimeInSession=r.eventTime,c.lastEventTimeInSession=e.eventTime,c.eventCount+=1,S.saveObjectToStorage(a.localStorageObject(),i,c);var p=this._getSessionFieldNames(n);return e[p.sessionId]=c.sessionId,n.sessionStartTime&&(e[p.sessionStartTime]=c.firstEventTimeInSession),e};j.prototype._storageKey=function(e,r){var n=this._scope(e,r);return this._storageKeyPrefix(r)+(s.isEmptyString(n)?"":Ze+n)};j.prototype._storageKeyPrefix=function(e){return e&&s.isString(e.storageKeyPrefix)&&e.storageKeyPrefix.length>0?e.storageKeyPrefix:kt};j.prototype._scope=function(e,r){var n="";return s.isDefined(r)&&(s.isString(r.namespace)&&(n+=r.namespace),s.isString(r.scopeFieldName)&&s.isDefinedNonNull(e[r.scopeFieldName])&&(n+=Ze,n+=e[r.scopeFieldName].toString())),n};j.prototype._generateSessionId=function(e){return $e({idVersion:1,time:Date.now(),idTokenSeparator:Lt,generatedIdSeparator:e.tokenSeparator})};j.prototype._shouldCreateNewSession=function(e,r,n){var o=!1;return o|=!s.isDefinedNonNull(r.sessionId),s.isDefinedNonNull(n.endSessionConditions)&&(s.isDefinedNonNull(n.endSessionConditions.lifespan)&&(o|=e.eventTime>=r.rawFirstEventTimeInSession+n.endSessionConditions.lifespan),s.isDefinedNonNull(n.endSessionConditions.idleSpan)&&(o|=e.eventTime>=r.rawLastEventTimeInSession+n.endSessionConditions.idleSpan),s.isDefinedNonNull(n.endSessionConditions.eventCount)&&(o|=r.eventCount>=n.endSessionConditions.eventCount)),o};j.prototype._resetSession=function(e,r,n){var o=n.sessionResetOptions,i=this._constraintsInstance._constraintGenerator;if(s.isDefinedNonNull(i)&&s.isDefinedNonNull(i.eventMatchesTreatment)&&i.eventMatchesTreatment(r,o)){var a=this._storageKey(e,n),c=this._constraintsInstance.system.environment;return S.saveObjectToStorage(c.localStorageObject(),a,void 0),o.newSessionAfterReset}return!0};j.prototype._getSessionFieldNames=function(e){var r={sessionId:he,sessionStartTime:ye};return s.isDefinedNonNull(e.sessionFields)&&(s.isDefinedNonNullNonEmpty(e.sessionFields[he])&&(r.sessionId=e.sessionFields[he]),s.isDefinedNonNullNonEmpty(e.sessionFields[ye])&&(r.sessionStartTime=e.sessionFields[ye])),r};var U={blacklistedEventAction:"blacklisted",denylistedEventAction:"denylisted",blacklistedFieldsAction:"blacklistedFields",denylistedFieldsAction:"denylistedFields",whitelistedFieldsAction:"whitelistedFields",allowlistedFieldsAction:"allowlistedFields",sessionizationFieldsAction:"sessionizationFields"},et=function(e){var r=new We,n=new Qe,o=new Xe,i=new j(e);this._actions={},this._actions[U.blacklistedEventAction]=r,this._actions[U.denylistedEventAction]=r,this._actions[U.blacklistedFieldsAction]=n,this._actions[U.denylistedFieldsAction]=n,this._actions[U.whitelistedFieldsAction]=o,this._actions[U.allowlistedFieldsAction]=o,this._actions[U.sessionizationFieldsAction]=i};et.prototype.getAction=function(e){return this._actions[e]};var q="start",jt="value",Bt=function(e,r){var n=-1,o=n;if(!s.isDefinedNonNull(r)||e.length===0||s.isDefinedNonNull(e[0])&&r<e[0][q])return n;if(e[e.length-1][q]<r)o=e.length-1;else for(var i=0;i<e.length;i++){var a=e[i][q];if(a===r){o=i;break}else if(a>r){o=i-1;break}}return o},W=function(){b.apply(this,arguments)};W.prototype=Object.create(b.prototype);W.prototype.constructor=W;W.prototype.constrainedValue=function(e,r){var n=r?r.precision:0,o=r?r.buckets:null;if(s.isDefinedNonNullNonEmpty(o)){o=o.slice().sort(function(c,p){return c[q]-p[q]});var i=Bt(o,e),a=o[i];s.isDefinedNonNull(a)&&(e=a[jt])}else s.isNumber(e)&&s.isNumber(n)&&n>0&&(e=Math.floor(e/n)*n);return e};var Ht="mt_serial_number",oe="exp",Ee="sn",B=function(e){e=e||{},this._nextRotationTime=e.nextRotationTime||Number.POSITIVE_INFINITY,this._storageKey=e.namespace||Ht,this._initialSerialNumber=e.initialSerialNumber||0,this._rotationPeriod=e.rotationPeriod||Number.POSITIVE_INFINITY};B.prototype.setDelegate=function(e){s.attachDelegate(this,e)};B.prototype.localStorageObject=function(){return S.localStorageObject()};B.prototype.getNextSerialNumber=function(e){var r=this._storageKey,n=this._getCurrentSerialNumberData(r),o=n[Ee];return e=s.isNumber(e)?e:1,o=parseInt(o,10),isNaN(o)&&(o=this._initialSerialNumber),o=this._increaseSerialNumber(o,e),n[Ee]=o,S.saveObjectToStorage(this.localStorageObject(),this._storageKey,n),o};B.prototype.resetSerialNumber=function(){var e=S.objectFromStorage(this.localStorageObject(),this._storageKey);s.isDefinedNonNull(e)&&this._resetSerialNumber(e[oe])};B.prototype.getTime=function(){return Date.now()};B.prototype._increaseSerialNumber=function(e,r){return e+r};B.prototype._getCurrentSerialNumberData=function(e){var r=S.objectFromStorage(this.localStorageObject(),e),n,o;for(r?(n=r[oe],n=parseInt(n,10),r[oe]=n=isNaN(n)?this._nextRotationTime:n):n=this._nextRotationTime-this._rotationPeriod;!r||this.getTime()>=n;)n=o=n+this._rotationPeriod,r=this._resetSerialNumber(o);return r};B.prototype._resetSerialNumber=function(e){var r={};return r[oe]=e,r[Ee]=this._initialSerialNumber,S.saveObjectToStorage(this.localStorageObject(),this._storageKey,r),r};var Ve="_",Kt="mtTimestamp",H=function(){b.apply(this,arguments),this._storage=this._constraintsInstance.system.environment.localStorageObject(),this._precisionEndTimeCache={},this._serialNumberGenerator=null};H.prototype=Object.create(b.prototype);H.prototype.constructor=H;H.prototype.constrainedValue=function(e,r,n,o){var i=e;if(s.isNumber(e)&&s.isObject(r)&&s.isNumber(r.precision)&&r.precision>0){var a=this._computePrecisionStartTime(e,r);this._serialNumberGenerator=new B({namespace:this._persistentStorageKey(r,o),nextRotationTime:a+r.precision,rotationPeriod:r.precision}),this._serialNumberGenerator.setDelegate(this._constraintsInstance.system.environment),this._serialNumberGenerator.setDelegate({getTime:function(){return e}});var c=this._serialNumberGenerator.getNextSerialNumber();i=this._computeTimestamp(a,c),this._serialNumberGenerator=null}return i};H.prototype._computeTimestamp=function(e,r){return e+r};H.prototype._persistentStorageKey=function(e,r){var n=e.namespace?Ve+e.namespace:"";return(e.storageKeyPrefix||Kt)+n+Ve+r};H.prototype._computePrecisionStartTime=function(e,r){var n=r.precision;return Math.floor(e/n)*n};var ve="_",Ut="mtHash",Gt="salt",Rt=10,w=function(){b.apply(this,arguments)};w.prototype=Object.create(b.prototype);w.prototype.constructor=w;function tt(t,e){var r=t.namespace?ve+t.namespace:"";return(t.storageKeyPrefix||Ut)+r+ve+Gt+ve+e}function $t(){for(var t="";t.length<Rt;)t+=m.randomHexCharacter();return t}function zt(t,e){return[t,e].map(function(r){var n=0;if(s.isDefinedNonNullNonEmpty(r))for(var o=0;o<r.length;o++){var i=r.charCodeAt(o);n=(n<<5)-n+i}var a=Math.abs(n);return a=parseInt(a,16),m.convertNumberToBaseAlphabet(a,m.base62Alphabet)}).join("")}w.prototype.constrainedValue=function(e,r,n,o){return s.isDefinedNonNullNonEmpty(e)?this._loadPlatformBasedSalt(r,o).then(function(i){return zt(e,i)}):e};w.prototype.timeExpired=function(e){return e?e<=Date.now():!1};w.prototype.expirationTime=function(e){return e?Date.now()+e:null};w.prototype._loadPlatformBasedSalt=function(e,r){var n=null,o=this,i=e.platformBasedSalt;return s.isDefinedNonNull(i)?(n=this._constraintsInstance.system.environment.platformIdentifier(i.saltNamespace,"userid",i.crossDeviceSync||!0),s.isDefinedNonNull(n)?n=n.then(function(a){return s.isDefinedNonNull(a)||(o._constraintsInstance.system.logger.warn("Hash: platform returned an empty salt. Will use default salt generator to generate the salt."),a=o._getSalt(e,r)),a}):n=Promise.resolve(this._getSalt(e,r))):n=Promise.resolve(this._getSalt(e,r)),n};w.prototype._getSalt=function(e,r){var n=this._retrieveSaltFromStorage(e,r),o=e.saltLifespan;if(!s.isDefinedNonNull(n)||this.timeExpired(n.expirationTime)){var i=this._constraintsInstance.system.environment.localStorageObject(),a=$t();n={salt:a,expirationTime:this.expirationTime(o)},S.saveObjectToStorage(i,tt(e,r),n)}return n.salt};w.prototype._retrieveSaltFromStorage=function(e,r){var n=this._constraintsInstance.system.environment.localStorageObject(),o=S.objectFromStorage(n,tt(e,r));return o};var Y={ID:"idGenerator",NUMBER:"numberDeres",TIME:"timeDeres",URL:"urlDeres",HASH:"hash"},rt=function(e){this.actions={},this.actions[Y.ID]=new _(e),this.actions[Y.NUMBER]=new W(e),this.actions[Y.TIME]=new H(e),this.actions[Y.URL]=new G(e),this.actions[Y.HASH]=new w(e)};rt.prototype.getAction=function(e){return this.actions[e]};var nt=function(e){this._eventActions=new et(e),this._fieldActions=new rt(e)};nt.prototype.applyConstraints=function(e,r){var n=e;if(r&&!s.isEmptyObject(r)){var o=[],i=this;if(r.fieldActions&&!s.isEmptyObject(r.fieldActions)){var a=!1,c=n;c=Object.keys(r.fieldActions).reduce(function(l,f){var h=r.fieldActions[f];if(h){var v=h.denylisted||h.blacklisted,N=h.treatmentType,K=i._fieldActions.getAction(N);l=Se(l,f,!1,function(ee,J,ue,le){if(v)delete le[J],a=!0;else if(h.hasOwnProperty(ne.OVERRIDE_FIELD_VALUE))le[J]=h[ne.OVERRIDE_FIELD_VALUE],a=!0;else if(K){var fe=K.performAction(ee,f,n,h);le[J]=fe,fe instanceof Promise&&o.push(fe.then(function(yt){Se(c,f,!0,function(br,vt,dt,gt){dt===ue&&(gt[vt]=yt)})})),a=!0}})}return l},c),a&&(o.length>0?n=Promise.all(o).then(function(){return c}):n=c)}if(r.eventActions&&!s.isEmptyObject(r.eventActions)){var p=Object.keys(r.eventActions),u=function(l){return p.forEach(function(f){var h=i._eventActions.getAction(f);if(h){var v=r.eventActions[f];l=h.performAction(l,e,v)}}),l};n instanceof Promise?n=Promise.resolve(n).then(function(l){return u(l)}):n=u(n)}}return n};var Jt="filters",Yt="any",te="eventActions",de="fieldActions";function qt(t,e){var r=t||{};return Wt(r,e),Qt(r,e),r}function Wt(t,e){t[te]||(t[te]={});var r=t[te],n=e[te];n&&Object.keys(n).reduce(function(o,i){var a=o[i],c=n[i];return s.isArray(a)?s.isArray(c)&&c.forEach(function(p){a.indexOf(p)===-1&&a.push(p)}):s.isArray(c)?o[i]=c.slice():(s.isObject(c)||!s.isObject(c)&&!s.isFunction(c))&&(o[i]=c),o},r)}function Qt(t,e){t[de]||(t[de]={}),qe(t,e,de,function(r,n,o){return r[o]&&r[o].treatmentType===n[o].treatmentType?r[o]:{}})}var ie=function(e){this._constraintsInstance=e,this.treatment=new nt(e)};ie.prototype._combineTreatments=function(e,r,n){var o,i=[];return s.isArray(e)?(e.forEach(function(a){if(a){var c="treatmentProfiles."+a,p=r.value(c,n).then(function(u){return u&&u.treatments?u.treatments:[]});i.push(p)}}),o=Promise.all(i).then(function(a){var c=[];return a.forEach(function(p){c=c.concat(p)}),c})):o=Promise.resolve([]),o};ie.prototype.constraintsForEvent=function(e,r,n){if(!r)return Promise.resolve(null);var o=this;return Promise.resolve(r.constraintProfiles(n)).then(function(i){return s.isDefinedNonNull(i)?i:Promise.resolve(r.constraintProfile(n)).then(function(a){return s.isDefinedNonNull(a)?[a]:null})}).then(function(i){if(s.isDefinedNonNull(i)){if(!s.isArray(i))throw new TypeError('"constraintProfiles" should be an Array, but got: '+(i&&i.constructor));return o._combineTreatments(i,r,n).then(function(a){if(a.length===0)throw new SyntaxError("The constraintProfiles: "+i.join(", ")+" are not found in the topic config");return a})}else return Promise.resolve([])}).then(function(i){var a=i.reduce(function(c,p){return o.eventMatchesTreatment(e,p)&&(c=qt(c,p)),c},null);return a})};ie.prototype.eventMatchesTreatment=function(e,r){var n=r[Jt];if(!s.isDefinedNonNull(n))return!0;if(s.isString(n))return n===Yt;if(Object.keys(n).length===0)throw new SyntaxError("Unable to find the filter in \n"+JSON.stringify(r));return Object.keys(n).every(function(o){var i=n[o];if(i&&s.isString(i))return!1;if(!i||!s.isObject(i)||s.isEmptyObject(i))throw new SyntaxError("Invalid filter object for field ("+o+") in \n"+JSON.stringify(r));return Object.keys(i).every(function(a){var c=i[a];if(R[a])return R[a](o,e,c);throw new SyntaxError("Unable to find the filter ("+a+") for field ("+o+")in \n"+JSON.stringify(r))})})};var Xt={constraintProfile:function(e){return this.value("constraints.defaultProfile",e)},constraintProfiles:function(e){return this.value("defaultTreatmentProfiles",e)}};function Zt(t){var e=!0;return e&=s.isDefinedNonNull(t),e&&(e&=!s.isEmptyObject(t),e&=s.isFunction(t.initialized),e&=s.isFunction(t.value),e&=s.isFunction(t.constraintProfile)),e}function er(t){return s.isFunction(t.constraintProfile)&&s.isFunction(t.constraintProfiles)||s.attachMethods(t,Xt,t),t}var se=function(e,r){if(!Zt(e))throw new Error('The topic config is not a valid instance of "mt-client-config".');this._isInitialized=!1,this._topicConfig=e,this._constraintGenerator=null,this.system=new St,s.setDelegates(this.system,r||{})};se.prototype._getConstraintGenerator=function(){var e=this;return this._constraintGenerator?Promise.resolve(this._constraintGenerator):this._topicConfig.value("treatmentProfiles").then(function(r){return s.isDefinedNonNull(r)?e._constraintGenerator=new ie(e):e._constraintGenerator=new $(e),e._constraintGenerator})};se.prototype.constraintsForEvent=function(e,r){var n=this;return this._getConstraintGenerator().then(function(o){return o.constraintsForEvent(e,n._topicConfig,r)})};se.prototype.applyConstraintTreatments=function(e,r){var n=r?Promise.resolve(r):this.constraintsForEvent(e),o=this;return Promise.all([n,this._getConstraintGenerator()]).then(function(i){var a=i[0],c=i[1];return c.treatment.applyConstraints(e,a)}).catch(function(i){return o.system.logger.warn("An error occurred while applying constraints: "+i.message||i),null})};var ge,me;function ot(){return["app","appVersion","hardwareFamily","hardwareModel","os","osBuildNumber","osLanguages","osVersion","resourceRevNum","screenHeight","screenWidth","userAgent"]}function it(){return["delegateApp","hardwareBrand","storeFrontCountryCode","storeFrontHeader","storeFrontLanguage"]}function tr(){return["baseVersion","clientEventId","connection","eventTime","eventType","eventVersion","timezoneOffset","xpPostFrequency","xpSendMethod"]}function st(){return me||(me=ot().concat(it())),me}function rr(){return ge||(ge=st().concat(tr())),ge}var nr=s.attachDelegate,or=m.cryptoRandomBase62String,ae=m.exceptionString,Ce;function d(t){if(!s.isDefinedNonNull(t))throw new Error("A processor instance is required for creating BaseEventHandler.");this._processor=t,Ce||(Ce=!0,st().forEach(function(e){d.prototype[e]=function(r){var n;return r&&r.hasOwnProperty(e)?n=r[e]:n=this.environment()[e](),n}}))}d._className="eventHandlers.base";d.prototype.setDelegate=function(e){return nr(this,e)};d.prototype.environment=function(){throw ae(d._className,"environment")};d.prototype.eventRecorder=function(){throw ae(d._className,"eventRecorder")};d.prototype.metricsData=function(){throw ae(d._className,"metricsData")};d.prototype.processMetricsData=function(){throw ae(d._className,"processMetricsData")};d.prototype.knownFields=function(){return rr()};d.prototype.baseVersion=function(){return 1};d.prototype.clientEventId=function(e){return e&&e.clientEventId||or(!0)};d.prototype.connection=function(e){return e&&e.connection||this.environment().connectionType()};d.prototype.dsId=function(e){return e&&e.dsId||this.environment().dsId()};d.prototype.eventTime=function(e){return e&&e.eventTime||Date.now()};d.prototype.eventVersion=function(e){return e&&e.eventVersion||null};d.prototype.timezoneOffset=function(e){return e&&e.timezoneOffset||new Date().getTimezoneOffset()};d.prototype.xpPostFrequency=function(e){return e&&e.xpPostFrequency||this._processor.config.value("postFrequency")};d.prototype.xpSendMethod=function(t){return t&&t.xpSendMethod||this.eventRecorder().sendMethod()};var ir={Base:d},sr=s.attachDelegate,at=m.exceptionString,ar=S.localStorageObject,cr=S.sessionStorageObject,ke;function D(){ke||(ke=!0,ot().forEach(function(t){D.prototype[t]=function(){throw at(D._className,t)}}),it().forEach(function(t){D.prototype[t]=function(){}}))}D._className="system.environment";D.prototype.setDelegate=function(e){return sr(this,e)};D.prototype.connectionType=function(){throw at(D._className,"connectionType")};D.prototype.dsId=function(){};D.prototype.localStorageObject=ar;D.prototype.sessionStorageObject=cr;D.prototype.platformIdentifier=function(){};var pr={Environment:D},be={version:"8.6.3",name:"mt-metricskit-processor-clickstream"},ur={mtName:function(){return be.name},mtVersion:function(){return be.version}},T={attachDelegateInfo:function(t){s.extend(t,ur)}};function lr(t){er(t),T.attachDelegateInfo(t)}function fr(t){t.cleanup()}var hr=["constraintProfile","constraintProfiles","clientId","isSignedIn","page","pageContext","pageDetails","pageId","pageType","xpVersionMetricsKit","xpDelegatesInfo"],Le=["capacityData","capacityDataAvailable","capacityDisk","capacitySystem","capacitySystemAvailable","dsId","hostApp","pageUrl","pixelRatio","userType","windowInnerHeight","windowInnerWidth","windowOuterHeight","windowOuterWidth"],je=["browser","consumerId","consumerNs","hostAppVersion","parentPageUrl","userId","xpUserIdSyncState","xpAccountsMatch"],ce={METRICS_KIT_BASE_FIELDS:hr.concat(Le,je),IGNORED_BASE_FIELDS:["osLanguages"],REQUIRED_ENVIRONMENT_FIELD_NAMES:Le.concat("connectionType"),OPTIONAL_ENVIRONMENT_FIELD_NAMES:je.concat(["clientId","cookie","osLanguages"])},ct=pr.Environment,yr=m.exceptionString,vr=ce.REQUIRED_ENVIRONMENT_FIELD_NAMES,dr=ce.OPTIONAL_ENVIRONMENT_FIELD_NAMES,Be=!1,gr=function(){},Q=function t(){ct.apply(this,arguments),Be||(Be=!0,vr.forEach(function(e){t.prototype[e]=function(){throw yr("metrics.system.environment",e)}}),dr.forEach(function(e){t.prototype[e]=gr}))};Q.prototype=new ct;Q.prototype.constructor=Q;Q.prototype.setDelegate=function(e){return Ke.setDelegate(e),s.attachDelegate(this,e)};var Z=function(){};Z.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};Z.prototype.recordEvent=function(e,r){throw m.exceptionString("metrics.system.event_recorder","recordEvent")};Z.prototype.sendMethod=function(){throw m.exceptionString("metrics.system.event_recorder","sendMethod")};Z.prototype.flushUnreportedEvents=function(e){};var pt=Ue("mt-metricskit-processor-clickstream"),mr=function(){this.environment=new Q,this.eventRecorder=new Z,this.logger=pt;for(var e in this)T.attachDelegateInfo(this[e])},pe=function(e){this._processor=e.processor,this._eventMetricsDataPromise=e.eventMetricsDataPromise};pe.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};pe.prototype.toJSON=function(){return this._eventMetricsDataPromise.catch((function(e){return this._processor.system.logger.error("An error occurred when generating Metrics Data. Error: \n"+e),null}).bind(this))};pe.prototype.recordEvent=function(e){var r=Array.prototype.slice.call(arguments,1);return this._processor.system.eventRecorder.recordEvent.apply(this._processor.system.eventRecorder,[e,this.toJSON()].concat(r))};var ut=m.exceptionString,y=function(e){this._processor=e};y.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};y.prototype.knownFields=function(){throw ut("ClickStreamEventHandler","knownFields")};y.prototype.eventType=function(t){throw ut("ClickStreamEventHandler","eventType")};y.prototype.processMetricsData=function(e,r,n){var o=arguments,i=Array.prototype.slice.call(o,3),a=this.eventType(i),c=this._processor.config,p=this._processor._constraints,u=this._processor.system.logger,l=c.metricsDisabledOrBlacklistedEvent(a).then(function(f){if(f)throw"event was disabled"}).then((function(){var f=typeof this.mtIncludeBaseFields=="function"?this.mtIncludeBaseFields():!0,h=null;if(f){var v=this._processor.eventHandlers.base;h=v.metricsData.apply(v,o)}else h={};return h}).bind(this)).then((function(f){var h=[];i=[f].concat(i);var v=Ae.processMetricsData(this,this.knownFields(),!0,i),N={};return Object.keys(v).forEach(function(K){var ee=v[K],J=Promise.resolve(ee).then(function(ue){N[K]=ue});h.push(J)}),Promise.all(h).then(function(){return N})}).bind(this)).then(function(f){return p.applyConstraintTreatments(f)}).then(function(f){return c.removeBlacklistedFields(f)}).then(function(f){return c.applyDeRes(f)}).catch((function(f){return u.error("MetricsKit: Unable to generate the event ("+this.eventType(i)+") for the topic "+this._processor.config.topic()+", due to "+f),null}).bind(this));return new pe({processor:this._processor,eventMetricsDataPromise:l})};var F=function(t){y.apply(this,arguments)};F.prototype=Object.create(y.prototype);F.prototype.constructor=F;F.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};F.prototype.metricsData=function(t,e,r){return this.processMetricsData.apply(this,arguments)};F.prototype.knownFields=function(){var e=["eventType","eventVersion","type"];return e};F.prototype.eventType=function(t){return"account"};F.prototype.eventVersion=function(t){return t&&t.eventVersion||1};var lt=ce.METRICS_KIT_BASE_FIELDS,_e=ce.IGNORED_BASE_FIELDS,Pe=ir.Base,g=function(t){Pe.apply(this,arguments)};g.prototype=Object.create(Pe.prototype);g.prototype.constructor=g;g.prototype.environment=function(){return this._processor.system.environment};g.prototype.eventRecorder=function(){return this._processor.system.eventRecorder};g.prototype.knownFields=function(){var e=Pe.prototype.knownFields.call(this);return _e&&_e.length>0&&(e=e.slice(),_e.forEach(function(r){var n=e.indexOf(r);n>-1&&e.splice(n,1)})),e.concat(lt)};g.prototype.metricsData=function(e,r,n){var o={},i=[],a=Array.prototype.slice.call(arguments,3),c=this._processor.utils;return this._processor.config.value("metricsBase").then((function(p){p&&a.push(p);var u=c.eventFields.processMetricsData(this,this.knownFields(),e,r,n,a);return Object.keys(u).forEach(function(l){var f=u[l],h=Promise.resolve(f).then(function(v){o[l]=v});i.push(h)}),i}).bind(this)).then(function(p){return Promise.all(p).then(function(){return o})})};lt.forEach(function(t){g.prototype[t]=function(e){var r=this._processor.system.environment;return e&&e[t]||r[t]()}});g.prototype.constraintProfile=function(e){var r=this._processor.config;return e&&e.constraintProfile||r.constraintProfile()};g.prototype.constraintProfiles=function(e){var r=this._processor.config;return e&&e.constraintProfiles||r.constraintProfiles()};g.prototype.clientEventId=function(e){var r=e&&e.clientEventId;return r||(m.cryptoRandomBase62String&&(r=m.cryptoRandomBase62String(!0)),r||(r=m.uuid())),r};g.prototype.clientId=function(e){var r,n=this._processor.config;return e&&e.clientId?r=e.clientId:this._processor.system.environment.clientId()?r=this._processor.system.environment.clientId():r=n.value("ignoreClientIdCookie").then(function(o){if(!o)return Ke.get("xp_ci")}),r};g.prototype.isSignedIn=function(e){return e&&"isSignedIn"in e?e.isSignedIn:!!this.dsId(e)};g.prototype.page=function(e){if(e){if(e.page)return e.page;if(this.pageType(e)&&this.pageId(e)){var r=this._processor.config,n=this.pageType(e),o=this.pageId(e);return r.value("compoundSeparator").then(function(i){return n+i+o})}}else throw"No data provided to event_handlers/base page function"};g.prototype.pageContext=function(e){return e&&e.pageContext};g.prototype.pageDetails=function(e){return e&&e.pageDetails};g.prototype.pageId=function(e){return e&&e.pageId};g.prototype.pageType=function(e){return e&&e.pageType};g.prototype.xpViewablePercentage=function(e){var r=this._processor.config;return e&&e.xpViewablePercentage||r.value("impressions.viewablePercentage")};g.prototype.xpVersionMetricsKit=function(){return be.version};g.prototype.xpDelegatesInfo=function(){var e=mt.getStoredDelegateObject(this),r=e&&e.delegates;return r||void 0};var I=function(t){y.apply(this,arguments)};I.prototype=Object.create(y.prototype);I.prototype.constructor=I;I.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};I.prototype.metricsData=function(t,e,r){return this.processMetricsData.apply(this,arguments)};I.prototype.knownFields=function(){var e=["eventType","eventVersion"];return e};I.prototype.eventType=function(t){return"buyConfirmed"};I.prototype.eventVersion=function(t){return t&&t.eventVersion||1};I.prototype.createClientBuyId=function(){var t=null,e=this._processor.system.environment,r=e.sessionStorageObject().getItem("mtMetricsKit_previousClientBuyId");return t=++r,r||(this._processor.system.logger.warn("Metrics: buyConfirmed.createClientBuyId: clientBuyId did not exist or was of incorrect type, reset to 1."),t=1),e.sessionStorageObject().setItem("mtMetricsKit_previousClientBuyId",t),t};I.prototype.clientBuyIdQueryParamString=function(t){return"&clientBuyId="+t};I.prototype.metricsBuyParamsString=function(t,e,r,n){var o=this._processor.eventHandlers.base,i=this._processor.eventHandlers.page,a=Array.prototype.slice.call(arguments,4),c=i.pageHistory(),p=o.clientId(),u;return Array.isArray(c)?c.length>=2&&(u=c[c.length-2]):this._processor.system.logger.warn("MetricsKit: metricsBuyParamsString: pageHistory is not an Array"),Promise.resolve(p).then((function(l){var f={mtApp:o.app(a),mtEventTime:Date.now(),mtHardwareBrand:o.hardwareBrand(a),mtHardwareFamily:o.hardwareFamily(a),mtHardwareModel:o.hardwareModel(a),mtHostApp:o.hostApp(a),mtHostAppVersion:o.hostAppVersion(a),mtOs:o.os(a),mtOsBuildNumber:o.osBuildNumber(a),mtOsVersion:o.osVersion(a),mtPageId:t,mtPageType:e,mtPageContext:r,mtTopic:n||"xp_its_main",mtPrevPage:u,mtRequestId:m.uuid(),mtClientId:l};return s.extend.apply(s,[f].concat(a)),m.paramString(f)}).bind(this))};I.prototype.cacheMetricsBuyData=function(t,e){var r=this._processor.system.environment;if(arguments.length!=2)this._processor.system.logger.error("buyConfirmed.cacheMetricsBuyData(): function invoked with incorrect number of parameters. Perhaps you meant to retrieve cached data instead of setting it, which would be a call to uncacheMetricsBuyData(clientBuyId)?");else{var n=JSON.stringify(e);r.sessionStorageObject().setItem("mtMetricsKit_metricsBuyData_for_clientBuyId_"+t,n)}};I.prototype.uncacheMetricsBuyData=function(t){var e=null,r=this._processor.system.environment;if(arguments.length!=1)this._processor.system.logger.error("buyConfirmed.uncacheMetricsBuyData(): function invoked with incorrect number of parameters. Perhaps you meant to set cached data instead of retrieving it, which would be a call to cacheMetricsBuyData(clientBuyId, metricsBuyData)?");else{var n=r.sessionStorageObject().getItem("mtMetricsKit_metricsBuyData_for_clientBuyId_"+t);n&&(e=JSON.parse(n),r.sessionStorageObject().removeItem("mtMetricsKit_metricsBuyData_for_clientBuyId_"+t))}return e};I.prototype.buyFailureOccurred=function(t){var e=this.uncacheMetricsBuyData(t);e&&(e.detoured=!0,this.cacheMetricsBuyData(t,e))};var De=function(e){var r=null;try{r=JSON.parse(e)}catch(n){pt.error("MetricsKit: error parsing click data - "+n)}return r},E=function(t){y.apply(this,arguments)};E.prototype=Object.create(y.prototype);E.prototype.constructor=E;E.prototype.metricsData=function(t,e,r,n){var o=[t,e,r],i=this._processor.utils;return n&&(o.push({location:i.eventFields.buildLocationStructure(n,this.locationDataForElement)}),o.push(this.dataForElement(n)||{})),o=o.concat(Array.prototype.slice.call(arguments,4)),this.processMetricsData.apply(this,o)};E.prototype.knownFields=function(){var e=["actionContext","actionDetails","actionType","actionUrl","eventType","eventVersion","impressions","location","targetId","targetType","positionX","positionY","xpViewablePercentage"];return e};E.prototype.dataForElement=function(e){var r=null;if(e&&s.isFunction(e.hasAttribute)&&s.isFunction(e.getAttribute)){var n=this.dataAttribute();e.hasAttribute(n)&&(r=De(e.getAttribute(n)))}return r};E.prototype.dataAttribute=function(){return"data-metrics-click"};E.prototype.locationDataForElement=function(e){var r=e.parentNode,n=0,o=null,i,a,c,p;if(e.hasAttribute&&e.hasAttribute("data-metrics-location")&&(o=De(e.getAttribute("data-metrics-location")),o.locationType)){if(r){i=r.childNodes;for(var u=0;u<i.length;u++)if(a=typeof i.item=="function"&&i.item(u)||i[u],c=a.hasAttribute&&a.hasAttribute("data-metrics-location")?De(a.getAttribute("data-metrics-location")):void 0,p=c?c.locationType:void 0,p){if(a===e)break;n++}}o.locationPosition=n}return o};E.prototype.eventType=function(t){return"click"};E.prototype.eventVersion=function(t){return t&&t.eventVersion||4};E.prototype.impressions=function(e){return e?e.impressions:void 0};E.prototype.xpViewablePercentage=function(e){return this._processor.eventHandlers.base.xpViewablePercentage(e)};var M=function(t){y.apply(this,arguments)};M.prototype=Object.create(y.prototype);M.prototype.constructor=M;M.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};M.prototype.metricsData=function(t,e,r){return this.processMetricsData.apply(this,arguments)};M.prototype.knownFields=function(){var e=["buttons","code","details","message","type","eventType","eventVersion","type"];return e};M.prototype.eventType=function(t){return"dialog"};M.prototype.eventVersion=function(t){return t&&t.eventVersion||2};var O=function(t){y.apply(this,arguments)};O.prototype=Object.create(y.prototype);O.prototype.constructor=O;O.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};O.prototype.metricsData=function(t,e,r){return this.processMetricsData.apply(this,arguments)};O.prototype.knownFields=function(){var e=["eventType","eventVersion","extRefUrl","osLanguages","refApp","type"];return e};O.prototype.eventType=function(t){return"enter"};O.prototype.eventVersion=function(t){return t&&t.eventVersion||1};O.prototype.osLanguages=function(e){return e&&e.osLanguages||this._processor.system.environment.osLanguages()};var V=function(t){y.apply(this,arguments)};V.prototype=Object.create(y.prototype);V.prototype.constructor=V;V.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};V.prototype.metricsData=function(t,e,r){return this.processMetricsData.apply(this,arguments)};V.prototype.knownFields=function(){var e=["destinationUrl","eventType","eventVersion","type"];return e};V.prototype.eventType=function(t){return"exit"};V.prototype.eventVersion=function(t){return t&&t.eventVersion||1};var P=function(t){y.apply(this,arguments)};P.prototype=Object.create(y.prototype);P.prototype.constructor=P;P.prototype.metricsData=function(t){var e=[void 0,void 0,void 0];e.push({eventType:t});var r=Array.prototype.slice.call(arguments,1);return e=e.concat(r),this.processMetricsData.apply(this,e)};P.prototype.knownFields=function(){var e=["eventTime","eventType"];return e};P.prototype.mtIncludeBaseFields=function(){return!1};P.prototype.eventTime=function(e){return e&&e.eventTime||Date.now()};P.prototype.eventType=function(t){return t&&t.eventType||void 0};var A=function(t){y.apply(this,arguments)};A.prototype=Object.create(y.prototype);A.prototype.constructor=A;A.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};A.prototype.metricsData=function(t,e,r){return this.processMetricsData.apply(this,arguments)};A.prototype.knownFields=function(){var e=["eventType","eventVersion","impressions","xpViewablePercentage","xpViewableThreshold"];return e};A.prototype.eventType=function(t){return"impressions"};A.prototype.eventVersion=function(t){return t&&t.eventVersion||3};A.prototype.impressions=function(e){return e?e.impressions:void 0};A.prototype.xpViewablePercentage=function(e){var r=this._processor.eventHandlers.base;return r.xpViewablePercentage(e)};A.prototype.xpViewableThreshold=function(e){var r=this._processor.config;return e&&e.xpViewableThreshold||r.value("impressions.viewableThreshold")};var C=function(t){y.apply(this,arguments)};C.prototype=Object.create(y.prototype);C.prototype.constructor=C;C.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};C.prototype.metricsData=function(t,e,r){return this.processMetricsData.apply(this,arguments)};C.prototype.knownFields=function(){var e=["eventType","eventVersion","id","idType","type","typeDetails","actionType","actionDetails","url","duration","position"];return e};C.prototype.eventType=function(t){return"media"};C.prototype.eventVersion=function(t){return t&&t.eventVersion||1};var x=function(t){y.apply(this,arguments),this.pageHistoryCache=[]};x.prototype=Object.create(y.prototype);x.prototype.constructor=x;x.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};x.prototype.metricsData=function(t,e,r){return this.processMetricsData.apply(this,arguments)};x.prototype.knownFields=function(){var e=["eventType","eventVersion","extRefUrl","hostApp","refApp","refUrl","requestStartTime","responseStartTime","responseEndTime","pageHistory","pageLoadTime","pageRenderTime","searchFilters","searchTerm"];return e};x.prototype.eventType=function(t){return"page"};x.prototype.eventVersion=function(t){return t&&t.eventVersion||1};x.prototype.pageHistory=function(e){var r;if(e=e||{},e.pageHistory)r=e.pageHistory;else{r=this.pageHistoryCache.slice(0);var n=e.page;n&&(this.pageHistoryCache.length>=5&&this.pageHistoryCache.shift(),this.pageHistoryCache.push(n))}return r};var k=function(t){y.apply(this,arguments)};k.prototype=Object.create(y.prototype);k.prototype.constructor=k;k.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};k.prototype.metricsData=function(t,e,r){return this.processMetricsData.apply(this,arguments)};k.prototype.knownFields=function(){var e=["actionDetails","actionType","actionUrl","eventType","eventVersion","filters","location","targetId","targetType","term"];return e};k.prototype.eventType=function(t){return"search"};k.prototype.eventVersion=function(t){return t&&t.eventVersion||2};var L=function(t){y.apply(this,arguments)};L.prototype=Object.create(y.prototype);L.prototype.constructor=L;L.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};L.prototype.metricsData=function(e){var r=[null,null,null].concat(Array.prototype.slice.call(arguments));return this.processMetricsData.apply(this,r)};L.prototype.knownFields=function(){var e=["eventType","eventVersion"];return e};L.prototype.eventType=function(t){return"transaction"};L.prototype.eventVersion=function(t){return t&&t.eventVersion||1};var _r=function(t){this.account=new F(t),this.base=new g(t),this.buyConfirmed=new I(t),this.click=new E(t),this.dialog=new M(t),this.enter=new O(t),this.exit=new V(t),this.flexible=new P(t),this.impressions=new A(t),this.media=new C(t),this.page=new x(t),this.search=new k(t),this.transaction=new L(t),T.attachDelegateInfo(this.account),T.attachDelegateInfo(this.base),T.attachDelegateInfo(this.buyConfirmed),T.attachDelegateInfo(this.click),T.attachDelegateInfo(this.enter),T.attachDelegateInfo(this.exit),T.attachDelegateInfo(this.flexible),T.attachDelegateInfo(this.impressions),T.attachDelegateInfo(this.media),T.attachDelegateInfo(this.page),T.attachDelegateInfo(this.search),T.attachDelegateInfo(this.transaction)},Sr=function(t){var e={},r=[],n;if(t&&t[0]&&t[0].index!==void 0)for(var o=0;o<t.length;++o)n=t[o].index,e[n]||(e[n]=!0,r.push(t[o]));return r},z=function(t){this._processor=t};z.prototype.getIdType=function(t,e){var r=this._processor.config,n="its",o=t.indexOf("."),i=o!==-1?t.substring(0,o):n;return s.isString(e)?i+e+"id":r.value("compoundSeparator").then(function(a){return i+a+"id"})};z.prototype.processMetricsData=function(t,e,r,n,o,i){var a=[{pageId:r,pageType:n,pageContext:o}];return s.isArray(i)&&(a=a.concat(i)),Ae.processMetricsData(t,e,!0,a)};z.prototype.applyFieldsMap=function(t,e){var r=this._processor.config,n=this;return t&&e?r.value("fieldsMap").then(function(o){var i={};o=o||{};var a=re.valueForKeyPath(e,o,o.custom);if(a){var c;if(Array.isArray(a))for(c=0;c<a.length;++c)t[a[c]]&&(i[a[c]]=t[a[c]]);else if(typeof a=="object")for(var p in a)for(c=0;c<a[p].length;++c){var u=re.valueForKeyPath(a[p][c],t);if(u){i[p]=u;break}}else n._processor.system.logger.error("mt-metricskit-processor-clickstream: incorrect data type provided to applyFieldsMap (only accepts objects and Arrays)")}else n._processor.system.logger.error("mt-metricskit-processor-clickstream: unable to get fieldsMap from config-source");return i}):(t||this._processor.system.logger.error("mt-metricskit-processor-clickstream: No data provided to applyFieldsMap"),e||this._processor.system.logger.error("mt-metricskit-processor-clickstream: No sectionName provided to applyFieldsMap"),Promise.resolve(void 0))};z.prototype.flattenImpressions=function(t,e){var r=this._processor.config,n=(function o(i,a,c){var p=[],u,l,f,h,v=a||1;if(i){i=Sr(i);for(var N=0;N<i.length;N++){if(u=i[N],typeof u.data=="string")try{l=JSON.parse(u.data)}catch(K){h=decodeURIComponent(u.data);try{l=JSON.parse(h)}catch(ee){this._processor.system.logger.error("mt-metricskit-processor-clickstream: non-JSON serialized data found on impression object. Cannot parse.",K)}}else l=u;l&&(l.impressionTimes=u.timestamps,l.impressionIndex=u.index,l.id&&!l.idType&&(u.kind==="genre"?l.idType="label"+c+"id":l.idType=this.getIdType(l.id.toString(),c)),u.parent&&u.parent.impressionId!==void 0&&(l.impressionParentId=u.parent.impressionId),l.impressionId=v,u.impressionId=v,++v,p.push(l),re.valueForKeyPath("children.length",u)>0&&(f=o(u.children,v,c),p=p.concat(f),v+=f.length))}}else this._processor.system.logger.warn("Fuse-Metrics: No impressions provided to to flattenImpressions");return p}).bind(this);return r.value("compoundSeparator").then(function(o){return n(t,e,o)})};z.prototype.buildLocationStructure=function(e,r){for(var n=e,o=[],i;n;)i=r.call(r,n),i&&o.push(i),n=n.parentNode;return o};var xe=function(){};xe.prototype.setDelegate=function(e){return s.attachDelegate(this,e)};xe.prototype.makeAjaxRequest=_t.makeAjaxRequest;var He={attachDelegate:function(e,r){return s.attachDelegate(e,r)},extend:function(e){return s.extend.apply(s,arguments)},bindFunctionsContext:function(e){if(e)for(var r in e)typeof e[r]=="function"&&(e[r]=e[r].bind(e))}},Tr={versionStringFromUserAgent:function(e,r){return m.versionStringFromUserAgent(e,r)}},Ir=function(e){this.delegateExtension=T,this.eventFields=new z(e),He.bindFunctionsContext(this.eventFields),this.keyValue=re,this.network=new xe,this.reflect=He,this.string=Tr},ft=function(t){this._eventHandler=new P(t)};ft.prototype.clientId=function(e){return this._eventHandler.metricsData("",e).toJSON().then(function(r){return r?r.clientId:null})};var Er=function(t){this.base=new ft(t)},ht=function(e){if(!s.isDefinedNonNull(e))throw new Error("No delegate is provided to ClickstreamProcessor");this._initCalled=!1,this._delegatePackage=e,this.system=new mr,this.config=this._delegatePackage.config,this.eventHandlers=new _r(this),this.eventFields=new Er(this),this.utils=new Ir(this),this._constraints=null};ht.prototype.init=function(){var e=Promise.resolve();return this._initCalled||(this._initCalled=!0,this._delegatePackage&&(s.setDelegates(this.eventHandlers,this._delegatePackage),s.setDelegates(this.system,this._delegatePackage),s.setDelegates(this.utils,this._delegatePackage)),lr(this.config),e=this._delegatePackage.init(),this._constraints=new se(this.config,{environment:this.system.environment})),e};ht.prototype.cleanup=function(){this._delegatePackage&&s.isFunction(this._delegatePackage.cleanup)&&this._delegatePackage.cleanup(),fr(this.config),s.resetDelegates(this.eventHandlers),s.resetDelegates(this.system),s.resetDelegates(this.utils),this.config=null,this.system=null,this.eventHandlers=null,this.utils=null,this._delegatePackage=null,this._constraints=null,this._initCalled=!1};export{ht as ClickstreamProcessor};
|
|
//# sourceMappingURL=mt-metricskit-processor-clickstream.esm~BRd_H7lt9Y.js.map
|