hi guys, I'm currently trying to connect Growthboo...
# experimentation
l
hi guys, I'm currently trying to connect Growthbook to backend application with Java SDK. I have few questions about the setup: 1. In experiment, I want to test two value A or B, how should I set the variations? Is it true true, true false, false true, or false false? 2. Growthbook will determine which user get A or B by hash value on id. Is it correct to setup UserContext first, then call gb.isOn ? I don't see any usage of boolean showNewFeature, instead it hard coded to blue?
UserContext user1Context = UserContext.builder()
.attributesJson("{\"id\":\"user_123\",\"country\":\"US\",\"premium\":true}")
.build();
_boolean_ showNewFeature = gb.isOn("new-homepage", user1Context);
String buttonColor = gb.getFeatureValue("button-color", "blue", user1Context);
p
Hi 1) If you're testing two string values (like A/B copy or colors), set variations as strings like
["blue", "green"]
. The
true/false
combos are only for boolean feature flags, not really useful for A/B. 2) You're right, that's just a misleading example in the docs.
showNewFeature
is declared but never used, which is confusing. The pattern is correct though: build
UserContext
first, then call
getFeatureValue
to get the actual variation value for that user. The
"blue"
is just the default fallback if the user isn't in the experiment. FYI:
_boolean_ showNewFeature = gb.isOn("new-homepage", user1Context);
- Returns true if the value is a truthy value;
String buttonColor = gb.getFeatureValue("button-color", "blue", user1Context);
- Returns the value cast to the generic type. Type is inferred based on the
defaultValue
argument provided. Docs
l
1. ok clear, if want to use it as feature flag, then can set the value as
true/false
2. for the
gb.isOn
will determine if it's a truthy value.. then, if use the same id value for example
"test"
will it always return the same true/false or can be on first second attempt true, and third attempt false?
p
Same id will always return the same value. GrowthBook hashes the user id to assign a variation, so as long as the feature config doesn't change, "test" will always get the same result.
l
thanks @powerful-spoon-16837