packages/optimizely-sdk/lib/core/audience_evaluator/index.js
function(audienceConditions, audiencesById, userAttributes, logger) {
    // if there are no audiences, return true because that means ALL users are included in the experiment
    if (!audienceConditions || audienceConditions.length === 0) {
      return true;
    }

    if (!userAttributes) {
      userAttributes = {};
    }

    var evaluateConditionWithUserAttributes = function(condition) {
      return customAttributeConditionEvaluator.evaluate(condition, userAttributes, logger);
    };

    var evaluateAudience = function(audienceId) {
      var audience = audiencesById[audienceId];
      if (audience) {
        logger.log(LOG_LEVEL.DEBUG, sprintf(LOG_MESSAGES.EVALUATING_AUDIENCE, MODULE_NAME, audienceId, JSON.stringify(audience.conditions)));
        var result = conditionTreeEvaluator.evaluate(audience.conditions, evaluateConditionWithUserAttributes);
        var resultText = result === null ? 'UNKNOWN' : result.toString().toUpperCase();
        logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.AUDIENCE_EVALUATION_RESULT, MODULE_NAME, audienceId, resultText));
        return result;
      }

      return null;
    };

    return conditionTreeEvaluator.evaluate(audienceConditions, evaluateAudience) || false;
  }
function(audienceConditions, audiencesById, userAttributes, logger) {
    // if there are no audiences, return true because that means ALL users are included in the experiment
    if (!audienceConditions || audienceConditions.length === 0) {
      return true;
    }

    if (!userAttributes) {
      userAttributes = {};
    }

    var evaluateConditionWithUserAttributes = function(condition) {
      return customAttributeConditionEvaluator.evaluate(condition, userAttributes, logger);
    };

    var evaluateAudience = function(audienceId) {
      var audience = audiencesById[audienceId];
      if (audience) {
        logger.log(LOG_LEVEL.DEBUG, sprintf(LOG_MESSAGES.EVALUATING_AUDIENCE, MODULE_NAME, audienceId, JSON.stringify(audience.conditions)));
        var result = conditionTreeEvaluator.evaluate(audience.conditions, evaluateConditionWithUserAttributes);
        var resultText = result === null ? 'UNKNOWN' : result.toString().toUpperCase();
        logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.AUDIENCE_EVALUATION_RESULT, MODULE_NAME, audienceId, resultText));
        return result;
      }

      return null;
    };

    return conditionTreeEvaluator.evaluate(audienceConditions, evaluateAudience) || false;
  }
function ( audienceConditions , audiencesById , userAttributes , logger ) { // if there are no audiences, return true because that means ALL users are included in the experiment if ( ! audienceConditions || audienceConditions . length === 0 ) { return true ; } if ( ! userAttributes ) { userAttributes = { } ; } var evaluateConditionWithUserAttributes = function ( condition ) { return customAttributeConditionEvaluator . evaluate ( condition , userAttributes , logger ) ; } ; var evaluateAudience = function ( audienceId ) { var audience = audiencesById [ audienceId ] ; if ( audience ) { logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . EVALUATING_AUDIENCE , MODULE_NAME , audienceId , JSON . stringify ( audience . conditions ) ) ) ; var result = conditionTreeEvaluator . evaluate ( audience . conditions , evaluateConditionWithUserAttributes ) ; var resultText = result === null ? 'UNKNOWN' : result . toString ( ) . toUpperCase ( ) ; logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . AUDIENCE_EVALUATION_RESULT , MODULE_NAME , audienceId , resultText ) ) ; return result ; } return null ; } ; return conditionTreeEvaluator . evaluate ( audienceConditions , evaluateAudience ) || false ; }
Determine if the given user attributes satisfy the given audience conditions
@param  {Array|String|null|undefined}  audienceConditions    Audience conditions to match the user attributes against - can be an array
of audience IDs, a nested array of conditions, or a single leaf condition.
Examples: ["5", "6"], ["and", ["or", "1", "2"], "3"], "1"
@param  {Object}                       audiencesById         Object providing access to full audience objects for audience IDs
contained in audienceConditions. Keys should be audience IDs, values
should be full audience objects with conditions properties
@param  {Object}                       [userAttributes]      User attributes which will be used in determining if audience conditions
are met. If not provided, defaults to an empty object
@param  {Object}                       logger                Logger instance.
@return {Boolean}                                            true if the user attributes match the given audience conditions, false
otherwise
Determine if the given user attributes satisfy the given audience conditions