Class: Kameleoon::Targeting::TargetingManager Private

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/targeting/targeting_manager.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(data_manager, visitor_manager) ⇒ TargetingManager

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TargetingManager.



10
11
12
13
# File 'lib/kameleoon/targeting/targeting_manager.rb', line 10

def initialize(data_manager, visitor_manager)
  @data_manager = data_manager
  @visitor_manager = visitor_manager
end

Instance Method Details

#check_targeting(visitor_code, campaign_id, exp_ff_rule) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kameleoon/targeting/targeting_manager.rb', line 15

def check_targeting(visitor_code, campaign_id, exp_ff_rule)
  Logging::KameleoonLogger.debug(
    "CALL: TargetingManager.check_targeting(visitorCode: '%s', campaignId: %s, exp_ff_rule: %s)",
    visitor_code, campaign_id, exp_ff_rule
  )
  segment = exp_ff_rule.targeting_segment
  if segment.nil?
    Logging::KameleoonLogger.debug(
      "RETURN: TargetingManager.check_targeting(visitorCode: '%s', campaignId: %s, exp_ff_rule: %s) -> " \
        '(targeting: true)', visitor_code, campaign_id, exp_ff_rule
    )
    return true
  end

  visitor = @visitor_manager.get_visitor(visitor_code)
  targeting = segment.check_tree(->(type) { get_condition_data(type, visitor, visitor_code, campaign_id) })
  Logging::KameleoonLogger.debug(
    "RETURN: TargetingManager.check_targeting(visitorCode: '%s', campaignId: %s, exp_ff_rule: %s) -> " \
      '(targeting: %s)', visitor_code, campaign_id, exp_ff_rule, targeting
  )
  targeting
end

#get_condition_data(type, visitor, visitor_code, campaign_id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/kameleoon/targeting/targeting_manager.rb', line 38

def get_condition_data(type, visitor, visitor_code, campaign_id)
  Logging::KameleoonLogger.debug(
    "CALL: TargetingManager.get_condition_data(type: %s, visitor, visitorCode: '%s', campaignId: %s)",
    type, visitor_code, campaign_id
  )
  condition_data = nil
  case type
  when Kameleoon::Targeting::ConditionType::CUSTOM_DATUM
    condition_data = visitor.custom_data unless visitor.nil?
  when Kameleoon::Targeting::ConditionType::PAGE_VIEWS,
    Kameleoon::Targeting::ConditionType::PREVIOUS_PAGE,
    Kameleoon::Targeting::ConditionType::PAGE_TITLE,
    Kameleoon::Targeting::ConditionType::PAGE_URL
    condition_data = visitor.page_view_visits unless visitor.nil?
  when Kameleoon::Targeting::ConditionType::DEVICE_TYPE
    condition_data = visitor.device unless visitor.nil?
  when Kameleoon::Targeting::ConditionType::BROWSER
    condition_data = visitor.browser unless visitor.nil?
  when Kameleoon::Targeting::ConditionType::COOKIE
    condition_data = visitor.cookie unless visitor.nil?
  when Kameleoon::Targeting::ConditionType::GEOLOCATION
    condition_data = visitor.geolocation unless visitor.nil?
  when Kameleoon::Targeting::ConditionType::OPERATING_SYSTEM
    condition_data = visitor.operating_system unless visitor.nil?
  when Kameleoon::Targeting::ConditionType::SEGMENT
    condition_data = SegmentInfo.new(
      @data_manager.data_file,
      lambda { |type|
        get_condition_data(type, visitor, visitor_code, campaign_id)
      }
    )
  when Kameleoon::Targeting::ConditionType::CONVERSIONS
    condition_data = visitor.conversions unless visitor.nil?
  when Kameleoon::Targeting::ConditionType::SDK_LANGUAGE
    condition_data = Kameleoon::Targeting::SdkInfo.new(Kameleoon::SDK_NAME, Kameleoon::SDK_VERSION)
  when Kameleoon::Targeting::ConditionType::VISITOR_CODE
    condition_data = visitor_code
  when Kameleoon::Targeting::ConditionType::TARGET_FEATURE_FLAG
    condition_data = TargetFeatureFlagInfo.new(@data_manager.data_file, visitor.variations) unless visitor.nil?
  when Kameleoon::Targeting::ConditionType::EXCLUSIVE_FEATURE_FLAG
    condition_data = ExclusiveFeatureFlagInfo.new(campaign_id, visitor&.variations)
  when ConditionType::FIRST_VISIT,
    ConditionType::LAST_VISIT,
    ConditionType::VISITS,
    ConditionType::SAME_DAY_VISITS,
    ConditionType::NEW_VISITORS
    condition_data = visitor.visitor_visits unless visitor.nil?
  when Kameleoon::Targeting::ConditionType::HEAT_SLICE
    condition_data = visitor&.kcs_heat
  end
  Logging::KameleoonLogger.debug(
    "RETURN: TargetingManager.get_condition_data(type: %s, visitor, visitor_code: '%s', campaign_id: %s) -> " \
      '(condition_data: %s)', type, visitor_code, campaign_id, condition_data
  )
  condition_data
end