Skip to content

Commit

Permalink
feat(decide): add a new set of decide apis (#373)
Browse files Browse the repository at this point in the history
Add a new set of decide apis

- add OptimizelyUserContext (setAttribute/decide/decideAll)
- add OptimizelyDecision
- add "createUserContext" to OptimizelyClient
  • Loading branch information
jaeopt authored Jan 23, 2021
1 parent faafa82 commit 3b31260
Show file tree
Hide file tree
Showing 66 changed files with 4,487 additions and 588 deletions.
25 changes: 14 additions & 11 deletions DemoObjCApp/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2019-2020, Optimizely, Inc. and contributors *
* Copyright 2019-2021, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand All @@ -24,21 +24,23 @@

static NSString * const kOptimizelySdkKey = @"FCnSegiEkRry9rhVMroit4";
static NSString * const kOptimizelyDatafileName = @"demoTestDatafile";
static NSString * const kOptimizelyExperimentKey = @"background_experiment";
static NSString * const kOptimizelyFeatureKey = @"decide_demo";
static NSString * const kOptimizelyExperimentKey = @"background_experiment_decide";
static NSString * const kOptimizelyEventKey = @"sample_conversion";

@interface AppDelegate ()
@property(nonnull, strong, nonatomic) NSString *userId;
@property(nonnull, strong, nonatomic) NSDictionary *attributes;
@property(nullable, strong, nonatomic) OptimizelyClient *optimizely;
@property(nullable, strong, nonatomic) OptimizelyUserContext *user;
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.userId = [NSString stringWithFormat:@"%d", arc4random_uniform(300000)];
self.attributes = @{ @"browser_type": @"safari" };
self.attributes = @{ @"location": @"CA", @"semanticVersioning": @"1.2"};

// initialize SDK in one of these two ways:
// (1) asynchronous SDK initialization (RECOMMENDED)
Expand Down Expand Up @@ -134,6 +136,7 @@ -(void)initializeOptimizelySDKWithCustomization {

// For sample codes for APIs, see "Samples/SamplesForAPI.swift"
//[SamplesForAPI checkOptimizelyConfig:self.optimizely];
//[SamplesForAPI checkOptimizelyUserContext:self.optimizely];
}];
}

Expand Down Expand Up @@ -166,16 +169,16 @@ -(void)startWithRootViewController {
dispatch_async(dispatch_get_main_queue(), ^{
// For sample codes for other APIs, see "Samples/SamplesForAPI.m"

NSError *error;
NSString *variationKey = [self.optimizely activateWithExperimentKey:kOptimizelyExperimentKey
userId:self.userId
attributes:self.attributes
error:&error];
self.user = [self.optimizely createUserContextWithUserId:self.userId
attributes:self.attributes];

OptimizelyDecision *decision = [self.user decideWithKey:kOptimizelyFeatureKey
options:@[@(OptimizelyDecideOptionIncludeReasons)]];

if (variationKey != nil) {
[self openVariationViewWithVariationKey:variationKey];
if (decision.variationKey != nil) {
[self openVariationViewWithVariationKey:decision.variationKey];
} else {
NSLog(@"Optimizely SDK activation failed: %@", error.localizedDescription);
NSLog(@"Optimizely SDK activation failed: %@", decision.reasons);
[self openFailureView];
}
});
Expand Down
32 changes: 31 additions & 1 deletion DemoObjCApp/DemoObjcApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@
remoteGlobalIDString = 6E614DCC21E3F389005982A1;
remoteInfo = "OptimizelySwiftSDK-tvOS";
};
6EF41A992523D23E00EAADF1 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 6E4D2FE722C5457F00062EB3 /* OptimizelySwiftSDK.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = BD6485812491474500F30986;
remoteInfo = "OptimizelySwiftSDK-macOS";
};
6EF41A9B2523D23E00EAADF1 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 6E4D2FE722C5457F00062EB3 /* OptimizelySwiftSDK.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 6E14CD632423F80B00010234;
remoteInfo = "OptimizelyTests-Batch-iOS";
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -218,8 +232,10 @@
children = (
6E4D2FF722C5457F00062EB3 /* Optimizely.framework */,
6E4D2FF922C5457F00062EB3 /* Optimizely.framework */,
6EF41A9A2523D23E00EAADF1 /* Optimizely.framework */,
6E4D2FFB22C5457F00062EB3 /* OptimizelyTests-iOS.xctest */,
6E4D2FFD22C5457F00062EB3 /* OptimizelyTests-Common-iOS.xctest */,
6EF41A9C2523D23E00EAADF1 /* OptimizelyTests-Batch-iOS.xctest */,
6E4D2FFF22C5457F00062EB3 /* OptimizelyTests-APIs-iOS.xctest */,
6E4D300122C5457F00062EB3 /* OptimizelyTests-DataModel-iOS.xctest */,
6E4D300322C5457F00062EB3 /* OptimizelyTests-Others-iOS.xctest */,
Expand Down Expand Up @@ -403,7 +419,7 @@
6EF7496721E40467008B22A0 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1010;
LastUpgradeCheck = 1200;
ORGANIZATIONNAME = Optimizely;
TargetAttributes = {
6EF7498D21E404BB008B22A0 = {
Expand Down Expand Up @@ -529,6 +545,20 @@
remoteRef = 6E4D300C22C5457F00062EB3 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
6EF41A9A2523D23E00EAADF1 /* Optimizely.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = Optimizely.framework;
remoteRef = 6EF41A992523D23E00EAADF1 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
6EF41A9C2523D23E00EAADF1 /* OptimizelyTests-Batch-iOS.xctest */ = {
isa = PBXReferenceProxy;
fileType = wrapper.cfbundle;
path = "OptimizelyTests-Batch-iOS.xctest";
remoteRef = 6EF41A9B2523D23E00EAADF1 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading

0 comments on commit 3b31260

Please sign in to comment.