SHARE
TWEET

Untitled

a guest Jul 17th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DecisionService.prototype.getVariation = function(configObj, experimentKey, userId, attributes) {
  2.   // by default, the bucketing ID should be the user ID
  3.   var bucketingId = this._getBucketingId(userId, attributes);
  4.  
  5.   if (!this.__checkIfExperimentIsActive(configObj, experimentKey, userId)) {
  6.     return null;
  7.   }
  8.   var experiment = configObj.experimentKeyMap[experimentKey];
  9.   var forcedVariationKey = this.getForcedVariation(configObj, experimentKey, userId);
  10.   if (!!forcedVariationKey) {
  11.     return forcedVariationKey;
  12.   }
  13.  
  14.   var variation = this.__getWhitelistedVariation(experiment, userId);
  15.   if (!!variation) {
  16.     return variation.key;
  17.   }
  18.  
  19.   // check for sticky bucketing
  20.   var experimentBucketMap = this.__resolveExperimentBucketMap(userId, attributes);
  21.   variation = this.__getStoredVariation(configObj, experiment, userId, experimentBucketMap);
  22.   if (!!variation) {
  23.     this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.RETURNING_STORED_VARIATION, MODULE_NAME, variation.key, experimentKey, userId));
  24.     return variation.key;
  25.   }
  26.  
  27.   // Perform regular targeting and bucketing
  28.   if (!this.__checkIfUserIsInAudience(configObj, experimentKey, userId, attributes)) {
  29.     return null;
  30.   }
  31.  
  32.   var bucketerParams = this.__buildBucketerParams(configObj, experimentKey, bucketingId, userId);
  33.   var variationId = bucketer.bucket(bucketerParams);
  34.   variation = configObj.variationIdMap[variationId];
  35.   if (!variation) {
  36.     return null;
  37.   }
  38.  
  39.   // persist bucketing
  40.   this.__saveUserProfile(experiment, variation, userId, experimentBucketMap);
  41.  
  42.   return variation.key;
  43. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top