Class: Optimizely::EventBuilder

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

Constant Summary collapse

ENDPOINTS =
{
  US: 'https://logx.optimizely.com/v1/events',
  EU: 'https://eu.logx.optimizely.com/v1/events'
}.freeze
POST_HEADERS =
{'Content-Type' => 'application/json'}.freeze
ACTIVATE_EVENT_KEY =
'campaign_activated'

Constants inherited from BaseEventBuilder

BaseEventBuilder::CUSTOM_ATTRIBUTE_FEATURE_TYPE

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(project_config, event, user_id, attributes, event_tags) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/optimizely/event_builder.rb', line 139

def create_conversion_event(project_config, event, user_id, attributes, event_tags)
  # Create conversion Event to be sent to the logging endpoint.
  #
  # project_config -           +Object+ Instance of ProjectConfig
  # event -                    +Object+ 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.

  region = project_config.region || 'US'
  event_params = get_common_params(project_config, user_id, attributes)
  conversion_params = get_conversion_params(event, event_tags)
  event_params[:visitors][0][:snapshots] = [conversion_params]

  endpoint = ENDPOINTS[region.to_s.upcase.to_sym]

  Event.new(:post, endpoint, event_params, POST_HEADERS)
end

#create_impression_event(project_config, experiment, variation_id, user_id, attributes) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/optimizely/event_builder.rb', line 118

def create_impression_event(project_config, experiment, variation_id, user_id, attributes)
  # Create impression Event to be sent to the logging endpoint.
  #
  # project_config - +Object+ Instance of ProjectConfig
  # experiment -   +Object+ 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.

  region = project_config.region || 'US'
  event_params = get_common_params(project_config, user_id, attributes)
  impression_params = get_impression_params(project_config, experiment, variation_id)
  event_params[:visitors][0][:snapshots].push(impression_params)

  endpoint = ENDPOINTS[region.to_s.upcase.to_sym]

  Event.new(:post, endpoint, event_params, POST_HEADERS)
end