@@ -39,20 +39,20 @@ class DefaultDecisionService: OPTDecisionService {
39
39
return nil
40
40
}
41
41
42
- // ---- check for whitelisted variation registered at runtime ----
42
+ // ---- check if the user is forced into a variation ----
43
43
if let variationId = config. getForcedVariation ( experimentKey: experiment. key, userId: userId) ? . id,
44
44
let variation = experiment. getVariation ( id: variationId) {
45
45
return variation
46
46
}
47
47
48
- // ---- check if the experiment has forced variation ----
48
+ // ---- check to see if user is white-listed for a certain variation ----
49
49
if let variationKey = experiment. forcedVariations [ userId] {
50
50
if let variation = experiment. getVariation ( key: variationKey) {
51
51
logger. i ( . forcedVariationFound( variationKey, userId) )
52
52
return variation
53
53
}
54
54
55
- // mapped to invalid variation - ignore and continue for other deciesions
55
+ // mapped to invalid variation - ignore and continue for other decisions
56
56
logger. e ( . forcedVariationFoundButInvalid( variationKey, userId) )
57
57
}
58
58
@@ -65,22 +65,26 @@ class DefaultDecisionService: OPTDecisionService {
65
65
66
66
var bucketedVariation : Variation ?
67
67
// ---- check if the user passes audience targeting before bucketing ----
68
- if isInExperiment ( config: config, experiment: experiment, userId: userId, attributes: attributes) {
68
+ if doesMeetAudienceConditions ( config: config, experiment: experiment, userId: userId, attributes: attributes) {
69
69
// bucket user into a variation
70
70
bucketedVariation = bucketer. bucketExperiment ( config: config, experiment: experiment, bucketingId: bucketingId)
71
71
72
72
if let bucketedVariation = bucketedVariation {
73
+ logger. i ( . userBucketedIntoVariationInExperiment( userId, experiment. key, bucketedVariation. key) )
73
74
// save to user profile
74
75
self . saveProfile ( userId: userId, experimentId: experimentId, variationId: bucketedVariation. id)
76
+ } else {
77
+ logger. i ( . userNotBucketedIntoVariation( userId) )
75
78
}
79
+
76
80
} else {
77
81
logger. i ( . userNotInExperiment( userId, experiment. key) )
78
82
}
79
83
80
84
return bucketedVariation
81
85
}
82
86
83
- func isInExperiment ( config: ProjectConfig , experiment: Experiment , userId: String , attributes: OptimizelyAttributes , logType: Constants . EvaluationLogType = . experiment, loggingKey: String ? = nil ) -> Bool {
87
+ func doesMeetAudienceConditions ( config: ProjectConfig , experiment: Experiment , userId: String , attributes: OptimizelyAttributes , logType: Constants . EvaluationLogType = . experiment, loggingKey: String ? = nil ) -> Bool {
84
88
85
89
var result = true // success as default (no condition, etc)
86
90
let evType = logType. rawValue
@@ -133,19 +137,13 @@ class DefaultDecisionService: OPTDecisionService {
133
137
//1. Attempt to bucket user into experiment using feature flag.
134
138
// Check if the feature flag is under an experiment and the the user is bucketed into one of these experiments
135
139
if let pair = getVariationForFeatureExperiment ( config: config, featureFlag: featureFlag, userId: userId, attributes: attributes) {
136
- logger. d ( . userInFeatureExperiment( userId, pair. variation? . key ?? " unknown " , pair. experiment? . key ?? " unknown " , featureFlag. key) )
137
140
return pair
138
- } else {
139
- logger. d ( . userNotInFeatureExperiment( userId, featureFlag. key) )
140
141
}
141
142
142
143
//2. Attempt to bucket user into rollout using the feature flag.
143
144
// Check if the feature flag has rollout and the user is bucketed into one of it's rules
144
145
if let variation = getVariationForFeatureRollout ( config: config, featureFlag: featureFlag, userId: userId, attributes: attributes) {
145
- logger. d ( . userInRollout( userId, featureFlag. key) )
146
146
return ( nil , variation)
147
- } else {
148
- logger. d ( . userNotInRollout( userId, featureFlag. key) )
149
147
}
150
148
151
149
return nil
@@ -202,7 +200,7 @@ class DefaultDecisionService: OPTDecisionService {
202
200
for index in 0 ..< rolloutRules. count. advanced ( by: - 1 ) {
203
201
let loggingKey = index + 1
204
202
let experiment = rolloutRules [ index]
205
- if isInExperiment ( config: config, experiment: experiment, userId: userId, attributes: attributes, logType: . rolloutRule, loggingKey: " \( loggingKey) " ) {
203
+ if doesMeetAudienceConditions ( config: config, experiment: experiment, userId: userId, attributes: attributes, logType: . rolloutRule, loggingKey: " \( loggingKey) " ) {
206
204
logger. d ( . userMeetsConditionsForTargetingRule( userId, loggingKey) )
207
205
if let variation = bucketer. bucketExperiment ( config: config, experiment: experiment, bucketingId: bucketingId) {
208
206
logger. d ( . userBucketedIntoTargetingRule( userId, loggingKey) )
@@ -217,7 +215,7 @@ class DefaultDecisionService: OPTDecisionService {
217
215
// Evaluate fall back rule / last rule now
218
216
let experiment = rolloutRules [ rolloutRules. count - 1 ]
219
217
220
- if isInExperiment ( config: config, experiment: experiment, userId: userId, attributes: attributes, logType: . rolloutRule, loggingKey: " Everyone Else " ) {
218
+ if doesMeetAudienceConditions ( config: config, experiment: experiment, userId: userId, attributes: attributes, logType: . rolloutRule, loggingKey: " Everyone Else " ) {
221
219
if let variation = bucketer. bucketExperiment ( config: config, experiment: experiment, bucketingId: bucketingId) {
222
220
logger. d ( . userBucketedIntoEveryoneTargetingRule( userId) )
223
221
0 commit comments