Class: Optimizely::UserEventFactory

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

Class Method Summary collapse

Class Method Details

.create_conversion_event(project_config, event, user_id, user_attributes, event_tags) ⇒ Object



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
# File 'lib/optimizely/event/user_event_factory.rb', line 57

def self.create_conversion_event(project_config, event, user_id, user_attributes, event_tags)
  # Create conversion Event to be sent to the logging endpoint.
  #
  # project_config - Instance of ProjectConfig
  # event - Event which needs to be recorded.
  # user_id - String ID for user.
  # attributes - Hash Representing user attributes and values which need to be recorded.
  # event_tags - Hash representing metadata associated with the event.
  #
  # Returns Event encapsulating the conversion event.

  event_context = Optimizely::EventContext.new(
    account_id: project_config.,
    project_id: project_config.project_id,
    anonymize_ip: project_config.anonymize_ip,
    revision: project_config.revision,
    client_name: CLIENT_ENGINE,
    client_version: VERSION
  ).as_json

  Optimizely::ConversionEvent.new(
    event_context: event_context,
    event: event,
    user_id: user_id,
    visitor_attributes: Optimizely::EventFactory.build_attribute_list(user_attributes, project_config),
    tags: event_tags,
    bot_filtering: project_config.bot_filtering
  )
end

.create_impression_event(project_config, experiment, variation_id, user_id, user_attributes) ⇒ Object

UserEventFactory builds ImpressionEvent and ConversionEvent objects from a given user_event.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/optimizely/event/user_event_factory.rb', line 25

def self.create_impression_event(project_config, experiment, variation_id, user_id, user_attributes)
  # Create impression Event to be sent to the logging endpoint.
  #
  # project_config - Instance of ProjectConfig
  # experiment -   Instance Experiment for which impression needs to be recorded.
  # variation_id - String ID for variation which would be presented to user.
  # user_id -      String ID for user.
  # attributes -   Hash Representing user attributes and values which need to be recorded.
  #
  # Returns Event encapsulating the impression event.
  event_context = Optimizely::EventContext.new(
    account_id: project_config.,
    project_id: project_config.project_id,
    anonymize_ip: project_config.anonymize_ip,
    revision: project_config.revision,
    client_name: CLIENT_ENGINE,
    client_version: VERSION
  ).as_json

  visitor_attributes = Optimizely::EventFactory.build_attribute_list(user_attributes, project_config)
  experiment_layer_id = project_config.experiment_key_map[experiment['key']]['layerId']
  Optimizely::ImpressionEvent.new(
    event_context: event_context,
    user_id: user_id,
    experiment_layer_id: experiment_layer_id,
    experiment_id: experiment['id'],
    variation_id: variation_id,
    visitor_attributes: visitor_attributes,
    bot_filtering: project_config.bot_filtering
  )
end