Class: Optimizely::EventBuilderV1

Inherits:
BaseEventBuilder 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}'
OFFLINE_API_PATH =

Event endpoint path

'https://%{project_id}.log.optimizely.com/event'

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_tags, experiment_keys) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/optimizely/event_builder.rb', line 267

def create_conversion_event(event_key, user_id, attributes, event_tags, 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_tags - Hash representing metadata associated with the event.
  # experiment_keys - Array of valid experiment keys for the goal
  #
  # Returns event hash encapsulating the conversion event.

  @params = {}

  event_value = Helpers::EventTagUtils.get_revenue_value(event_tags)

  add_common_params(user_id, attributes)
  add_conversion_goal(event_key, event_value)
  add_experiment_variation_params(user_id, experiment_keys)
  Event.new(:get, sprintf(OFFLINE_API_PATH, project_id: @params[Params::PROJECT_ID]), @params, {})
end

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



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/optimizely/event_builder.rb', line 250

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(:get, sprintf(OFFLINE_API_PATH, project_id: @params[Params::PROJECT_ID]), @params, {})
end