@@ -286,11 +286,11 @@ - (BOOL)isFeatureEnabled:(NSString *)featureKey userId:(NSString *)userId attrib
286
286
return result;
287
287
}
288
288
289
- - (NSString * )getFeatureVariableValueForType : (NSString *)variableType
290
- featureKey : (nullable NSString *)featureKey
291
- variableKey : (nullable NSString *)variableKey
292
- userId : (nullable NSString *)userId
293
- attributes : (nullable NSDictionary <NSString *, id> *)attributes {
289
+ - (id )getFeatureVariableValueForType : (NSString *)variableType
290
+ featureKey : (nullable NSString *)featureKey
291
+ variableKey : (nullable NSString *)variableKey
292
+ userId : (nullable NSString *)userId
293
+ attributes : (nullable NSDictionary <NSString *, id> *)attributes {
294
294
295
295
NSMutableDictionary <NSString *, NSString *> *inputValues = [[NSMutableDictionary alloc ] initWithDictionary: @{
296
296
OPTLYNotificationUserIdKey:[self ObjectOrNull: userId],
@@ -321,13 +321,19 @@ - (NSString *)getFeatureVariableValueForType:(NSString *)variableType
321
321
return nil ;
322
322
}
323
323
324
+ NSMutableDictionary *decisionInfo = [NSMutableDictionary new ];
325
+ [decisionInfo setValue: [NSNull null ] forKey: DecisionInfo.SourceExperimentKey];
326
+ [decisionInfo setValue: [NSNull null ] forKey: DecisionInfo.SourceVariationKey];
327
+
324
328
NSString *variableValue = featureVariable.defaultValue ;
325
329
OPTLYFeatureDecision *decision = [self .decisionService getVariationForFeature: featureFlag userId: userId attributes: attributes];
326
-
327
330
if (decision) {
331
+ if ([decision.source isEqualToString: DecisionSource.Experiment]) {
332
+ [decisionInfo setValue: decision.experiment.experimentKey forKey: DecisionInfo.SourceExperimentKey];
333
+ [decisionInfo setValue: decision.variation.variationKey forKey: DecisionInfo.SourceVariationKey];
334
+ }
328
335
OPTLYVariation *variation = decision.variation ;
329
336
OPTLYVariableUsage *featureVariableUsage = [variation getVariableUsageForVariableId: featureVariable.variableId];
330
-
331
337
if (featureVariableUsage) {
332
338
if (variation.featureEnabled ) {
333
339
variableValue = featureVariableUsage.value ;
@@ -346,23 +352,47 @@ - (NSString *)getFeatureVariableValueForType:(NSString *)variableType
346
352
[self .logger logMessage: logMessage withLevel: OptimizelyLogLevelInfo];
347
353
}
348
354
349
- return variableValue;
355
+ id finalValue = nil ;
356
+ if (variableValue) {
357
+ if ([variableType isEqualToString: FeatureVariableTypeBoolean]) {
358
+ finalValue = [NSNumber numberWithBool: [variableValue boolValue ]];
359
+ } else if ([variableType isEqualToString: FeatureVariableTypeDouble]) {
360
+ finalValue = [NSNumber numberWithDouble: [variableValue doubleValue ]];
361
+ } else if ([variableType isEqualToString: FeatureVariableTypeInteger]) {
362
+ finalValue = [NSNumber numberWithDouble: [variableValue intValue ]];
363
+ } else if ([variableType isEqualToString: FeatureVariableTypeString]) {
364
+ finalValue = variableValue;
365
+ }
366
+ }
367
+
368
+ NSMutableDictionary *args = [[NSMutableDictionary alloc ] init ];
369
+ [args setValue: OPTLYDecisionTypeFeatureVariable forKey: OPTLYNotificationDecisionTypeKey];
370
+ [args setValue: userId forKey: OPTLYNotificationUserIdKey];
371
+ [args setValue: attributes forKey: OPTLYNotificationAttributesKey];
372
+
373
+ [decisionInfo setValue: featureKey forKey: DecisionInfo.FeatureKey];
374
+ [decisionInfo setValue: [NSNumber numberWithBool: decision.variation.featureEnabled] forKey: DecisionInfo.FeatureEnabledKey];
375
+ [decisionInfo setValue: variableKey forKey: DecisionInfo.VariableKey];
376
+ [decisionInfo setValue: variableType forKey: DecisionInfo.VariableTypeKey];
377
+ [decisionInfo setValue: finalValue forKey: DecisionInfo.VariableValueKey];
378
+ [decisionInfo setValue: decision.source forKey: DecisionInfo.SourceKey];
379
+ [args setValue: decisionInfo forKey: DecisionInfo.Key];
380
+
381
+ [_notificationCenter sendNotifications: OPTLYNotificationTypeDecision args: args];
382
+
383
+ return finalValue;
350
384
}
351
385
352
386
- (NSNumber *)getFeatureVariableBoolean : (nullable NSString *)featureKey
353
387
variableKey : (nullable NSString *)variableKey
354
388
userId : (nullable NSString *)userId
355
389
attributes : (nullable NSDictionary <NSString *, id> *)attributes {
356
390
357
- NSString *variableValue = [self getFeatureVariableValueForType: FeatureVariableTypeBoolean
391
+ NSNumber * booleanValue = [self getFeatureVariableValueForType: FeatureVariableTypeBoolean
358
392
featureKey: featureKey
359
393
variableKey: variableKey
360
394
userId: userId
361
395
attributes: attributes];
362
- NSNumber * booleanValue = nil ;
363
- if (variableValue) {
364
- booleanValue = @([variableValue boolValue ]);
365
- }
366
396
return booleanValue;
367
397
}
368
398
@@ -371,15 +401,11 @@ - (NSNumber *)getFeatureVariableDouble:(nullable NSString *)featureKey
371
401
userId : (nullable NSString *)userId
372
402
attributes : (nullable NSDictionary <NSString *, id> *)attributes {
373
403
374
- NSString *variableValue = [self getFeatureVariableValueForType: FeatureVariableTypeDouble
404
+ NSNumber * doubleValue = [self getFeatureVariableValueForType: FeatureVariableTypeDouble
375
405
featureKey: featureKey
376
406
variableKey: variableKey
377
407
userId: userId
378
408
attributes: attributes];
379
- NSNumber * doubleValue = nil ;
380
- if (variableValue) {
381
- doubleValue = @([variableValue doubleValue ]);
382
- }
383
409
return doubleValue;
384
410
}
385
411
@@ -389,15 +415,11 @@ - (NSNumber *)getFeatureVariableInteger:(nullable NSString *)featureKey
389
415
userId : (nullable NSString *)userId
390
416
attributes : (nullable NSDictionary <NSString *, id> *)attributes {
391
417
392
- NSString *variableValue = [self getFeatureVariableValueForType: FeatureVariableTypeInteger
418
+ NSNumber * intValue = [self getFeatureVariableValueForType: FeatureVariableTypeInteger
393
419
featureKey: featureKey
394
420
variableKey: variableKey
395
421
userId: userId
396
422
attributes: attributes];
397
- NSNumber * intValue = nil ;
398
- if (variableValue) {
399
- intValue = @([variableValue intValue ]);
400
- }
401
423
return intValue;
402
424
}
403
425
0 commit comments