Class: Optimizely::EventBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/optimizely/event_builder.rb

Constant Summary collapse

ATTRIBUTE_PARAM_FORMAT =

Attribute mapping format

'%{segment_prefix}%{segment_id}'
EXPERIMENT_PARAM_FORMAT =

Experiment mapping format

'%{experiment_prefix}%{experiment_id}'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, bucketer) ⇒ EventBuilder

Returns a new instance of EventBuilder.



43
44
45
46
47
# File 'lib/optimizely/event_builder.rb', line 43

def initialize(config, bucketer)
  @config = config
  @bucketer = bucketer
  @params = {}
end

Instance Attribute Details

#bucketerObject

Returns the value of attribute bucketer.



40
41
42
# File 'lib/optimizely/event_builder.rb', line 40

def bucketer
  @bucketer
end

#configObject

Returns the value of attribute config.



39
40
41
# File 'lib/optimizely/event_builder.rb', line 39

def config
  @config
end

#paramsObject

Returns the value of attribute params.



41
42
43
# File 'lib/optimizely/event_builder.rb', line 41

def params
  @params
end

Instance Method Details

#create_conversion_event(event_key, user_id, attributes, event_value, experiment_keys) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/optimizely/event_builder.rb', line 66

def create_conversion_event(event_key, user_id, attributes, event_value, experiment_keys)
  # Create conversion Event to be sent to the logging endpoint.
  #
  # event_key - Goal key representing the event which needs to be recorded.
  # user_id - ID for user.
  # attributes - Hash representing user attributes and values which need to be recorded.
  # event_value - Value associated with the event. Can be used to represent revenue in cents.
  # experiment_keys - Array of valid experiment keys for the goal

  @params = {}
  add_common_params(user_id, attributes)
  add_conversion_goal(event_key, event_value)
  add_experiment_variation_params(user_id, experiment_keys)
  Event.new(@params)
end

#create_impression_event(experiment_key, variation_id, user_id, attributes) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/optimizely/event_builder.rb', line 49

def create_impression_event(experiment_key, variation_id, user_id, attributes)
  # Create conversion Event to be sent to the logging endpoint.
  #
  # experiment_key - Experiment for which impression needs to be recorded.
  # variation_id - ID for variation which would be presented to user.
  # user_id - ID for user.
  # attributes - Hash representing user attributes and values which need to be recorded.
  #
  # Returns event hash encapsulating the impression event.

  @params = {}
  add_common_params(user_id, attributes)
  add_impression_goal(experiment_key)
  add_experiment(experiment_key, variation_id)
  Event.new(@params)
end