1717
1818import com .optimizely .ab .Optimizely ;
1919import com .optimizely .ab .OptimizelyFactory ;
20- import com .optimizely .ab .config .Variation ;
20+ import com .optimizely .ab .OptimizelyUserContext ;
21+ import com .optimizely .ab .optimizelydecision .OptimizelyDecision ;
22+ import com .optimizely .ab .optimizelyjson .OptimizelyJSON ;
2123
2224import java .util .Collections ;
2325import java .util .Map ;
24-
2526import java .util .Random ;
2627import java .util .concurrent .TimeUnit ;
2728
@@ -33,20 +34,23 @@ private Example(Optimizely optimizely) {
3334 this .optimizely = optimizely ;
3435 }
3536
36- private void processVisitor (String userId , Map <String , String > attributes ) {
37- Variation variation = optimizely .activate ("background_experiment" , userId , attributes );
37+ private void processVisitor (String userId , Map <String , Object > attributes ) {
38+ OptimizelyUserContext user = optimizely .createUserContext (userId , attributes );
39+
40+ OptimizelyDecision decision = user .decide ("eet_feature" );
41+ String variationKey = decision .getVariationKey ();
42+
43+ if (variationKey != null ) {
44+ boolean enabled = decision .getEnabled ();
45+ System .out .println ("[Example] feature enabled: " + enabled );
3846
39- if (variation != null ) {
40- optimizely .track ("sample_conversion" , userId , attributes );
41- System .out .println (String .format ("Found variation %s" , variation .getKey ()));
47+ OptimizelyJSON variables = decision .getVariables ();
48+ System .out .println ("[Example] feature variables: " + variables .toString ());
49+
50+ user .trackEvent ("eet_conversion" );
4251 }
4352 else {
44- System .out .println ("didn't get a variation" );
45- }
46-
47- if (optimizely .isFeatureEnabled ("eet_feature" , userId , attributes )) {
48- optimizely .track ("eet_conversion" , userId , attributes );
49- System .out .println ("feature enabled" );
53+ System .out .println ("[Example] decision failed: " + decision .getReasons ().toString ());
5054 }
5155 }
5256
@@ -57,7 +61,7 @@ public static void main(String[] args) throws InterruptedException {
5761 Random random = new Random ();
5862
5963 for (int i = 0 ; i < 10 ; i ++) {
60- String userId = String .valueOf (random .nextInt ());
64+ String userId = String .valueOf (random .nextInt (Integer . MAX_VALUE ));
6165 example .processVisitor (userId , Collections .emptyMap ());
6266 TimeUnit .MILLISECONDS .sleep (500 );
6367 }
0 commit comments