17
17
18
18
import com .optimizely .ab .Optimizely ;
19
19
import 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 ;
21
23
22
24
import java .util .Collections ;
23
25
import java .util .Map ;
24
-
25
26
import java .util .Random ;
26
27
import java .util .concurrent .TimeUnit ;
27
28
@@ -33,20 +34,23 @@ private Example(Optimizely optimizely) {
33
34
this .optimizely = optimizely ;
34
35
}
35
36
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 );
38
46
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" );
42
51
}
43
52
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 ());
50
54
}
51
55
}
52
56
@@ -57,7 +61,7 @@ public static void main(String[] args) throws InterruptedException {
57
61
Random random = new Random ();
58
62
59
63
for (int i = 0 ; i < 10 ; i ++) {
60
- String userId = String .valueOf (random .nextInt ());
64
+ String userId = String .valueOf (random .nextInt (Integer . MAX_VALUE ));
61
65
example .processVisitor (userId , Collections .emptyMap ());
62
66
TimeUnit .MILLISECONDS .sleep (500 );
63
67
}
0 commit comments