lib/vwo.rb
# This API method: Identifies whether the user becomes a part of feature rollout/test or not.
# 1. Validates the arguments being passed
# 2. Checks if user is eligible to get bucketed into the feature test/rollout,
# 3. Assigns the deterministic variation to the user(based on userId),
#    If user becomes part of feature test/rollout
#    If UserStorage is used, it will look into it for the variation and if found, no further processing is done
#
# @param[String]                :campaign_key                       Unique campaign key
# @param[String]                :user_id                            ID assigned to a user
# @param[Hash]                  :custom_variables                   Pass it through options as custom_variables={}
#
# @return[Boolean]  true if user becomes part of feature test/rollout, otherwise false.
This API method: Identifies whether the user becomes a part of feature rollout/test or not.
1. Validates the arguments being passed
2. Checks if user is eligible to get bucketed into the feature test/rollout,
3. Assigns the deterministic variation to the user(based on userId),
If user becomes part of feature test/rollout
If UserStorage is used, it will look into it for the variation and if found, no further processing is done
This API method : Identifies whether the user becomes a part of feature rollout / test or not . 1 . Validates the arguments being passed 2 . Checks if user is eligible to get bucketed into the feature test / rollout 3 . Assigns the deterministic variation to the user ( based on userId ) If user becomes part of feature test / rollout If UserStorage is used it will look into it for the variation and if found no further processing is done
def feature_enabled?(campaign_key, user_id, options = {})
    if is_opted_out(ApiMethods::IS_FEATURE_ENABLED)
      return false
    end
    unless @is_instance_valid
      @logger.log(
        LogLevelEnum::ERROR,
        format(
          LogMessageEnum::ErrorMessages::API_CONFIG_CORRUPTED,
          file: FILE,
          api_name: ApiMethods::IS_FEATURE_ENABLED
        )
      )
      return false
    end
    options = convert_to_symbol_hash(options)
    custom_variables = options[:custom_variables]
    variation_targeting_variables = options[:variation_targeting_variables]
    @logger.log(
      LogLevelEnum::INFO,
      format(
        LogMessageEnum::InfoMessages::API_CALLED,
        file: FILE,
        api_name: ApiMethods::IS_FEATURE_ENABLED,
        user_id: user_id
      )
    )
    unless valid_string?(campaign_key) && valid_string?(user_id) && (custom_variables.nil? || valid_hash?(custom_variables)) &&
      (variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables))
      @logger.log(
        LogLevelEnum::ERROR,
        format(
          LogMessageEnum::ErrorMessages::IS_FEATURE_ENABLED_API_INVALID_PARAMS,
          api_name: ApiMethods::IS_FEATURE_ENABLED,
          file: FILE
        )
      )
      return false
    end
    campaign = get_campaign(@settings_file, campaign_key)
    unless campaign && campaign['status'] == STATUS_RUNNING
      @logger.log(
        LogLevelEnum::ERROR,
        format(
          LogMessageEnum::ErrorMessages::CAMPAIGN_NOT_RUNNING,
          file: FILE,
          campaign_key: campaign_key,
          api_name: ApiMethods::IS_FEATURE_ENABLED
        )
      )
      return false
    end
    _type
    campaign_type = campaign['type']
    if campaign_type == CampaignTypes::VISUAL_AB
      @logger.log(
        LogLevelEnum::ERROR,
        format(
          LogMessageEnum::ErrorMessages::INVALID_API,
          file: FILE,
          api_name: ApiMethods::IS_FEATURE_ENABLED,
          user_id: user_id,
          campaign_key: campaign_key,
          campaign_type: campaign_type
        )
      )
      return false
    end
    variation = @variation_decider.get_variation(user_id, campaign, ApiMethods::IS_FEATURE_ENABLED, campaign_key, custom_variables, variation_targeting_variables)
    return false unless variation
    if is_eligible_to_send_impression()
      if defined?(@batch_events)
        impression = create_bulk_event_impression(
          @settings_file,
          campaign['id'],
          variation['id'],
          user_id
        )
        @batch_events_queue.enqueue(impression)
      elsif is_event_arch_enabled
        properties = get_events_base_properties(@settings_file, EventEnum::VWO_VARIATION_SHOWN, @usage_stats.usage_stats)
        payload = get_track_user_payload_data(@settings_file, user_id, EventEnum::VWO_VARIATION_SHOWN, campaign['id'], variation['id'])
        @event_dispatcher.dispatch_event_arch_post(properties, payload)
      else
        impression = create_impression(
          @settings_file,
          campaign['id'],
          variation['id'],
          user_id,
          @sdk_key,
          nil,
          nil,
          usage_stats: @usage_stats.usage_stats
        )
        @event_dispatcher.dispatch(impression)
        @logger.log(
          LogLevelEnum::INFO,
          format(
            LogMessageEnum::InfoMessages::MAIN_KEYS_FOR_IMPRESSION,
            file: FILE,
            campaign_id: impression[:experiment_id],
            account_id: impression[:account_id],
            variation_id: impression[:combination]
          )
        )
      end
    else
      @logger.log(
        LogLevelEnum::INFO,
        format(
          LogMessageEnum::InfoMessages::USER_ALREADY_TRACKED,
          file: FILE,
          user_id: user_id,
          campaign_key: campaign_key,
          api_name: ApiMethods::IS_FEATURE_ENABLED
        )
      )
    end
    if campaign_type == CampaignTypes::FEATURE_ROLLOUT
      result = true
    else
      result = variation['isFeatureEnabled']
    end
    if result
      @logger.log(
        LogLevelEnum::INFO,
        format(
          LogMessageEnum::InfoMessages::FEATURE_ENABLED_FOR_USER,
          file: FILE,
          user_id: user_id,
          feature_key: campaign_key,
          api_name: ApiMethods::IS_FEATURE_ENABLED
        )
      )
    else
      @logger.log(
        LogLevelEnum::INFO,
        format(
          LogMessageEnum::InfoMessages::FEATURE_NOT_ENABLED_FOR_USER,
          file: FILE,
          user_id: user_id,
          feature_key: campaign_key,
          api_name: ApiMethods::IS_FEATURE_ENABLED
        )
      )
    end
    result
  rescue StandardError => e
    @logger.log(
      LogLevelEnum::ERROR,
      format(
        LogMessageEnum::ErrorMessages::API_NOT_WORKING,
        file: FILE,
        api_name: ApiMethods::IS_FEATURE_ENABLED,
        exception: e
      )
    )
    false
  end
def feature_enabled? ( campaign_key , user_id , options = { } ) if is_opted_out ( ApiMethods :: IS_FEATURE_ENABLED ) return false end unless @is_instance_valid @logger . log ( LogLevelEnum :: ERROR , format ( LogMessageEnum :: ErrorMessages :: API_CONFIG_CORRUPTED , file : FILE , api_name : ApiMethods :: IS_FEATURE_ENABLED ) ) return false end options = convert_to_symbol_hash ( options ) custom_variables = options [ :custom_variables ] variation_targeting_variables = options [ :variation_targeting_variables ] @logger . log ( LogLevelEnum :: INFO , format ( LogMessageEnum :: InfoMessages :: API_CALLED , file : FILE , api_name : ApiMethods :: IS_FEATURE_ENABLED , user_id : user_id ) ) unless valid_string? ( campaign_key ) && valid_string? ( user_id ) && ( custom_variables . nil? || valid_hash? ( custom_variables ) ) && ( variation_targeting_variables . nil? || valid_hash? ( variation_targeting_variables ) ) @logger . log ( LogLevelEnum :: ERROR , format ( LogMessageEnum :: ErrorMessages :: IS_FEATURE_ENABLED_API_INVALID_PARAMS , api_name : ApiMethods :: IS_FEATURE_ENABLED , file : FILE ) ) return false end campaign = get_campaign ( @settings_file , campaign_key ) unless campaign && campaign [ 'status' ] == STATUS_RUNNING @logger . log ( LogLevelEnum :: ERROR , format ( LogMessageEnum :: ErrorMessages :: CAMPAIGN_NOT_RUNNING , file : FILE , campaign_key : campaign_key , api_name : ApiMethods :: IS_FEATURE_ENABLED ) ) return false end campaign_type = campaign [ 'type' ] if campaign_type == CampaignTypes :: VISUAL_AB @logger . log ( LogLevelEnum :: ERROR , format ( LogMessageEnum :: ErrorMessages :: INVALID_API , file : FILE , api_name : ApiMethods :: IS_FEATURE_ENABLED , user_id : user_id , campaign_key : campaign_key , campaign_type : campaign_type ) ) return false end variation = @variation_decider . get_variation ( user_id , campaign , ApiMethods :: IS_FEATURE_ENABLED , campaign_key , custom_variables , variation_targeting_variables ) return false unless variation if is_eligible_to_send_impression ( ) if defined? ( @batch_events ) impression = create_bulk_event_impression ( @settings_file , campaign [ 'id' ] , variation [ 'id' ] , user_id ) @batch_events_queue . enqueue ( impression ) elsif is_event_arch_enabled properties = get_events_base_properties ( @settings_file , EventEnum :: VWO_VARIATION_SHOWN , @usage_stats . usage_stats ) payload = get_track_user_payload_data ( @settings_file , user_id , EventEnum :: VWO_VARIATION_SHOWN , campaign [ 'id' ] , variation [ 'id' ] ) @event_dispatcher . dispatch_event_arch_post ( properties , payload ) else impression = create_impression ( @settings_file , campaign [ 'id' ] , variation [ 'id' ] , user_id , @sdk_key , nil , nil , usage_stats : @usage_stats . usage_stats ) @event_dispatcher . dispatch ( impression ) @logger . log ( LogLevelEnum :: INFO , format ( LogMessageEnum :: InfoMessages :: MAIN_KEYS_FOR_IMPRESSION , file : FILE , campaign_id : impression [ :experiment_id ] , account_id : impression [ :account_id ] , variation_id : impression [ :combination ] ) ) end else @logger . log ( LogLevelEnum :: INFO , format ( LogMessageEnum :: InfoMessages :: USER_ALREADY_TRACKED , file : FILE , user_id : user_id , campaign_key : campaign_key , api_name : ApiMethods :: IS_FEATURE_ENABLED ) ) end if campaign_type == CampaignTypes :: FEATURE_ROLLOUT result = true else result = variation [ 'isFeatureEnabled' ] end if result @logger . log ( LogLevelEnum :: INFO , format ( LogMessageEnum :: InfoMessages :: FEATURE_ENABLED_FOR_USER , file : FILE , user_id : user_id , feature_key : campaign_key , api_name : ApiMethods :: IS_FEATURE_ENABLED ) ) else @logger . log ( LogLevelEnum :: INFO , format ( LogMessageEnum :: InfoMessages :: FEATURE_NOT_ENABLED_FOR_USER , file : FILE , user_id : user_id , feature_key : campaign_key , api_name : ApiMethods :: IS_FEATURE_ENABLED ) ) end result rescue StandardError => e @logger . log ( LogLevelEnum :: ERROR , format ( LogMessageEnum :: ErrorMessages :: API_NOT_WORKING , file : FILE , api_name : ApiMethods :: IS_FEATURE_ENABLED , exception : e ) ) false end
This API method: Identifies whether the user becomes a part of feature rollout/test or not.
This API method : Identifies whether the user becomes a part of feature rollout / test or not .
# Retrieve custom variables # Validate input parameters # Get the campaign settings # Validate campaign # log error # Validate campaign_type # Get variation # If no variation, did not become part of feature_test/rollout # if campaign type is feature_test Send track call to server
campaign_key
<not_specific>
user_id
<not_specific>
options
<not_specific>
param[String]
:campaign_key Unique campaign key
: campaign_key Unique campaign key
param[String]
:user_id ID assigned to a user
: user_id ID assigned to a user
param[Hash]
:custom_variables Pass it through options as custom_variables={}
: custom_variables Pass it through options as custom_variables = {}
return[Boolean]
true if user becomes part of feature test/rollout, otherwise false.
true if user becomes part of feature test / rollout otherwise false .