UNPKG

@optimizely/optimizely-sdk

Version:
1 lines 60.7 kB
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@optimizely/js-sdk-logging"),r=require("@optimizely/js-sdk-utils"),i=require("@optimizely/js-sdk-datafile-manager"),n=e(require("murmurhash")),o=require("@optimizely/js-sdk-event-processor"),a=e(require("http")),s=e(require("https")),l=e(require("url")),u=Math.pow(2,53);function E(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(!e)return{};if("function"==typeof Object.assign)return Object.assign.apply(Object,[e].concat(t));for(var i=Object(e),n=0;n<t.length;n++){var o=t[n];if(null!=o)for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(i[a]=o[a])}return i}function _(){return Math.round((new Date).getTime())}function f(e){return"number"==typeof e&&Math.abs(e)<=u}function I(e,t){return e?r.keyBy(e,(function(e){return e[t]})):{}}function g(e){return"number"==typeof e}var c={NOTSET:0,DEBUG:1,INFO:2,WARNING:3,ERROR:4},p={CONDITION_EVALUATOR_ERROR:"%s: Error evaluating audience condition of type %s: %s",DATAFILE_AND_SDK_KEY_MISSING:"%s: You must provide at least one of sdkKey or datafile. Cannot start Optimizely",EXPERIMENT_KEY_NOT_IN_DATAFILE:"%s: Experiment key %s is not in datafile.",FEATURE_NOT_IN_DATAFILE:"%s: Feature key %s is not in datafile.",IMPROPERLY_FORMATTED_EXPERIMENT:"%s: Experiment key %s is improperly formatted.",INVALID_ATTRIBUTES:"%s: Provided attributes are in an invalid format.",INVALID_BUCKETING_ID:"%s: Unable to generate hash for bucketing ID %s: %s",INVALID_DATAFILE:"%s: Datafile is invalid - property %s: %s",INVALID_DATAFILE_MALFORMED:"%s: Datafile is invalid because it is malformed.",INVALID_CONFIG:"%s: Provided Optimizely config is in an invalid format.",INVALID_JSON:"%s: JSON object is not valid.",INVALID_ERROR_HANDLER:'%s: Provided "errorHandler" is in an invalid format.',INVALID_EVENT_DISPATCHER:'%s: Provided "eventDispatcher" is in an invalid format.',INVALID_EVENT_TAGS:"%s: Provided event tags are in an invalid format.",INVALID_EXPERIMENT_KEY:"%s: Experiment key %s is not in datafile. It is either invalid, paused, or archived.",INVALID_EXPERIMENT_ID:"%s: Experiment ID %s is not in datafile.",INVALID_GROUP_ID:"%s: Group ID %s is not in datafile.",INVALID_LOGGER:'%s: Provided "logger" is in an invalid format.',INVALID_ROLLOUT_ID:"%s: Invalid rollout ID %s attached to feature %s",INVALID_USER_ID:"%s: Provided user ID is in an invalid format.",INVALID_USER_PROFILE_SERVICE:"%s: Provided user profile service instance is in an invalid format: %s.",NO_DATAFILE_SPECIFIED:"%s: No datafile specified. Cannot start optimizely.",NO_JSON_PROVIDED:"%s: No JSON object to validate against schema.",NO_VARIATION_FOR_EXPERIMENT_KEY:"%s: No variation key %s defined in datafile for experiment %s.",UNDEFINED_ATTRIBUTE:"%s: Provided attribute: %s has an undefined value.",UNRECOGNIZED_ATTRIBUTE:"%s: Unrecognized attribute %s provided. Pruning before sending event to Optimizely.",UNABLE_TO_CAST_VALUE:"%s: Unable to cast value %s to type %s, returning null.",USER_NOT_IN_FORCED_VARIATION:"%s: User %s is not in the forced variation map. Cannot remove their forced variation.",USER_PROFILE_LOOKUP_ERROR:'%s: Error while looking up user profile for user ID "%s": %s.',USER_PROFILE_SAVE_ERROR:'%s: Error while saving user profile for user ID "%s": %s.',VARIABLE_KEY_NOT_IN_DATAFILE:'%s: Variable with key "%s" associated with feature with key "%s" is not in datafile.',VARIATION_ID_NOT_IN_DATAFILE:"%s: No variation ID %s defined in datafile for experiment %s.",VARIATION_ID_NOT_IN_DATAFILE_NO_EXPERIMENT:"%s: Variation ID %s is not in the datafile.",INVALID_INPUT_FORMAT:"%s: Provided %s is in an invalid format.",INVALID_DATAFILE_VERSION:"%s: This version of the JavaScript SDK does not support the given datafile version: %s",INVALID_VARIATION_KEY:"%s: Provided variation key is in an invalid format."},d={ACTIVATE_USER:"%s: Activating user %s in experiment %s.",DISPATCH_CONVERSION_EVENT:"%s: Dispatching conversion event to URL %s with params %s.",DISPATCH_IMPRESSION_EVENT:"%s: Dispatching impression event to URL %s with params %s.",DEPRECATED_EVENT_VALUE:"%s: Event value is deprecated in %s call.",EVENT_KEY_NOT_FOUND:"%s: Event key %s is not in datafile.",EXPERIMENT_NOT_RUNNING:"%s: Experiment %s is not running.",FEATURE_ENABLED_FOR_USER:"%s: Feature %s is enabled for user %s.",FEATURE_NOT_ENABLED_FOR_USER:"%s: Feature %s is not enabled for user %s.",FEATURE_HAS_NO_EXPERIMENTS:"%s: Feature %s is not attached to any experiments.",FAILED_TO_PARSE_VALUE:'%s: Failed to parse event value "%s" from event tags.',FAILED_TO_PARSE_REVENUE:'%s: Failed to parse revenue value "%s" from event tags.',FORCED_BUCKETING_FAILED:"%s: Variation key %s is not in datafile. Not activating user %s.",INVALID_OBJECT:"%s: Optimizely object is not valid. Failing %s.",INVALID_CLIENT_ENGINE:"%s: Invalid client engine passed: %s. Defaulting to node-sdk.",INVALID_VARIATION_ID:"%s: Bucketed into an invalid variation ID. Returning null.",NOTIFICATION_LISTENER_EXCEPTION:"%s: Notification listener for (%s) threw exception: %s",NO_ROLLOUT_EXISTS:"%s: There is no rollout of feature %s.",NOT_ACTIVATING_USER:"%s: Not activating user %s for experiment %s.",NOT_TRACKING_USER:"%s: Not tracking user %s.",PARSED_REVENUE_VALUE:'%s: Parsed revenue value "%s" from event tags.',PARSED_NUMERIC_VALUE:'%s: Parsed event value "%s" from event tags.',RETURNING_STORED_VARIATION:'%s: Returning previously activated variation "%s" of experiment "%s" for user "%s" from user profile.',ROLLOUT_HAS_NO_EXPERIMENTS:"%s: Rollout of feature %s has no experiments",SAVED_VARIATION:'%s: Saved variation "%s" of experiment "%s" for user "%s".',SAVED_VARIATION_NOT_FOUND:"%s: User %s was previously bucketed into variation with ID %s for experiment %s, but no matching variation was found.",SHOULD_NOT_DISPATCH_ACTIVATE:'%s: Experiment %s is not in "Running" state. Not activating user.',SKIPPING_JSON_VALIDATION:"%s: Skipping JSON schema validation.",TRACK_EVENT:"%s: Tracking event %s for user %s.",USER_ASSIGNED_TO_EXPERIMENT_BUCKET:"%s: Assigned bucket %s to user with bucketing ID %s.",USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP:"%s: User %s is in experiment %s of group %s.",USER_BUCKETED_INTO_TARGETING_RULE:"%s: User %s bucketed into targeting rule %s.",USER_IN_FEATURE_EXPERIMENT:"%s: User %s is in variation %s of experiment %s on the feature %s.",USER_IN_ROLLOUT:"%s: User %s is in rollout of feature %s.",USER_BUCKETED_INTO_EVERYONE_TARGETING_RULE:"%s: User %s bucketed into everyone targeting rule.",USER_NOT_BUCKETED_INTO_EVERYONE_TARGETING_RULE:"%s: User %s not bucketed into everyone targeting rule due to traffic allocation.",USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP:"%s: User %s is not in experiment %s of group %s.",USER_NOT_BUCKETED_INTO_ANY_EXPERIMENT_IN_GROUP:"%s: User %s is not in any experiment of group %s.",USER_NOT_BUCKETED_INTO_TARGETING_RULE:"%s User %s not bucketed into targeting rule %s due to traffic allocation. Trying everyone rule.",USER_NOT_IN_FEATURE_EXPERIMENT:"%s: User %s is not in any experiment on the feature %s.",USER_NOT_IN_ROLLOUT:"%s: User %s is not in rollout of feature %s.",USER_FORCED_IN_VARIATION:"%s: User %s is forced in variation %s.",USER_MAPPED_TO_FORCED_VARIATION:"%s: Set variation %s for experiment %s and user %s in the forced variation map.",USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE:"%s: User %s does not meet conditions for targeting rule %s.",USER_MEETS_CONDITIONS_FOR_TARGETING_RULE:"%s: User %s meets conditions for targeting rule %s.",USER_HAS_VARIATION:"%s: User %s is in variation %s of experiment %s.",USER_HAS_FORCED_VARIATION:"%s: Variation %s is mapped to experiment %s and user %s in the forced variation map.",USER_HAS_NO_VARIATION:"%s: User %s is in no variation of experiment %s.",USER_HAS_NO_FORCED_VARIATION:"%s: User %s is not in the forced variation map.",USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT:"%s: No experiment %s mapped to user %s in the forced variation map.",USER_NOT_IN_ANY_EXPERIMENT:"%s: User %s is not in any experiment of group %s.",USER_NOT_IN_EXPERIMENT:"%s: User %s does not meet conditions to be in experiment %s.",USER_RECEIVED_DEFAULT_VARIABLE_VALUE:'%s: User "%s" is not in any variation or rollout rule. Returning default value for variable "%s" of feature flag "%s".',FEATURE_NOT_ENABLED_RETURN_DEFAULT_VARIABLE_VALUE:'%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".',VARIABLE_NOT_USED_RETURN_DEFAULT_VARIABLE_VALUE:'%s: Variable "%s" is not used in variation "%s". Returning default value.',USER_RECEIVED_VARIABLE_VALUE:'%s: Got variable value "%s" for variable "%s" of feature flag "%s"',VALID_DATAFILE:"%s: Datafile is valid.",VALID_USER_PROFILE_SERVICE:"%s: Valid user profile service provided.",VARIATION_REMOVED_FOR_USER:"%s: Variation mapped to experiment %s has been removed for user %s.",VARIABLE_REQUESTED_WITH_WRONG_TYPE:'%s: Requested variable type "%s", but variable is of type "%s". Use correct API to retrieve value. Returning None.',VALID_BUCKETING_ID:'%s: BucketingId is valid: "%s"',BUCKETING_ID_NOT_STRING:"%s: BucketingID attribute is not a string. Defaulted to userId",EVALUATING_AUDIENCE:'%s: Starting to evaluate audience "%s" with conditions: %s.',EVALUATING_AUDIENCES_COMBINED:'%s: Evaluating audiences for %s "%s": %s.',AUDIENCE_EVALUATION_RESULT:'%s: Audience "%s" evaluated to %s.',AUDIENCE_EVALUATION_RESULT_COMBINED:"%s: Audiences for %s %s collectively evaluated to %s.",MISSING_ATTRIBUTE_VALUE:'%s: Audience condition %s evaluated to UNKNOWN because no value was passed for user attribute "%s".',UNEXPECTED_CONDITION_VALUE:"%s: Audience condition %s evaluated to UNKNOWN because the condition value is not supported.",UNEXPECTED_TYPE:'%s: Audience condition %s evaluated to UNKNOWN because a value of type "%s" was passed for user attribute "%s".',UNEXPECTED_TYPE_NULL:'%s: Audience condition %s evaluated to UNKNOWN because a null value was passed for user attribute "%s".',UNKNOWN_CONDITION_TYPE:"%s: Audience condition %s has an unknown condition type. You may need to upgrade to a newer release of the Optimizely SDK.",UNKNOWN_MATCH_TYPE:"%s: Audience condition %s uses an unknown match type. You may need to upgrade to a newer release of the Optimizely SDK.",UPDATED_OPTIMIZELY_CONFIG:"%s: Updated Optimizely config to revision %s (project id %s)",OUT_OF_BOUNDS:'%s: Audience condition %s evaluated to UNKNOWN because the number value for user attribute "%s" is not in the range [-2^53, +2^53].',UNABLE_TO_ATTACH_UNLOAD:'%s: unable to bind optimizely.close() to page unload event: "%s"'},N={REVENUE:"revenue",VALUE:"value"},R={BOT_FILTERING:"$opt_bot_filtering",BUCKETING_ID:"$opt_bucketing_id",STICKY_BUCKETING_KEY:"$opt_experiment_bucket_map",USER_AGENT:"$opt_user_agent"},O=["node-sdk","react-sdk","javascript-sdk"],T=r.NOTIFICATION_TYPES,h={AB_TEST:"ab-test",FEATURE:"feature",FEATURE_TEST:"feature-test",FEATURE_VARIABLE:"feature-variable",ALL_FEATURE_VARIABLES:"all-feature-variables"},v={FEATURE_TEST:"feature-test",ROLLOUT:"rollout"},A={RULE:"rule",EXPERIMENT:"experiment"},y={BOOLEAN:"boolean",DOUBLE:"double",INTEGER:"integer",STRING:"string",JSON:"json"},U={V2:"2",V3:"3",V4:"4"},L=Object.freeze({__proto__:null,LOG_LEVEL:c,ERROR_MESSAGES:p,LOG_MESSAGES:d,RESERVED_EVENT_KEYWORDS:N,CONTROL_ATTRIBUTES:R,JAVASCRIPT_CLIENT_ENGINE:"javascript-sdk",NODE_CLIENT_ENGINE:"node-sdk",REACT_CLIENT_ENGINE:"react-sdk",NODE_CLIENT_VERSION:"4.3.4",VALID_CLIENT_ENGINES:O,NOTIFICATION_TYPES:T,DECISION_NOTIFICATION_TYPES:h,DECISION_SOURCES:v,AUDIENCE_EVALUATION_TYPES:A,FEATURE_VARIABLE_TYPES:y,DATAFILE_VERSIONS:U}),V="CONFIG_VALIDATOR",D=[U.V2,U.V3,U.V4],m=function(e){if("object"==typeof e&&null!==e){if(e.errorHandler&&"function"!=typeof e.errorHandler.handleError)throw new Error(r.sprintf(p.INVALID_ERROR_HANDLER,V));if(e.eventDispatcher&&"function"!=typeof e.eventDispatcher.dispatchEvent)throw new Error(r.sprintf(p.INVALID_EVENT_DISPATCHER,V));if(e.logger&&"function"!=typeof e.logger.log)throw new Error(r.sprintf(p.INVALID_LOGGER,V));return!0}throw new Error(r.sprintf(p.INVALID_CONFIG,V))},S=function(e){if(!e)throw new Error(r.sprintf(p.NO_DATAFILE_SPECIFIED,V));if("string"==typeof e)try{e=JSON.parse(e)}catch(e){throw new Error(r.sprintf(p.INVALID_DATAFILE_MALFORMED,V))}if("object"==typeof e&&!Array.isArray(e)&&null!==e&&-1===D.indexOf(e.version))throw new Error(r.sprintf(p.INVALID_DATAFILE_VERSION,V,e.version));return e},C="PROJECT_CONFIG";var P=function(e,t){void 0===t&&(t=null);var i,n,o=((n=E({},i=e)).audiences=(i.audiences||[]).map((function(e){return E({},e)})),n.experiments=(i.experiments||[]).map((function(e){return E({},e)})),n.featureFlags=(i.featureFlags||[]).map((function(e){return E({},e)})),n.groups=(i.groups||[]).map((function(e){var t=E({},e);return t.experiments=(e.experiments||[]).map((function(e){return E({},e)})),t})),n.rollouts=(i.rollouts||[]).map((function(e){var t=E({},e);return t.experiments=(e.experiments||[]).map((function(e){return E({},e)})),t})),n);return o.__datafileStr=null===t?JSON.stringify(e):t,(o.audiences||[]).forEach((function(e){e.conditions=JSON.parse(e.conditions)})),o.audiencesById=I(o.audiences,"id"),E(o.audiencesById,I(o.typedAudiences,"id")),o.attributeKeyMap=I(o.attributes,"key"),o.eventKeyMap=I(o.events,"key"),o.groupIdMap=I(o.groups,"id"),Object.keys(o.groupIdMap||{}).forEach((function(e){(o.groupIdMap[e].experiments||[]).forEach((function(t){o.experiments.push(E(t,{groupId:e}))}))})),o.rolloutIdMap=I(o.rollouts||[],"id"),r.objectValues(o.rolloutIdMap||{}).forEach((function(e){(e.experiments||[]).forEach((function(e){o.experiments.push(e),e.variationKeyMap=I(e.variations,"key")}))})),o.experimentKeyMap=I(o.experiments,"key"),o.experimentIdMap=I(o.experiments,"id"),o.variationIdMap={},o.variationVariableUsageMap={},(o.experiments||[]).forEach((function(e){e.variationKeyMap=I(e.variations,"key"),E(o.variationIdMap,I(e.variations,"id")),r.objectValues(e.variationKeyMap||{}).forEach((function(e){e.variables&&(o.variationVariableUsageMap[e.id]=I(e.variables,"id"))}))})),o.experimentFeatureMap={},o.featureKeyMap=I(o.featureFlags||[],"key"),r.objectValues(o.featureKeyMap||{}).forEach((function(e){e.variables.forEach((function(e){e.type===y.STRING&&e.subType===y.JSON&&(e.type=y.JSON,delete e.subType)})),e.variableKeyMap=I(e.variables,"key"),(e.experimentIds||[]).forEach((function(t){o.experimentFeatureMap[t]?o.experimentFeatureMap[t].push(e.id):o.experimentFeatureMap[t]=[e.id];var r=o.experimentIdMap[t];r.groupId&&!e.groupId&&(e.groupId=r.groupId)}))})),o},b=function(e,t){var i=e.experimentKeyMap[t];if(!i)throw new Error(r.sprintf(p.INVALID_EXPERIMENT_KEY,C,t));return i.id},F=function(e,t){var i=e.experimentKeyMap[t];if(!i)throw new Error(r.sprintf(p.INVALID_EXPERIMENT_KEY,C,t));return i.status},M=function(e,t){return"Running"===F(e,t)},k=function(e,t,r){var i=e.experimentKeyMap[t];return i.variationKeyMap.hasOwnProperty(r)?i.variationKeyMap[r].id:null},x=function(e,t,i){if(e.featureKeyMap.hasOwnProperty(t)){var n=e.featureKeyMap[t];if(n)return n}return i.log(c.ERROR,r.sprintf(p.FEATURE_NOT_IN_DATAFILE,C,t)),null},B=function(e,t,i,n){var o=e.featureKeyMap[t];if(!o)return n.log(c.ERROR,r.sprintf(p.FEATURE_NOT_IN_DATAFILE,C,t)),null;var a=o.variableKeyMap[i];return a||(n.log(c.ERROR,r.sprintf(p.VARIABLE_KEY_NOT_IN_DATAFILE,C,i,t)),null)},K=function(e,t,i,n){if(!t||!i)return null;if(!e.variationVariableUsageMap.hasOwnProperty(i.id))return n.log(c.ERROR,r.sprintf(p.VARIATION_ID_NOT_IN_DATAFILE_NO_EXPERIMENT,C,i.id)),null;var o=e.variationVariableUsageMap[i.id][t.id];return o?o.value:null},G=function(e,t,i){var n;switch(t){case y.BOOLEAN:"true"!==e&&"false"!==e?(i.log(c.ERROR,r.sprintf(p.UNABLE_TO_CAST_VALUE,C,e,t)),n=null):n="true"===e;break;case y.INTEGER:n=parseInt(e,10),isNaN(n)&&(i.log(c.ERROR,r.sprintf(p.UNABLE_TO_CAST_VALUE,C,e,t)),n=null);break;case y.DOUBLE:n=parseFloat(e),isNaN(n)&&(i.log(c.ERROR,r.sprintf(p.UNABLE_TO_CAST_VALUE,C,e,t)),n=null);break;case y.JSON:try{n=JSON.parse(e)}catch(o){i.log(c.ERROR,r.sprintf(p.UNABLE_TO_CAST_VALUE,C,e,t)),n=null}break;default:n=e}return n},w=function(e,t){return e.eventKeyMap.hasOwnProperty(t)},j=function(e,t){return e.experimentFeatureMap.hasOwnProperty(t)},Y=b,H=function(e,t){var i=e.experimentIdMap[t];if(!i)throw new Error(r.sprintf(p.INVALID_EXPERIMENT_ID,C,t));return i.layerId},X=function(e,t,i){var n=e.attributeKeyMap[t],o=0===t.indexOf("$opt_");return n?(o&&i.log(c.WARN,r.sprintf("Attribute %s unexpectedly has reserved prefix %s; using attribute ID instead of reserved attribute name.",t,"$opt_")),n.id):o?t:(i.log(c.DEBUG,r.sprintf(p.UNRECOGNIZED_ATTRIBUTE,C,t)),null)},J=function(e,t){var r=e.eventKeyMap[t];return r?r.id:null},z=function(e,t){return"Running"===F(e,t)},Z=function(e,t){var i=e.experimentKeyMap[t];if(!i)throw new Error(r.sprintf(p.INVALID_EXPERIMENT_KEY,C,t));return i.audienceConditions||i.audienceIds},W=function(e,t){return e.variationIdMap.hasOwnProperty(t)?e.variationIdMap[t].key:null},q=k,$=function(e,t){if(e.experimentKeyMap.hasOwnProperty(t)){var i=e.experimentKeyMap[t];if(i)return i}throw new Error(r.sprintf(p.EXPERIMENT_KEY_NOT_IN_DATAFILE,C,t))},Q=function(e,t){var i=e.experimentKeyMap[t];if(!i)throw new Error(r.sprintf(p.INVALID_EXPERIMENT_KEY,C,t));return i.trafficAllocation},ee=function(e,t,i){if(e.experimentIdMap.hasOwnProperty(t)){var n=e.experimentIdMap[t];if(n)return n}return i.log(c.ERROR,r.sprintf(p.INVALID_EXPERIMENT_ID,C,t)),null},te=function(e){return e.audiencesById},re=function(e){return e.__datafileStr},ie=function(e){var t;try{t=S(e.datafile)}catch(e){return{configObj:null,error:e}}if(e.jsonSchemaValidator)try{e.jsonSchemaValidator.validate(t),e.logger.log(c.INFO,r.sprintf(d.VALID_DATAFILE,C))}catch(e){return{configObj:null,error:e}}else e.logger.log(c.INFO,r.sprintf(d.SKIPPING_JSON_VALIDATION,C));var i=[t];return"string"==typeof e.datafile&&i.push(e.datafile),{configObj:P.apply(void 0,i),error:null}};function ne(e,t,r,i){var n=e.experimentFeatureMap[r],o={};if(n){var a=i[n],s=(t.variables||[]).reduce((function(e,t){return e[t.id]={id:t.id,value:t.value},e}),{});o=(a||[]).reduce((function(e,r){var i=s[r.id],n=t.featureEnabled&&i?i.value:r.defaultValue;return e[r.key]={id:r.id,key:r.key,type:r.type,value:n},e}),{})}return o}function oe(e,t){this.experimentsMap=function(e){var t=(e.rollouts||[]).reduce((function(e,t){return t.experiments.forEach((function(t){e[t.id]=!0})),e}),{}),r=(e.featureFlags||[]).reduce((function(e,t){return e[t.id]=t.variables,e}),{});return(e.experiments||[]).reduce((function(i,n){return t[n.id]||(i[n.key]={id:n.id,key:n.key,variationsMap:(n.variations||[]).reduce((function(t,i){return t[i.key]={id:i.id,key:i.key,variablesMap:ne(e,i,n.id,r)},j(e,n.id)&&(t[i.key].featureEnabled=i.featureEnabled),t}),{})}),i}),{})}(e),this.featuresMap=function(e,t){return(e.featureFlags||[]).reduce((function(r,i){return r[i.key]={id:i.id,key:i.key,experimentsMap:(i.experimentIds||[]).reduce((function(r,i){var n=e.experimentIdMap[i].key;return r[n]=t[n],r}),{}),variablesMap:(i.variables||[]).reduce((function(e,t){return e[t.key]={id:t.id,key:t.key,type:t.type,value:t.defaultValue},e}),{})},r}),{})}(e,this.experimentsMap),this.revision=e.revision,this.__datafile=t}oe.prototype.getDatafile=function(){return this.__datafile};var ae={OptimizelyConfig:oe},se=t.getLogger();function le(e,t){return e instanceof Error?e.message:t||"Unknown error"}function ue(e){try{this.__initialize(e)}catch(e){se.error(e),this.__updateListeners=[],this.__configObj=null,this.__optimizelyConfigObj=null,this.__readyPromise=Promise.resolve({success:!1,reason:le(e,"Error in initialize")})}}ue.prototype.__initialize=function(e){if(this.__updateListeners=[],this.jsonSchemaValidator=e.jsonSchemaValidator,!e.datafile&&!e.sdkKey){this.__configObj=null;var t=new Error(r.sprintf(p.DATAFILE_AND_SDK_KEY_MISSING,"PROJECT_CONFIG_MANAGER"));return this.__readyPromise=Promise.resolve({success:!1,reason:le(t)}),void se.error(t)}var n;if(e.datafile?(n=this.__handleNewDatafile(e.datafile))&&(this.__configObj=null):this.__configObj=null,e.sdkKey){var o={sdkKey:e.sdkKey};this.__validateDatafileOptions(e.datafileOptions)&&E(o,e.datafileOptions),this.__configObj&&(o.datafile=re(this.__configObj)),this.datafileManager=new i.HttpPollingDatafileManager(o),this.datafileManager.start(),this.__readyPromise=this.datafileManager.onReady().then(this.__onDatafileManagerReadyFulfill.bind(this),this.__onDatafileManagerReadyReject.bind(this)),this.datafileManager.on("update",this.__onDatafileManagerUpdate.bind(this))}else this.__configObj?this.__readyPromise=Promise.resolve({success:!0}):this.__readyPromise=Promise.resolve({success:!1,reason:le(n,"Invalid datafile")})},ue.prototype.__onDatafileManagerReadyFulfill=function(){var e=this.__handleNewDatafile(this.datafileManager.get());return e?{success:!1,reason:le(e)}:{success:!0}},ue.prototype.__onDatafileManagerReadyReject=function(e){return{success:!1,reason:le(e,"Failed to become ready")}},ue.prototype.__onDatafileManagerUpdate=function(){this.__handleNewDatafile(this.datafileManager.get())},ue.prototype.__validateDatafileOptions=function(e){return void 0===e||"object"==typeof e&&null!==e},ue.prototype.__handleNewDatafile=function(e){var t=ie({datafile:e,jsonSchemaValidator:this.jsonSchemaValidator,logger:se}),r=t.configObj,i=t.error;i?se.error(i):(this.__configObj?this.__configObj.revision:"null")!==r.revision&&(this.__configObj=r,this.__optimizelyConfigObj=new ae.OptimizelyConfig(this.__configObj,re(this.__configObj)),this.__updateListeners.forEach((function(e){e(r)})));return i},ue.prototype.getConfig=function(){return this.__configObj},ue.prototype.getOptimizelyConfig=function(){return this.__optimizelyConfigObj},ue.prototype.onReady=function(){return this.__readyPromise},ue.prototype.onUpdate=function(e){return this.__updateListeners.push(e),function(){var t=this.__updateListeners.indexOf(e);t>-1&&this.__updateListeners.splice(t,1)}.bind(this)},ue.prototype.stop=function(){this.datafileManager&&this.datafileManager.stop(),this.__updateListeners=[]};function Ee(e){this.logger=e.logger,this.errorHandler=e.errorHandler,this.__notificationListeners={},r.objectValues(T).forEach(function(e){this.__notificationListeners[e]=[]}.bind(this)),this.__listenerId=1}Ee.prototype.addNotificationListener=function(e,t){try{if(!(r.objectValues(T).indexOf(e)>-1))return-1;this.__notificationListeners[e]||(this.__notificationListeners[e]=[]);var i=!1;if((this.__notificationListeners[e]||[]).forEach((function(e){if(e.callback===t)return i=!0,!1})),i)return-1;this.__notificationListeners[e].push({id:this.__listenerId,callback:t});var n=this.__listenerId;return this.__listenerId+=1,n}catch(e){return this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e),-1}},Ee.prototype.removeNotificationListener=function(e){try{var t,r;if(Object.keys(this.__notificationListeners).some(function(i){if((this.__notificationListeners[i]||[]).every((function(n,o){return n.id!==e||(t=o,r=i,!1)})),void 0!==t&&void 0!==r)return!0}.bind(this)),void 0!==t&&void 0!==r)return this.__notificationListeners[r].splice(t,1),!0}catch(e){this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e)}return!1},Ee.prototype.clearAllNotificationListeners=function(){try{r.objectValues(T).forEach(function(e){this.__notificationListeners[e]=[]}.bind(this))}catch(e){this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e)}},Ee.prototype.clearNotificationListeners=function(e){try{this.__notificationListeners[e]=[]}catch(e){this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e)}},Ee.prototype.sendNotifications=function(e,t){try{(this.__notificationListeners[e]||[]).forEach(function(i){var n=i.callback;try{n(t)}catch(t){this.logger.log(c.ERROR,r.sprintf(d.NOTIFICATION_LISTENER_EXCEPTION,"NOTIFICATION_CENTER",e,t.message))}}.bind(this))}catch(e){this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e)}};var _e=Math.pow(2,32),fe={bucket:function(e){var t=e.experimentKeyMap[e.experimentKey].groupId;if(t){var i=e.groupIdMap[t];if(!i)throw new Error(r.sprintf(p.INVALID_GROUP_ID,"BUCKETER",t));if("random"===i.policy){var n=this.bucketUserIntoExperiment(i,e.bucketingId,e.userId,e.logger);if(null===n){var o=r.sprintf(d.USER_NOT_IN_ANY_EXPERIMENT,"BUCKETER",e.userId,t);return e.logger.log(c.INFO,o),null}if(n!==e.experimentId){var a=r.sprintf(d.USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP,"BUCKETER",e.userId,e.experimentKey,t);return e.logger.log(c.INFO,a),null}var s=r.sprintf(d.USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP,"BUCKETER",e.userId,e.experimentKey,t);e.logger.log(c.INFO,s)}}var l=r.sprintf("%s%s",e.bucketingId,e.experimentId),u=this._generateBucketValue(l),E=r.sprintf(d.USER_ASSIGNED_TO_EXPERIMENT_BUCKET,"BUCKETER",u,e.userId);e.logger.log(c.DEBUG,E);var _=this._findBucket(u,e.trafficAllocationConfig);if(!e.variationIdMap.hasOwnProperty(_)){if(_){var f=r.sprintf(d.INVALID_VARIATION_ID,"BUCKETER");e.logger.log(c.WARNING,f)}return null}return _},bucketUserIntoExperiment:function(e,t,i,n){var o=r.sprintf("%s%s",t,e.id),a=this._generateBucketValue(o);n.log(c.DEBUG,r.sprintf(d.USER_ASSIGNED_TO_EXPERIMENT_BUCKET,"BUCKETER",a,i));var s=e.trafficAllocation;return this._findBucket(a,s)},_findBucket:function(e,t){for(var r=0;r<t.length;r++)if(e<t[r].endOfRange)return t[r].entityId;return null},_generateBucketValue:function(e){try{var t=n.v3(e,1);return parseInt(1e4*(t/_e),10)}catch(t){throw new Error(r.sprintf(p.INVALID_BUCKETING_ID,"BUCKETER",e,t.message))}}},Ie=["and","or","not"];function ge(e,t){if(Array.isArray(e)){var r=e[0],i=e.slice(1);switch("string"==typeof r&&-1===Ie.indexOf(r)&&(r="or",i=e),r){case"and":return function(e,t){var r=!1;if(Array.isArray(e)){for(var i=0;i<e.length;i++){var n=ge(e[i],t);if(!1===n)return!1;null===n&&(r=!0)}return!r||null}return null}(i,t);case"not":return function(e,t){if(Array.isArray(e)&&e.length>0){var r=ge(e[0],t);return null===r?null:!r}return null}(i,t);default:return function(e,t){var r=!1;if(Array.isArray(e)){for(var i=0;i<e.length;i++){var n=ge(e[i],t);if(!0===n)return!0;null===n&&(r=!0)}return!!r&&null}return null}(i,t)}}return t(e)}var ce=t.getLogger();function pe(e){return/^\d+$/.test(e)}function de(e){var t=e.indexOf("-"),r=e.indexOf("+");return!(t<0)&&(r<0||t<r)}function Ne(e){var t=e.indexOf("-"),r=e.indexOf("+");return!(r<0)&&(t<0||r<t)}function Re(e){var t=e,r="";if(function(e){return/\s/.test(e)}(e))return ce.warn(d.UNKNOWN_MATCH_TYPE,"SEMANTIC VERSION",e),null;if(de(e)?(t=e.substring(0,e.indexOf("-")),r=e.substring(e.indexOf("-")+1)):Ne(e)&&(t=e.substring(0,e.indexOf("+")),r=e.substring(e.indexOf("+")+1)),"string"!=typeof t||"string"!=typeof r)return null;var i=t.split(".").length-1;if(i>2)return ce.warn(d.UNKNOWN_MATCH_TYPE,"SEMANTIC VERSION",e),null;var n=t.split(".");if(n.length!=i+1)return ce.warn(d.UNKNOWN_MATCH_TYPE,"SEMANTIC VERSION",e),null;for(var o=0,a=n;o<a.length;o++){if(!pe(a[o]))return ce.warn(d.UNKNOWN_MATCH_TYPE,"SEMANTIC VERSION",e),null}return r&&n.push(r),n}var Oe="CUSTOM_ATTRIBUTE_CONDITION_EVALUATOR",Te=t.getLogger(),he=["exact","exists","gt","ge","lt","le","substring","semver_eq","semver_lt","semver_le","semver_gt","semver_ge"],ve={};function Ae(e){return"string"==typeof e||"boolean"==typeof e||g(e)}function ye(e,t){var r=e.value,i=typeof r,n=e.name,o=t[n],a=typeof o;return!Ae(r)||g(r)&&!f(r)?(Te.warn(d.UNEXPECTED_CONDITION_VALUE,Oe,JSON.stringify(e)),null):null===o?(Te.debug(d.UNEXPECTED_TYPE_NULL,Oe,JSON.stringify(e),n),null):Ae(o)&&i===a?g(o)&&!f(o)?(Te.warn(d.OUT_OF_BOUNDS,Oe,JSON.stringify(e),n),null):r===o:(Te.warn(d.UNEXPECTED_TYPE,Oe,JSON.stringify(e),a,n),null)}function Ue(e,t){var r=e.name,i=t[r],n=typeof i,o=e.value;return null!==o&&f(o)?null===i?(Te.debug(d.UNEXPECTED_TYPE_NULL,Oe,JSON.stringify(e),r),!1):g(i)?!!f(i)||(Te.warn(d.OUT_OF_BOUNDS,Oe,JSON.stringify(e),r),!1):(Te.warn(d.UNEXPECTED_TYPE,Oe,JSON.stringify(e),n,r),!1):(Te.warn(d.UNEXPECTED_CONDITION_VALUE,Oe,JSON.stringify(e)),!1)}function Le(e,t){var r=e.name,i=t[r],n=typeof i,o=e.value;return"string"!=typeof o?(Te.warn(d.UNEXPECTED_CONDITION_VALUE,Oe,JSON.stringify(e)),null):null===i?(Te.debug(d.UNEXPECTED_TYPE_NULL,Oe,JSON.stringify(e),r),null):"string"!=typeof i?(Te.warn(d.UNEXPECTED_TYPE,Oe,JSON.stringify(e),n,r),null):function(e,t){var r=Re(t),i=Re(e);if(!r||!i)return null;for(var n=r.length,o=0;o<i.length;o++){if(n<=o)return de(e)||Ne(e)?1:-1;if(pe(r[o])){var a=parseInt(r[o]),s=parseInt(i[o]);if(a>s)return 1;if(a<s)return-1}else{if(r[o]<i[o])return de(e)&&!de(t)?1:-1;if(r[o]>i[o])return!de(e)&&de(t)?-1:1}}return de(t)&&!de(e)?-1:0}(o,i)}ve.exact=ye,ve.exists=function(e,t){var r=t[e.name];return null!=r},ve.gt=function(e,t){var r=t[e.name],i=e.value;if(!Ue(e,t)||null===i)return null;return r>i},ve.ge=function(e,t){var r=t[e.name],i=e.value;if(!Ue(e,t)||null===i)return null;return r>=i},ve.lt=function(e,t){var r=t[e.name],i=e.value;if(!Ue(e,t)||null===i)return null;return r<i},ve.le=function(e,t){var r=t[e.name],i=e.value;if(!Ue(e,t)||null===i)return null;return r<=i},ve.substring=function(e,t){var r=e.name,i=t[e.name],n=typeof i,o=e.value;if("string"!=typeof o)return Te.warn(d.UNEXPECTED_CONDITION_VALUE,Oe,JSON.stringify(e)),null;if(null===i)return Te.debug(d.UNEXPECTED_TYPE_NULL,Oe,JSON.stringify(e),r),null;if("string"!=typeof i)return Te.warn(d.UNEXPECTED_TYPE,Oe,JSON.stringify(e),n,r),null;return-1!==i.indexOf(o)},ve.semver_eq=function(e,t){var r=Le(e,t);if(null===r)return null;return 0===r},ve.semver_gt=function(e,t){var r=Le(e,t);if(null===r)return null;return r>0},ve.semver_ge=function(e,t){var r=Le(e,t);if(null===r)return null;return r>=0},ve.semver_lt=function(e,t){var r=Le(e,t);if(null===r)return null;return r<0},ve.semver_le=function(e,t){var r=Le(e,t);if(null===r)return null;return r<=0};var Ve=Object.freeze({__proto__:null,evaluate:function(e,t){var r=e.match;if(void 0!==r&&-1===he.indexOf(r))return Te.warn(d.UNKNOWN_MATCH_TYPE,Oe,JSON.stringify(e)),null;var i=e.name;return t.hasOwnProperty(i)||"exists"==r?(r&&ve[r]||ye)(e,t):(Te.debug(d.MISSING_ATTRIBUTE_VALUE,Oe,JSON.stringify(e),i),null)}}),De=t.getLogger();function me(e){this.typeToEvaluatorMap=E({},e,{custom_attribute:Ve})}function Se(e){return"string"==typeof e&&""!==e}me.prototype.evaluate=function(e,t,i){if(!e||0===e.length)return!0;i||(i={});var n=function(e){var n=t[e];if(n){De.log(c.DEBUG,r.sprintf(d.EVALUATING_AUDIENCE,"AUDIENCE_EVALUATOR",e,JSON.stringify(n.conditions)));var o=ge(n.conditions,this.evaluateConditionWithUserAttributes.bind(this,i)),a=null===o?"UNKNOWN":o.toString().toUpperCase();return De.log(c.DEBUG,r.sprintf(d.AUDIENCE_EVALUATION_RESULT,"AUDIENCE_EVALUATOR",e,a)),o}return null}.bind(this);return ge(e,n)||!1},me.prototype.evaluateConditionWithUserAttributes=function(e,t){var i=this.typeToEvaluatorMap[t.type];if(!i)return De.log(c.WARNING,r.sprintf(d.UNKNOWN_CONDITION_TYPE,"AUDIENCE_EVALUATOR",JSON.stringify(t))),null;try{return i.evaluate(t,e,De)}catch(e){De.log(c.ERROR,r.sprintf(p.CONDITION_EVALUATOR_ERROR,"AUDIENCE_EVALUATOR",t.type,e.message))}return null};var Ce="DECISION_SERVICE",Pe=p,be=c,Fe=d,Me=v,ke=A;function xe(e){this.audienceEvaluator=new me(e.UNSTABLE_conditionEvaluators),this.forcedVariationMap={},this.logger=e.logger,this.userProfileService=e.userProfileService||null}xe.prototype.getVariation=function(e,t,i,n){var o=this._getBucketingId(i,n);if(!this.__checkIfExperimentIsActive(e,t))return null;var a=e.experimentKeyMap[t],s=this.getForcedVariation(e,t,i);if(s)return s;var l=this.__getWhitelistedVariation(a,i);if(l)return l.key;var u=this.__resolveExperimentBucketMap(i,n);if(l=this.__getStoredVariation(e,a,i,u))return this.logger.log(be.INFO,r.sprintf(Fe.RETURNING_STORED_VARIATION,Ce,l.key,t,i)),l.key;if(!this.__checkIfUserIsInAudience(e,t,ke.EXPERIMENT,i,n,"")){var E=r.sprintf(Fe.USER_NOT_IN_EXPERIMENT,Ce,i,t);return this.logger.log(be.INFO,E),null}var _=this.__buildBucketerParams(e,t,o,i),f=fe.bucket(_);if(!(l=e.variationIdMap[f])){var I=r.sprintf(Fe.USER_HAS_NO_VARIATION,Ce,i,t);return this.logger.log(be.DEBUG,I),null}var g=r.sprintf(Fe.USER_HAS_VARIATION,Ce,i,l.key,t);return this.logger.log(be.INFO,g),this.__saveUserProfile(a,l,i,u),l.key},xe.prototype.__resolveExperimentBucketMap=function(e,t){t=t||{};var r=this.__getUserProfile(e)||{},i=t[R.STICKY_BUCKETING_KEY];return E({},r.experiment_bucket_map,i)},xe.prototype.__checkIfExperimentIsActive=function(e,t){if(!z(e,t)){var i=r.sprintf(Fe.EXPERIMENT_NOT_RUNNING,Ce,t);return this.logger.log(be.INFO,i),!1}return!0},xe.prototype.__getWhitelistedVariation=function(e,t){if(e.forcedVariations&&e.forcedVariations.hasOwnProperty(t)){var i=e.forcedVariations[t];if(e.variationKeyMap.hasOwnProperty(i)){var n=r.sprintf(Fe.USER_FORCED_IN_VARIATION,Ce,t,i);return this.logger.log(be.INFO,n),e.variationKeyMap[i]}var o=r.sprintf(Fe.FORCED_BUCKETING_FAILED,Ce,i,t);return this.logger.log(be.ERROR,o),null}return null},xe.prototype.__checkIfUserIsInAudience=function(e,t,i,n,o,a){var s=Z(e,t),l=te(e);this.logger.log(be.DEBUG,r.sprintf(Fe.EVALUATING_AUDIENCES_COMBINED,Ce,i,a||t,JSON.stringify(s)));var u=this.audienceEvaluator.evaluate(s,l,o);return this.logger.log(be.INFO,r.sprintf(Fe.AUDIENCE_EVALUATION_RESULT_COMBINED,Ce,i,a||t,u.toString().toUpperCase())),u},xe.prototype.__buildBucketerParams=function(e,t,r,i){var n={};return n.experimentKey=t,n.experimentId=Y(e,t),n.userId=i,n.trafficAllocationConfig=Q(e,t),n.experimentKeyMap=e.experimentKeyMap,n.groupIdMap=e.groupIdMap,n.variationIdMap=e.variationIdMap,n.logger=this.logger,n.bucketingId=r,n},xe.prototype.__getStoredVariation=function(e,t,i,n){if(n.hasOwnProperty(t.id)){var o=n[t.id],a=o.variation_id;if(e.variationIdMap.hasOwnProperty(a))return e.variationIdMap[o.variation_id];this.logger.log(be.INFO,r.sprintf(Fe.SAVED_VARIATION_NOT_FOUND,Ce,i,a,t.key))}return null},xe.prototype.__getUserProfile=function(e){var t={user_id:e,experiment_bucket_map:{}};if(!this.userProfileService)return t;try{return this.userProfileService.lookup(e)}catch(t){this.logger.log(be.ERROR,r.sprintf(Pe.USER_PROFILE_LOOKUP_ERROR,Ce,e,t.message))}},xe.prototype.__saveUserProfile=function(e,t,i,n){if(this.userProfileService)try{n[e.id]={variation_id:t.id},this.userProfileService.save({user_id:i,experiment_bucket_map:n}),this.logger.log(be.INFO,r.sprintf(Fe.SAVED_VARIATION,Ce,t.key,e.key,i))}catch(e){this.logger.log(be.ERROR,r.sprintf(Pe.USER_PROFILE_SAVE_ERROR,Ce,i,e.message))}},xe.prototype.getVariationForFeature=function(e,t,i,n){var o=this._getVariationForFeatureExperiment(e,t,i,n);if(null!==o.variation)return o;var a=this._getVariationForRollout(e,t,i,n);return null!==a.variation?(this.logger.log(be.DEBUG,r.sprintf(Fe.USER_IN_ROLLOUT,Ce,i,t.key)),a):(this.logger.log(be.DEBUG,r.sprintf(Fe.USER_NOT_IN_ROLLOUT,Ce,i,t.key)),a)},xe.prototype._getVariationForFeatureExperiment=function(e,t,i,n){var o=null,a=null;if(t.hasOwnProperty("groupId")){var s=e.groupIdMap[t.groupId];s&&(o=this._getExperimentInGroup(e,s,i))&&-1!==t.experimentIds.indexOf(o.id)&&(a=this.getVariation(e,o.key,i,n))}else t.experimentIds.length>0?(o=ee(e,t.experimentIds[0],this.logger))&&(a=this.getVariation(e,o.key,i,n)):this.logger.log(be.DEBUG,r.sprintf(Fe.FEATURE_HAS_NO_EXPERIMENTS,Ce,t.key));var l=null;return null!==a&&null!==o&&(l=o.variationKeyMap[a]),{experiment:o,variation:l,decisionSource:Me.FEATURE_TEST}},xe.prototype._getExperimentInGroup=function(e,t,i){var n=fe.bucketUserIntoExperiment(t,i,i,this.logger);if(n){this.logger.log(be.INFO,r.sprintf(Fe.USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP,Ce,i,n,t.id));var o=ee(e,n,this.logger);if(o)return o}return this.logger.log(be.INFO,r.sprintf(Fe.USER_NOT_BUCKETED_INTO_ANY_EXPERIMENT_IN_GROUP,Ce,i,t.id)),null},xe.prototype._getVariationForRollout=function(e,t,i,n){if(!t.rolloutId)return this.logger.log(be.DEBUG,r.sprintf(Fe.NO_ROLLOUT_EXISTS,Ce,t.key)),{experiment:null,variation:null,decisionSource:Me.ROLLOUT};var o=e.rolloutIdMap[t.rolloutId];if(!o)return this.logger.log(be.ERROR,r.sprintf(Pe.INVALID_ROLLOUT_ID,Ce,t.rolloutId,t.key)),{experiment:null,variation:null,decisionSource:Me.ROLLOUT};if(0===o.experiments.length)return this.logger.log(be.ERROR,r.sprintf(Fe.ROLLOUT_HAS_NO_EXPERIMENTS,Ce,t.rolloutId)),{experiment:null,variation:null,decisionSource:Me.ROLLOUT};var a,s,l,u,E,_,f=this._getBucketingId(i,n),I=o.experiments.length-1;for(a=0;a<I;a++){if(s=e.experimentKeyMap[o.experiments[a].key],_=a+1,this.__checkIfUserIsInAudience(e,s.key,ke.RULE,i,n,_)){if(this.logger.log(be.DEBUG,r.sprintf(Fe.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE,Ce,i,_)),l=this.__buildBucketerParams(e,s.key,f,i),u=fe.bucket(l),E=e.variationIdMap[u])return this.logger.log(be.DEBUG,r.sprintf(Fe.USER_BUCKETED_INTO_TARGETING_RULE,Ce,i,_)),{experiment:s,variation:E,decisionSource:Me.ROLLOUT};this.logger.log(be.DEBUG,r.sprintf(Fe.USER_NOT_BUCKETED_INTO_TARGETING_RULE,Ce,i,_));break}this.logger.log(be.DEBUG,r.sprintf(Fe.USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE,Ce,i,_))}var g=e.experimentKeyMap[o.experiments[I].key];if(this.__checkIfUserIsInAudience(e,g.key,ke.RULE,i,n,"Everyone Else")){if(this.logger.log(be.DEBUG,r.sprintf(Fe.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE,Ce,i,"Everyone Else")),l=this.__buildBucketerParams(e,g.key,f,i),u=fe.bucket(l),E=e.variationIdMap[u])return this.logger.log(be.DEBUG,r.sprintf(Fe.USER_BUCKETED_INTO_EVERYONE_TARGETING_RULE,Ce,i)),{experiment:g,variation:E,decisionSource:Me.ROLLOUT};this.logger.log(be.DEBUG,r.sprintf(Fe.USER_NOT_BUCKETED_INTO_EVERYONE_TARGETING_RULE,Ce,i))}return{experiment:null,variation:null,decisionSource:Me.ROLLOUT}},xe.prototype._getBucketingId=function(e,t){var i=e;return null!=t&&"object"==typeof t&&t.hasOwnProperty(R.BUCKETING_ID)&&("string"==typeof t[R.BUCKETING_ID]?(i=t[R.BUCKETING_ID],this.logger.log(be.DEBUG,r.sprintf(Fe.VALID_BUCKETING_ID,Ce,i))):this.logger.log(be.WARNING,r.sprintf(Fe.BUCKETING_ID_NOT_STRING,Ce))),i},xe.prototype.removeForcedVariation=function(e,t,i){if(!e)throw new Error(r.sprintf(Pe.INVALID_USER_ID,Ce));if(!this.forcedVariationMap.hasOwnProperty(e))throw new Error(r.sprintf(Pe.USER_NOT_IN_FORCED_VARIATION,Ce,e));delete this.forcedVariationMap[e][t],this.logger.log(be.DEBUG,r.sprintf(Fe.VARIATION_REMOVED_FOR_USER,Ce,i,e))},xe.prototype.__setInForcedVariationMap=function(e,t,i){this.forcedVariationMap.hasOwnProperty(e)||(this.forcedVariationMap[e]={}),this.forcedVariationMap[e][t]=i,this.logger.log(be.DEBUG,r.sprintf(Fe.USER_MAPPED_TO_FORCED_VARIATION,Ce,i,t,e))},xe.prototype.getForcedVariation=function(e,t,i){var n,o=this.forcedVariationMap[i];if(!o)return this.logger.log(be.DEBUG,r.sprintf(Fe.USER_HAS_NO_FORCED_VARIATION,Ce,i)),null;try{var a=$(e,t);if(!a.hasOwnProperty("id"))return this.logger.log(be.ERROR,r.sprintf(Pe.IMPROPERLY_FORMATTED_EXPERIMENT,Ce,t)),null;n=a.id}catch(e){return this.logger.log(be.ERROR,e.message),null}var s=o[n];if(!s)return this.logger.log(be.DEBUG,r.sprintf(Fe.USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT,Ce,t,i)),null;var l=W(e,s);return l?this.logger.log(be.DEBUG,r.sprintf(Fe.USER_HAS_FORCED_VARIATION,Ce,l,t,i)):this.logger.log(be.DEBUG,r.sprintf(Fe.USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT,Ce,t,i)),l},xe.prototype.setForcedVariation=function(e,t,i,n){if(null!=n&&!Se(n))return this.logger.log(be.ERROR,r.sprintf(Pe.INVALID_VARIATION_KEY,Ce)),!1;var o;try{var a=$(e,t);if(!a.hasOwnProperty("id"))return this.logger.log(be.ERROR,r.sprintf(Pe.IMPROPERLY_FORMATTED_EXPERIMENT,Ce,t)),!1;o=a.id}catch(e){return this.logger.log(be.ERROR,e.message),!1}if(null==n)try{return this.removeForcedVariation(i,o,t,this.logger),!0}catch(e){return this.logger.log(be.ERROR,e.message),!1}var s=q(e,t,n);if(!s)return this.logger.log(be.ERROR,r.sprintf(Pe.NO_VARIATION_FOR_EXPERIMENT_KEY,Ce,n,t)),!1;try{return this.__setInForcedVariationMap(i,o,s),!0}catch(e){return this.logger.log(be.ERROR,e.message),!1}};var Be=N.REVENUE,Ke=N.VALUE;function Ge(e,t){if(e.hasOwnProperty(Be)){var i=e[Be],n=void 0;return"string"==typeof i?(n=parseInt(i),isNaN(n)?(t.log(c.INFO,r.sprintf(d.FAILED_TO_PARSE_REVENUE,"EVENT_TAG_UTILS",i)),null):(t.log(c.INFO,r.sprintf(d.PARSED_REVENUE_VALUE,"EVENT_TAG_UTILS",n)),n)):"number"==typeof i?(n=i,t.log(c.INFO,r.sprintf(d.PARSED_REVENUE_VALUE,"EVENT_TAG_UTILS",n)),n):null}return null}function we(e,t){if(e.hasOwnProperty(Ke)){var i=e[Ke],n=void 0;return"string"==typeof i?(n=parseFloat(i),isNaN(n)?(t.log(c.INFO,r.sprintf(d.FAILED_TO_PARSE_VALUE,"EVENT_TAG_UTILS",i)),null):(t.log(c.INFO,r.sprintf(d.PARSED_NUMERIC_VALUE,"EVENT_TAG_UTILS",n)),n)):"number"==typeof i?(n=i,t.log(c.INFO,r.sprintf(d.PARSED_NUMERIC_VALUE,"EVENT_TAG_UTILS",n)),n):null}return null}function je(e,t){return"string"==typeof e&&("string"==typeof t||"boolean"==typeof t||g(t)&&f(t))}var Ye="https://logx.optimizely.com/v1/events";function He(e){var t=e.attributes,r=e.configObj,i=r.anonymizeIP,n=r.botFiltering;null==i&&(i=!1);var o={snapshots:[],visitor_id:e.userId,attributes:[]},a={account_id:r.accountId,project_id:r.projectId,visitors:[o],revision:r.revision,client_name:e.clientEngine,client_version:e.clientVersion,anonymize_ip:i,enrich_decisions:!0};return Object.keys(t||{}).forEach((function(r){if(je(r,t[r])){var i=X(e.configObj,r,e.logger);i&&a.visitors[0].attributes.push({entity_id:i,key:r,type:"custom",value:t[r]})}})),"boolean"==typeof n&&a.visitors[0].attributes.push({entity_id:R.BOT_FILTERING,key:R.BOT_FILTERING,type:"custom",value:n}),a}var Xe=function(e){var t={httpVerb:"POST"},i=He(e);t.url=Ye;var n,o,a,s=(n=e.configObj,o=e.experimentId,a=e.variationId,{decisions:[{campaign_id:H(n,o),experiment_id:o,variation_id:a}],events:[{entity_id:H(n,o),timestamp:_(),key:"campaign_activated",uuid:r.generateUUID()}]});return i.visitors[0].snapshots.push(s),t.params=i,t},Je=function(e){var t={httpVerb:"POST"},i=He(e);t.url=Ye;var n=function(e,t,i,n){var o={events:[]},a={entity_id:J(e,t),timestamp:_(),uuid:r.generateUUID(),key:t};if(i){var s=Ge(i,n);null!==s&&(a[N.REVENUE]=s);var l=we(i,n);null!==l&&(a[N.VALUE]=l),a.tags=i}return o.events.push(a),o}(e.configObj,e.eventKey,e.eventTags,e.logger);return i.visitors[0].snapshots=[n],t.params=i,t},ze=t.getLogger("EVENT_BUILDER");function Ze(e,t){var r=[];return Object.keys(t||{}).forEach((function(i){if(je(i,t[i])){var n=X(e,i,ze);n&&r.push({entityId:n,key:i,value:t[i]})}})),r}var We="USER_PROFILE_SERVICE_VALIDATOR";var qe=function(){function e(e){var t=this,i=e.clientEngine;-1===O.indexOf(i)&&(e.logger.log(c.INFO,r.sprintf(d.INVALID_CLIENT_ENGINE,"OPTIMIZELY",i)),i="node-sdk"),this.clientEngine=i,this.clientVersion=e.clientVersion||"4.3.4",this.errorHandler=e.errorHandler,this.eventDispatcher=e.eventDispatcher,this.isOptimizelyConfigValid=e.isValidInstance,this.logger=e.logger,this.projectConfigManager=function(e){return new ue(e)}({datafile:e.datafile,datafileOptions:e.datafileOptions,jsonSchemaValidator:e.jsonSchemaValidator,sdkKey:e.sdkKey}),this.disposeOnUpdate=this.projectConfigManager.onUpdate((function(e){t.logger.log(c.INFO,r.sprintf(d.UPDATED_OPTIMIZELY_CONFIG,"OPTIMIZELY",e.revision,e.projectId)),t.notificationCenter.sendNotifications(T.OPTIMIZELY_CONFIG_UPDATE)}));var n=this.projectConfigManager.onReady(),a=null;if(e.userProfileService)try{(function(e){if("object"==typeof e&&null!==e){if("function"!=typeof e.lookup)throw new Error(r.sprintf(p.INVALID_USER_PROFILE_SERVICE,We,"Missing function 'lookup'"));if("function"!=typeof e.save)throw new Error(r.sprintf(p.INVALID_USER_PROFILE_SERVICE,We,"Missing function 'save'"));return!0}throw new Error(r.sprintf(p.INVALID_USER_PROFILE_SERVICE,We))})(e.userProfileService)&&(a=e.userProfileService,this.logger.log(c.INFO,r.sprintf(d.VALID_USER_PROFILE_SERVICE,"OPTIMIZELY")))}catch(e){this.logger.log(c.WARNING,e.message)}this.decisionService=new xe({userProfileService:a,logger:this.logger,UNSTABLE_conditionEvaluators:e.UNSTABLE_conditionEvaluators}),this.notificationCenter=function(e){return new Ee(e)}({logger:this.logger,errorHandler:this.errorHandler});var s={dispatcher:this.eventDispatcher,flushInterval:e.eventFlushInterval,batchSize:e.eventBatchSize,maxQueueSize:e.eventMaxQueueSize,notificationCenter:this.notificationCenter};this.eventProcessor=new o.LogTierV1EventProcessor(s);var l=this.eventProcessor.start();this.readyPromise=Promise.all([n,l]).then((function(e){return e[0]})),this.readyTimeouts={},this.nextReadyTimeoutId=0}return e.prototype.isValidInstance=function(){return this.isOptimizelyConfigValid&&!!this.projectConfigManager.getConfig()},e.prototype.activate=function(e,t,i){try{if(!this.isValidInstance())return this.logger.log(c.ERROR,r.sprintf(d.INVALID_OBJECT,"OPTIMIZELY","activate")),null;if(!this.validateInputs({experiment_key:e,user_id:t},i))return this.notActivatingExperiment(e,t);var n=this.projectConfigManager.getConfig();if(!n)return null;try{var o=this.getVariation(e,t,i);if(null===o)return this.notActivatingExperiment(e,t);if(!M(n,e)){var a=r.sprintf(d.SHOULD_NOT_DISPATCH_ACTIVATE,"OPTIMIZELY",e);return this.logger.log(c.DEBUG,a),o}return this.sendImpressionEvent(e,o,t,i),o}catch(i){this.logger.log(c.ERROR,i.message);var s=r.sprintf(d.NOT_ACTIVATING_USER,"OPTIMIZELY",t,e);return this.logger.log(c.INFO,s),this.errorHandler.handleError(i),null}}catch(e){return this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e),null}},e.prototype.sendImpressionEvent=function(e,t,i,n){var o=this.projectConfigManager.getConfig();if(o){var a=function(e){var t=e.configObj,i=e.experimentKey,n=e.variationKey,o=e.userId,a=e.userAttributes,s=e.clientEngine,l=e.clientVersion,u=q(t,i,n),E=Y(t,i),f=H(t,E);return{type:"impression",timestamp:_(),uuid:r.generateUUID(),user:{id:o,attributes:Ze(t,a)},context:{accountId:t.accountId,projectId:t.projectId,revision:t.revision,clientName:s,clientVersion:l,anonymizeIP:t.anonymizeIP||!1,botFiltering:t.botFiltering},layer:{id:f},experiment:{id:E,key:i},variation:{id:u,key:n}}}({experimentKey:e,variationKey:t,userId:i,userAttributes:n,clientEngine:this.clientEngine,clientVersion:this.clientVersion,configObj:o});this.eventProcessor.process(a),this.emitNotificationCenterActivate(e,t,i,n)}},e.prototype.emitNotificationCenterActivate=function(e,t,r,i){var n=this.projectConfigManager.getConfig();if(n){var o,a=k(n,e,t),s=b(n,e),l={attributes:i,clientEngine:this.clientEngine,clientVersion:this.clientVersion,configObj:n,experimentId:s,userId:r,variationId:a,logger:this.logger},u=Xe(l),E=n.experimentKeyMap[e];E&&E.variationKeyMap&&(o=E.variationKeyMap[t]),this.notificationCenter.sendNotifications(T.ACTIVATE,{experiment:E,userId:r,attributes:i,variation:o,logEvent:u})}},e.prototype.track=function(e,t,i,n){try{if(!this.isValidInstance())return void this.logger.log(c.ERROR,r.sprintf(d.INVALID_OBJECT,"OPTIMIZELY","track"));if(!this.validateInputs({user_id:t,event_key:e},i,n))return;var o=this.projectConfigManager.getConfig();if(!o)return;if(!w(o,e))return this.logger.log(c.WARNING,r.sprintf(d.EVENT_KEY_NOT_FOUND,"OPTIMIZELY",e)),void this.logger.log(c.WARNING,r.sprintf(d.NOT_TRACKING_USER,"OPTIMIZELY",t));var a=function(e){var t=e.configObj,i=e.userId,n=e.userAttributes,o=e.clientEngine,a=e.clientVersion,s=e.eventKey,l=e.eventTags,u=J(t,s),E=null,f=null;return l&&(E=Ge(l,ze),f=we(l,ze)),{type:"conversion",timestamp:_(),uuid:r.generateUUID(),user:{id:i,attributes:Ze(t,n)},context:{accountId:t.accountId,projectId:t.projectId,revision:t.revision,clientName:o,clientVersion:a,anonymizeIP:t.anonymizeIP||!1,botFiltering:t.botFiltering},event:{id:u,key:s},revenue:E,value:f,tags:l}}({eventKey:e,eventTags:n=this.filterEmptyValues(n),userId:t,userAttributes:i,clientEngine:this.clientEngine,clientVersion:this.clientVersion,configObj:o});this.logger.log(c.INFO,r.sprintf(d.TRACK_EVENT,"OPTIMIZELY",e,t)),this.eventProcessor.process(a),this.emitNotificationCenterTrack(e,t,i,n)}catch(e){this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e);var s=r.sprintf(d.NOT_TRACKING_USER,"OPTIMIZELY",t);this.logger.log(c.ERROR,s)}},e.prototype.emitNotificationCenterTrack=function(e,t,r,i){try{var n=this.projectConfigManager.getConfig();if(!n)return;var o={attributes:r,clientEngine:this.clientEngine,clientVersion:this.clientVersion,configObj:n,eventKey:e,eventTags:i,logger:this.logger,userId:t},a=Je(o);this.notificationCenter.sendNotifications(T.TRACK,{eventKey:e,userId:t,attributes:r,eventTags:i,logEvent:a})}catch(e){this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e)}},e.prototype.getVariation=function(e,t,i){try{if(!this.isValidInstance())return this.logger.log(c.ERROR,r.sprintf(d.INVALID_OBJECT,"OPTIMIZELY","getVariation")),null;try{if(!this.validateInputs({experiment_key:e,user_id:t},i))return null;var n=this.projectConfigManager.getConfig();if(!n)return null;var o=n.experimentKeyMap[e];if(!o)return this.logger.log(c.DEBUG,r.sprintf(p.INVALID_EXPERIMENT_KEY,"OPTIMIZELY",e)),null;var a=this.decisionService.getVariation(n,e,t,i),s=j(n,o.id)?h.FEATURE_TEST:h.AB_TEST;return this.notificationCenter.sendNotifications(T.DECISION,{type:s,userId:t,attributes:i||{},decisionInfo:{experimentKey:e,variationKey:a}}),a}catch(e){return this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e),null}}catch(e){return this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e),null}},e.prototype.setForcedVariation=function(e,t,r){if(!this.validateInputs({experiment_key:e,user_id:t}))return!1;var i=this.projectConfigManager.getConfig();if(!i)return!1;try{return this.decisionService.setForcedVariation(i,e,t,r)}catch(e){return this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e),!1}},e.prototype.getForcedVariation=function(e,t){if(!this.validateInputs({experiment_key:e,user_id:t}))return null;var r=this.projectConfigManager.getConfig();if(!r)return null;try{return this.decisionService.getForcedVariation(r,e,t)}catch(e){return this.logger.log(c.ERROR,e.message),this.errorHandler.handleError(e),null}},e.prototype.validateInputs=function(e,t,i){try{if(e.hasOwnProperty("user_id")){var n=e.user