class Optimizely::UserEventFactory
Public Class Methods
create_conversion_event(project_config, event, user_id, user_attributes, event_tags)
click to toggle source
# File lib/optimizely/event/user_event_factory.rb, line 58 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.account_id, 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, metadata, user_id, user_attributes)
click to toggle source
UserEventFactory
builds ImpressionEvent
and ConversionEvent
objects from a given user_event.
# File lib/optimizely/event/user_event_factory.rb, line 25 def self.create_impression_event(project_config, experiment, variation_id, metadata, 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.account_id, 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 = experiment['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, metadata: metadata, visitor_attributes: visitor_attributes, bot_filtering: project_config.bot_filtering ) end