Class: Optimizely::EventBuilderV2

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

Constant Summary collapse

CONVERSION_EVENT_ENDPOINT =
'https://p13nlog.dz.optimizely.com/log/event'
IMPRESSION_EVENT_ENDPOINT =
'https://p13nlog.dz.optimizely.com/log/decision'
POST_HEADERS =
{ 'Content-Type' => 'application/json' }

Instance Attribute Summary

Attributes inherited from BaseEventBuilder

#bucketer, #config, #params

Instance Method Summary collapse

Methods inherited from BaseEventBuilder

#initialize

Constructor Details

This class inherits a constructor from Optimizely::BaseEventBuilder

Instance Method Details

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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/optimizely/event_builder.rb', line 77

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 - Event 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 event
  #
  # Returns event hash encapsulating the conversion event.

  @params = {}
  add_common_params(user_id, attributes)
  add_conversion_event(event_key, event_value)
  add_layer_states(user_id, experiment_keys)
  Event.new(:post, CONVERSION_EVENT_ENDPOINT, @params, POST_HEADERS)
end

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/optimizely/event_builder.rb', line 60

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_decision(experiment_key, variation_id)
  add_attributes(attributes)
  Event.new(:post, IMPRESSION_EVENT_ENDPOINT, @params, POST_HEADERS)
end