lib/vwo/core/bucketer.rb
# Validates the User ID and
# Generates Variation into which the User is bucketed to
#
# @param[String]            :user_id          The unique ID assigned to User
# @param[Hash]              :campaign         The Campaign of which User is a part of
#
# @return[Hash|nil}                           Variation data into which user is bucketed to
#                                             or nil if not
Validates the User ID and
Generates Variation into which the User is bucketed to
Validates the User ID and Generates Variation into which the User is bucketed to
def bucket_user_to_variation(user_id, campaign)
        unless valid_value?(user_id)
          @logger.log(
            LogLevelEnum::ERROR,
            format(LogMessageEnum::ErrorMessages::INVALID_USER_ID, file: FILE, user_id: user_id, method: 'bucket_user_to_variation')
          )
          return
        end
        unless campaign
          @logger.log(
            LogLevelEnum::ERROR,
            format(LogMessageEnum::ErrorMessages::INVALID_CAMPAIGN, file: FILE, method: 'is_user_part_of_campaign')
          )
          return
        end
        user_id_for_hash_value = user_id
        if campaign[:isBucketingSeedEnabled]
          user_id_for_hash_value = campaign[:id].to_s + "_" + user_id
        end
        hash_value = MurmurHash3::V32.str_hash(user_id_for_hash_value, SEED_VALUE) & U_MAX_32_BIT
        normalize = MAX_TRAFFIC_VALUE.to_f / campaign['percentTraffic']
        multiplier = normalize / 100
        bucket_value = get_bucket_value(
          hash_value,
          MAX_TRAFFIC_VALUE,
          multiplier
        )
        @logger.log(
          LogLevelEnum::DEBUG,
          format(
            LogMessageEnum::DebugMessages::VARIATION_HASH_BUCKET_VALUE,
            file: FILE,
            user_id: user_id,
            campaign_key: campaign['key'],
            percent_traffic: campaign['percentTraffic'],
            bucket_value: bucket_value,
            hash_value: hash_value
          )
        )
        get_variation(campaign['variations'], bucket_value)
      end
def bucket_user_to_variation ( user_id , campaign ) unless valid_value? ( user_id ) @logger . log ( LogLevelEnum :: ERROR , format ( LogMessageEnum :: ErrorMessages :: INVALID_USER_ID , file : FILE , user_id : user_id , method : 'bucket_user_to_variation' ) ) return end unless campaign @logger . log ( LogLevelEnum :: ERROR , format ( LogMessageEnum :: ErrorMessages :: INVALID_CAMPAIGN , file : FILE , method : 'is_user_part_of_campaign' ) ) return end user_id_for_hash_value = user_id if campaign [ :isBucketingSeedEnabled ] user_id_for_hash_value = campaign [ :id ] . to_s + "_" + user_id end hash_value = MurmurHash3 :: V32 . str_hash ( user_id_for_hash_value , SEED_VALUE ) & U_MAX_32_BIT normalize = MAX_TRAFFIC_VALUE . to_f / campaign [ 'percentTraffic' ] multiplier = normalize / 100 bucket_value = get_bucket_value ( hash_value , MAX_TRAFFIC_VALUE , multiplier ) @logger . log ( LogLevelEnum :: DEBUG , format ( LogMessageEnum :: DebugMessages :: VARIATION_HASH_BUCKET_VALUE , file : FILE , user_id : user_id , campaign_key : campaign [ 'key' ] , percent_traffic : campaign [ 'percentTraffic' ] , bucket_value : bucket_value , hash_value : hash_value ) ) get_variation ( campaign [ 'variations' ] , bucket_value ) end
Validates the User ID and
Generates Variation into which the User is bucketed to
Validates the User ID and Generates Variation into which the User is bucketed to
user_id
<not_specific>
campaign
<not_specific>
param[String]
:user_id The unique ID assigned to User
: user_id The unique ID assigned to User
param[Hash]
:campaign The Campaign of which User is a part of
: campaign The Campaign of which User is a part of
return[Hash|nil}
Variation data into which user is bucketed to or nil if not
Variation data into which user is bucketed to or nil if not