@@ -220,8 +220,16 @@ def create_optimizely_decision(user_context, flag_key, decision, reasons, decide
220220 decision_source = decision . source
221221 end
222222
223+ # For holdout decisions, ensure campaign_id is empty string, not nil
224+ campaign_id = nil
225+ if decision_source == Optimizely ::DecisionService ::DECISION_SOURCES [ 'HOLDOUT' ]
226+ campaign_id = ''
227+ elsif experiment
228+ campaign_id = experiment [ 'campaignId' ] || experiment [ 'layerId' ]
229+ end
230+
223231 if !decide_options . include? ( OptimizelyDecideOption ::DISABLE_DECISION_EVENT ) && ( decision_source == Optimizely ::DecisionService ::DECISION_SOURCES [ 'FEATURE_TEST' ] || decision_source == Optimizely ::DecisionService ::DECISION_SOURCES [ 'HOLDOUT' ] || config . send_flag_decisions )
224- send_impression ( config , experiment , variation_key || '' , flag_key , rule_key || '' , feature_enabled , decision_source , user_id , attributes , decision &.cmab_uuid )
232+ send_impression ( config , experiment , variation_key || '' , flag_key , rule_key || '' , feature_enabled , decision_source , user_id , attributes , decision &.cmab_uuid , campaign_id )
225233 decision_event_dispatched = true
226234 end
227235
@@ -1274,10 +1282,8 @@ def send_impression(config, experiment, variation_key, flag_key, rule_key, enabl
12741282 # For holdout decisions, filter attributes to only include $opt_bot_filtering
12751283 filtered_attributes = attributes
12761284 if rule_type == Optimizely ::DecisionService ::DECISION_SOURCES [ 'HOLDOUT' ]
1277- filtered_attributes = { }
1278- if attributes && attributes . is_a? ( Hash )
1279- filtered_attributes [ '$opt_bot_filtering' ] = attributes [ '$opt_bot_filtering' ] if attributes [ '$opt_bot_filtering' ]
1280- end
1285+ bot_filtering = attributes &.dig ( '$opt_bot_filtering' )
1286+ filtered_attributes = bot_filtering ? { '$opt_bot_filtering' => bot_filtering } : { }
12811287 end
12821288
12831289 metadata = {
@@ -1286,7 +1292,7 @@ def send_impression(config, experiment, variation_key, flag_key, rule_key, enabl
12861292 rule_type : rule_type ,
12871293 variation_key : variation_key
12881294 }
1289-
1295+
12901296 # Only include enabled field for non-holdout rule types
12911297 metadata [ :enabled ] = enabled unless rule_type == Optimizely ::DecisionService ::DECISION_SOURCES [ 'HOLDOUT' ]
12921298 metadata [ :cmab_uuid ] = cmab_uuid unless cmab_uuid . nil?
0 commit comments