2222require 'securerandom'
2323
2424module Optimizely
25- RESERVED_ATTRIBUTE_KEY_BUCKETING_ID_EVENT_PARAM_KEY = 'optimizely_bucketing_id'
26-
2725 class Event
2826 # Representation of an event which can be sent to the Optimizely logging endpoint.
2927
@@ -58,6 +56,13 @@ def initialize(config, logger)
5856
5957 private
6058
59+ def bot_filtering
60+ # Get bot filtering bool
61+ #
62+ # Returns 'botFiltering' value in the datafile.
63+ @config . bot_filtering
64+ end
65+
6166 def get_common_params ( user_id , attributes )
6267 # Get params which are used in both conversion and impression events.
6368 #
@@ -69,33 +74,28 @@ def get_common_params(user_id, attributes)
6974 visitor_attributes = [ ]
7075
7176 attributes &.keys &.each do |attribute_key |
72- # Omit null attribute value
77+ # Omit null attribute values
7378 attribute_value = attributes [ attribute_key ]
74- next if attribute_value . nil?
75-
76- if attribute_key . eql? RESERVED_ATTRIBUTE_KEY_BUCKETING_ID
77- # TODO: (Copied from PHP-SDK) (Alda): the type for bucketing ID attribute may change so
78- # that custom attributes are not overloaded
79- feature = {
80- entity_id : RESERVED_ATTRIBUTE_KEY_BUCKETING_ID ,
81- key : RESERVED_ATTRIBUTE_KEY_BUCKETING_ID_EVENT_PARAM_KEY ,
82- type : CUSTOM_ATTRIBUTE_FEATURE_TYPE ,
83- value : attribute_value
84- }
85- else
86- # Skip attributes not in the datafile
87- attribute_id = @config . get_attribute_id ( attribute_key )
88- next unless attribute_id
89-
90- feature = {
91- entity_id : attribute_id ,
92- key : attribute_key ,
93- type : CUSTOM_ATTRIBUTE_FEATURE_TYPE ,
94- value : attribute_value
95- }
96-
79+ unless attribute_value . nil?
80+ attribute_id = @config . get_attribute_id attribute_key
81+ if attribute_id
82+ visitor_attributes . push (
83+ entity_id : attribute_id ,
84+ key : attribute_key ,
85+ type : CUSTOM_ATTRIBUTE_FEATURE_TYPE ,
86+ value : attribute_value
87+ )
88+ end
9789 end
98- visitor_attributes . push ( feature )
90+ end
91+ # Append Bot Filtering Attribute
92+ if bot_filtering == true || bot_filtering == false
93+ visitor_attributes . push (
94+ entity_id : Optimizely ::Helpers ::Constants ::CONTROL_ATTRIBUTES [ 'BOT_FILTERING' ] ,
95+ key : Optimizely ::Helpers ::Constants ::CONTROL_ATTRIBUTES [ 'BOT_FILTERING' ] ,
96+ type : CUSTOM_ATTRIBUTE_FEATURE_TYPE ,
97+ value : bot_filtering
98+ )
9999 end
100100
101101 common_params = {
0 commit comments