Module: VWO::Utils::Impression
- Included in:
- VWO, CustomDimensions
- Defined in:
- lib/vwo/utils/impression.rb
Constant Summary
Constants included from CONSTANTS
CONSTANTS::API_VERSION, CONSTANTS::DEFAULT_EVENTS_PER_REQUEST, CONSTANTS::DEFAULT_REQUEST_TIME_INTERVAL, CONSTANTS::GOAL_TYPES, CONSTANTS::HTTPS_PROTOCOL, CONSTANTS::HTTP_PROTOCOL, CONSTANTS::LIBRARY_PATH, CONSTANTS::MAX_EVENTS_PER_REQUEST, CONSTANTS::MAX_RANGE, CONSTANTS::MAX_TRAFFIC_PERCENT, CONSTANTS::MAX_TRAFFIC_VALUE, CONSTANTS::MIN_EVENTS_PER_REQUEST, CONSTANTS::MIN_REQUEST_TIME_INTERVAL, CONSTANTS::PLATFORM, CONSTANTS::RUBY_VARIABLE_TYPES, CONSTANTS::SDK_NAME, CONSTANTS::SDK_VERSION, CONSTANTS::SEED_VALUE, CONSTANTS::STATUS_RUNNING, CONSTANTS::URL_NAMESPACE, CONSTANTS::VWO_DELIMITER
Constants included from UUID
Instance Method Summary collapse
-
#create_bulk_event_impression(settings_file, campaign_id, variation_id, user_id, goal_id = nil, revenue = nil, event_properties = {}, options = {}) ⇒ Object
Creates properties for the bulk impression event.
-
#create_impression(settings_file, campaign_id, variation_id, user_id, sdk_key, goal_id = nil, revenue = nil, usage_stats = {}) ⇒ Object
Creates the impression from the arguments passed.
- #get_batch_event_query_params(account_id, sdk_key, usage_stats = {}) ⇒ Object
-
#get_common_properties(user_id, settings_file) ⇒ Object
Returns commonly used params for making requests to our servers.
-
#get_event_base_payload(settings_file, user_id, event_name, _usage_stats = {}) ⇒ Object
Builds generic payload required by all the different tracking calls.
-
#get_events_base_properties(settings_file, event_name, usage_stats = {}) ⇒ Object
Builds generic properties for different tracking calls required by VWO servers.
-
#get_push_payload_data(settings_file, user_id, event_name, custom_dimension_map = {}) ⇒ Object
Builds payload to appply post segmentation on VWO campaign reports.
-
#get_track_goal_payload_data(settings_file, user_id, event_name, revenue_value, metric_map, revenue_props = [], event_properties) ⇒ Object
Builds payload to track the Goal.
-
#get_track_user_payload_data(settings_file, user_id, event_name, campaign_id, variation_id, _usage_stats = {}) ⇒ Object
Builds payload to track the visitor.
Methods included from Utility
#convert_to_symbol_hash, #get_url, #get_variation_identifiers, #prepare_push_response, #remove_sensitive_properties
Methods included from VWO::Utils
#valid_campaign_for_track_api?, #valid_track_api_params?
Methods included from Validations
#invalid_config_log, #valid_basic_data_type?, #valid_batch_event_settings, #valid_boolean?, #valid_config_log, #valid_goal?, #valid_hash?, #valid_number?, #valid_settings_file?, #valid_string?, #valid_value?, #validate_sdk_config?
Methods included from UUID
#generate, #generator_for, parse, uuid_v5
Methods included from Function
#get_current_unix_timestamp, #get_current_unix_timestamp_in_millis, #get_key_value, #get_random_number
Instance Method Details
#create_bulk_event_impression(settings_file, campaign_id, variation_id, user_id, goal_id = nil, revenue = nil, event_properties = {}, options = {}) ⇒ Object
Creates properties for the bulk impression event
@param :settings_file Settings file object @param :campaign_id Campaign identifier @param :variation_id Variation identifier @param :user_id User identifier @param :sdk_key SDK Key @param :goal_id Goal identifier, if building track impression @param[String|Float|Integer|nil) :revenue Number value, in any representation, if building track impression
@return None if campaign ID or variation ID is invalid,
Else Properties(dict)
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/vwo/utils/impression.rb', line 128 def create_bulk_event_impression(settings_file, campaign_id, variation_id, user_id, goal_id = nil, revenue = nil, event_properties = {} , = {}) return unless valid_number?(campaign_id) && valid_string?(user_id) is_track_user_api = true is_track_user_api = false unless goal_id.nil? account_id = settings_file['accountId'] impression = { eT: is_track_user_api ? 1 : 2, e: campaign_id, c: variation_id, u: generator_for(user_id, account_id, true), sId: } # Check if user_agent is provided if [:user_agent] impression['visitor_ua'] = [:user_agent] end # Check if user_ip_address is provided if [:user_ip_address] impression['visitor_ip'] = [:user_ip_address] end if is_track_user_api Logger.log( LogLevelEnum::DEBUG, 'IMPRESSION_FOR_TRACK_USER', { '{file}' => FileNameEnum::IMPRESSION_UTIL, '{properties}' => remove_sensitive_properties(impression) } ) else impression['g'] = goal_id impression['r'] = revenue if revenue if settings_file.key?('isEventArchEnabled') && settings_file['isEventArchEnabled'] impression['eventProps'] = event_properties end Logger.log( LogLevelEnum::DEBUG, 'IMPRESSION_FOR_TRACK_GOAL', { '{file}' => FileNameEnum::IMPRESSION_UTIL, '{properties}' => JSON.generate(impression) } ) end impression end |
#create_impression(settings_file, campaign_id, variation_id, user_id, sdk_key, goal_id = nil, revenue = nil, usage_stats = {}) ⇒ Object
Creates the impression from the arguments passed
@param :settings_file Settings file object @param :campaign_id Campaign identifier @param :variation_id Variation identifier @param :user_id User identifier @param :sdk_key SDK Key @param :goal_id Goal identifier, if building track impression @param[String|Float|Integer|nil) :revenue Number value, in any representation, if building track impression
@return None if campaign ID or variation ID is invalid,
Else Properties(dict)
46 47 48 49 50 51 52 53 54 55 56 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 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/vwo/utils/impression.rb', line 46 def create_impression(settings_file, campaign_id, variation_id, user_id, sdk_key, goal_id = nil, revenue = nil, usage_stats = {}) return unless valid_number?(campaign_id) && valid_string?(user_id) is_track_user_api = true is_track_user_api = false unless goal_id.nil? account_id = settings_file['accountId'] impression = { account_id: account_id, experiment_id: campaign_id, ap: PLATFORM, combination: variation_id, random: get_random_number, sId: , u: generator_for(user_id, account_id, true), env: sdk_key } # Version and SDK constants sdk_version = Gem.loaded_specs['vwo_sdk'] ? Gem.loaded_specs['vwo_sdk'].version : VWO::SDK_VERSION impression['sdk'] = 'ruby' impression['sdk-v'] = sdk_version impression = usage_stats.merge(impression) if is_track_user_api impression['ed'] = JSON.generate(p: 'server') impression['url'] = HTTPS_PROTOCOL + get_url(ENDPOINTS::TRACK_USER) Logger.log( LogLevelEnum::DEBUG, 'IMPRESSION_FOR_TRACK_USER', { '{file}' => FileNameEnum::IMPRESSION_UTIL, '{properties}' => remove_sensitive_properties(impression) } ) else impression['url'] = HTTPS_PROTOCOL + get_url(ENDPOINTS::TRACK_GOAL) impression['goal_id'] = goal_id impression['r'] = revenue if revenue Logger.log( LogLevelEnum::DEBUG, 'IMPRESSION_FOR_TRACK_GOAL', { '{file}' => FileNameEnum::IMPRESSION_UTIL, '{properties}' => JSON.generate(impression) } ) end impression end |
#get_batch_event_query_params(account_id, sdk_key, usage_stats = {}) ⇒ Object
357 358 359 360 361 362 363 364 |
# File 'lib/vwo/utils/impression.rb', line 357 def get_batch_event_query_params(account_id, sdk_key, usage_stats = {}) { a: account_id, sd: SDK_NAME, sv: SDK_VERSION, env: sdk_key }.merge(usage_stats) end |
#get_common_properties(user_id, settings_file) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/vwo/utils/impression.rb', line 103 def get_common_properties(user_id, settings_file) account_id = settings_file['accountId'] { 'random' => get_random_number, 'sdk' => SDK_NAME, 'sdk-v' => SDK_VERSION, 'ap' => PLATFORM, 'sId' => , 'u' => generator_for(user_id, account_id, true), 'account_id' => account_id } end |
#get_event_base_payload(settings_file, user_id, event_name, _usage_stats = {}) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/vwo/utils/impression.rb', line 210 def get_event_base_payload(settings_file, user_id, event_name, _usage_stats = {}) uuid = generator_for(user_id, (settings_file['accountId']), true) sdk_key = settings_file['sdkKey'] props = { vwo_sdkName: SDK_NAME, vwo_sdkVersion: SDK_VERSION, } # if usage_stats # props = props.merge(_usage_stats) # end { d: { msgId: "#{uuid}-#{get_current_unix_timestamp_in_millis}", visId: uuid, sessionId: Time.now.to_i, event: { props: props, name: event_name, time: }, visitor: { props: { vwo_fs_environment: sdk_key } } } } end |
#get_events_base_properties(settings_file, event_name, usage_stats = {}) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/vwo/utils/impression.rb', line 188 def get_events_base_properties(settings_file, event_name, usage_stats = {}) properties = { en: event_name, a: settings_file['accountId'], env: settings_file['sdkKey'], eTime: , random: get_random_number, p: 'FS' } properties = properties.merge(usage_stats) if event_name == EventEnum::VWO_VARIATION_SHOWN properties end |
#get_push_payload_data(settings_file, user_id, event_name, custom_dimension_map = {}) ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/vwo/utils/impression.rb', line 335 def get_push_payload_data(settings_file, user_id, event_name, custom_dimension_map = {}) properties = get_event_base_payload(settings_file, user_id, event_name) properties[:d][:event][:props][:isCustomEvent] = true custom_dimension_map.each do |tag_key, tag_value| properties[:d][:event][:props][tag_key] = tag_value properties[:d][:visitor][:props][tag_key] = tag_value end Logger.log( LogLevelEnum::DEBUG, 'IMPRESSION_FOR_EVENT_ARCH_PUSH', { '{file}' => FileNameEnum::IMPRESSION_UTIL, '{accountId}' => settings_file['accountId'], '{userId}' => user_id, '{property}' => JSON.generate(custom_dimension_map) } ) properties end |
#get_track_goal_payload_data(settings_file, user_id, event_name, revenue_value, metric_map, revenue_props = [], event_properties) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/vwo/utils/impression.rb', line 286 def get_track_goal_payload_data(settings_file, user_id, event_name, revenue_value, metric_map, revenue_props = [], event_properties) properties = get_event_base_payload(settings_file, user_id, event_name) metric = {} metric_map.each do |campaign_id, goal_id| metric["id_#{campaign_id}".to_sym] = ["g_#{goal_id}"] Logger.log( LogLevelEnum::DEBUG, 'IMPRESSION_FOR_EVENT_ARCH_TRACK_GOAL', { '{file}' => FileNameEnum::IMPRESSION_UTIL, '{accountId}' => settings_file['accountId'], '{goalName}' => event_name, '{userId}' => user_id, '{campaignId}' => campaign_id.to_s } ) end properties[:d][:event][:props][:vwoMeta] = { metric: metric } if revenue_props.length != 0 && revenue_value revenue_props.each do |revenue_prop| properties[:d][:event][:props][:vwoMeta][revenue_prop.to_sym] = revenue_value end end properties[:d][:event][:props][:isCustomEvent] = true if event_properties && event_properties.any? event_properties.each do |prop, value| properties[:d][:event][:props][prop] = value end end properties end |
#get_track_user_payload_data(settings_file, user_id, event_name, campaign_id, variation_id, _usage_stats = {}) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/vwo/utils/impression.rb', line 253 def get_track_user_payload_data(settings_file, user_id, event_name, campaign_id, variation_id, _usage_stats = {}) properties = get_event_base_payload(settings_file, user_id, event_name) properties[:d][:event][:props][:id] = campaign_id properties[:d][:event][:props][:variation] = variation_id # this is currently required by data-layer team, we can make changes on DACDN and remove it from here properties[:d][:event][:props][:isFirst] = 1 Logger.log( LogLevelEnum::DEBUG, 'IMPRESSION_FOR_EVENT_ARCH_TRACK_USER', { '{file}' => FileNameEnum::IMPRESSION_UTIL, '{accountId}' => settings_file['accountId'], '{userId}' => user_id, '{campaignId}' => campaign_id.to_s } ) properties end |