Package growthbook.sdk.java
Class GBContext
java.lang.Object
growthbook.sdk.java.GBContext
Context object passed into the GrowthBook constructor.
The
builder() is recommended for constructing a Context.
Alternatively, you can use the class's constructor.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe builder class to help create a context. -
Constructor Summary
ConstructorsConstructorDescriptionGBContext(String attributesJson, com.google.gson.JsonObject attributes, String featuresJson, com.google.gson.JsonObject features, String encryptionKey, Boolean enabled, Boolean isQaMode, String url, Boolean allowUrlOverrides, Map<String, Integer> forcedVariationsMap, TrackingCallback trackingCallback, FeatureUsageCallback featureUsageCallback, StickyBucketService stickyBucketService, Map<String, StickyAssignmentsDocument> stickyBucketAssignmentDocs, List<String> stickyBucketIdentifierAttributes, com.google.gson.JsonObject savedGroups) TheGBContext.GBContextBuilderis recommended for constructing a Context. -
Method Summary
Modifier and TypeMethodDescriptionstatic GBContext.GBContextBuilderbuilder()The builder class to help create a context.booleanBoolean flag to allow URL overrides (default: false)com.google.gson.JsonObjectMap of user attributes that are used to assign variationsString format of user attributes that are used to assign variationsSwitch to globally disable all experiments.Optional encryption key.com.google.gson.JsonObjectKeys are unique identifiers for the features and the values are Feature objects.A function that takesStringandFeatureResultas arguments.Force specific experiments to always assign a specific variation (used for QA)If true, random assignment is disabled and only explicitly forced variations are used.com.google.gson.JsonObjectMap of Sticky Bucket documentsList of user's attributes keysService that provide functionality of Sticky BucketingA function that takesExperimentandExperimentResultas arguments.getUrl()The URL of the current pageinthashCode()voidsetAllowUrlOverride(Boolean allowUrlOverride) Boolean flag to allow URL overrides (default: false)voidsetAttributes(com.google.gson.JsonObject attributes) You can update the attributes with new user attributes to evaluate against.voidsetAttributesJson(String attributesJson) You can update the attributes JSON with new user attributes to evaluate against.voidsetEnabled(Boolean enabled) Switch to globally disable all experiments.voidsetEncryptionKey(String encryptionKey) Optional encryption key.voidsetExperimentHelper(ExperimentHelper experimentHelper) voidsetFeatures(com.google.gson.JsonObject features) Keys are unique identifiers for the features and the values are Feature objects.voidsetFeaturesJson(String featuresJson) You can update the features JSON with new features to evaluate against.voidsetFeatureUsageCallback(FeatureUsageCallback featureUsageCallback) A function that takesStringandFeatureResultas arguments.voidsetForcedVariationsMap(Map<String, Integer> forcedVariationsMap) Force specific experiments to always assign a specific variation (used for QA)voidsetIsQaMode(Boolean isQaMode) If true, random assignment is disabled and only explicitly forced variations are used.voidsetSavedGroups(com.google.gson.JsonObject savedGroups) voidsetStickyBucketAssignmentDocs(Map<String, StickyAssignmentsDocument> stickyBucketAssignmentDocs) Map of Sticky Bucket documentsvoidsetStickyBucketIdentifierAttributes(List<String> stickyBucketIdentifierAttributes) List of user's attributes keysvoidsetStickyBucketService(StickyBucketService stickyBucketService) Service that provide functionality of Sticky BucketingvoidsetTrackingCallback(TrackingCallback trackingCallback) A function that takesExperimentandExperimentResultas arguments.voidThe URL of the current pagetoString()static com.google.gson.JsonObjecttransformEncryptedFeatures(String featuresJson, String encryptionKey) static com.google.gson.JsonObjecttransformFeatures(String featuresJsonString)
-
Constructor Details
-
GBContext
public GBContext(@Nullable String attributesJson, @Nullable com.google.gson.JsonObject attributes, @Nullable String featuresJson, @Nullable com.google.gson.JsonObject features, @Nullable String encryptionKey, @Nullable Boolean enabled, Boolean isQaMode, @Nullable String url, Boolean allowUrlOverrides, @Nullable Map<String, Integer> forcedVariationsMap, @Nullable TrackingCallback trackingCallback, @Nullable FeatureUsageCallback featureUsageCallback, @Nullable StickyBucketService stickyBucketService, @Nullable Map<String, StickyAssignmentsDocument> stickyBucketAssignmentDocs, @Nullable List<String> stickyBucketIdentifierAttributes, @Nullable com.google.gson.JsonObject savedGroups) TheGBContext.GBContextBuilderis recommended for constructing a Context. Alternatively, you can use this static method instead of the builder.- Parameters:
attributesJson- User attributes as JSON stringattributes- User attributes as JSON Object, either set this or `attributesJson`featuresJson- Features response as JSON string, or the encrypted payload. Encrypted payload requires `encryptionKey`features- Features response as JSON Object, either set this or `featuresJson`encryptionKey- Optional encryption key. If this is not null, featuresJson should be an encrypted payload.enabled- Whether globally all experiments are enabled (default: true)isQaMode- If true, random assignment is disabled and only explicitly forced variations are used.url- A URL string that is used for experiment evaluation, as well as forcing feature values.allowUrlOverrides- Boolean flag to allow URL overrides (default: false)forcedVariationsMap- Force specific experiments to always assign a specific variation (used for QA)trackingCallback- A function that takesExperimentandExperimentResultas arguments.featureUsageCallback- A function that takesStringandFeatureResultas arguments. A callback that will be invoked every time a feature is viewed. Listen for feature usage eventsstickyBucketService- Service that provide functionality of Sticky Bucketing.stickyBucketAssignmentDocs- Map of Sticky Bucket documents.stickyBucketIdentifierAttributes- List of user's attributes keys.
-
-
Method Details
-
setAttributesJson
You can update the attributes JSON with new user attributes to evaluate against.- Parameters:
attributesJson- updated user attributes
-
setAttributes
public void setAttributes(@Nullable com.google.gson.JsonObject attributes) You can update the attributes with new user attributes to evaluate against.- Parameters:
attributes- updated user attributes
-
setFeaturesJson
You can update the features JSON with new features to evaluate against.- Parameters:
featuresJson- updated features
-
builder
The builder class to help create a context. You can use this builder or the constructor- Returns:
GBContext.CustomGBContextBuilder
-
transformFeatures
-
transformEncryptedFeatures
-
getFeatures
@Nullable public com.google.gson.JsonObject getFeatures()Keys are unique identifiers for the features and the values are Feature objects. Feature definitions - To be pulled from API / Cache -
getEnabled
Switch to globally disable all experiments. Default true. -
getUrl
The URL of the current page -
getIsQaMode
If true, random assignment is disabled and only explicitly forced variations are used. -
getAllowUrlOverride
Boolean flag to allow URL overrides (default: false) -
getTrackingCallback
A function that takesExperimentandExperimentResultas arguments. -
getFeatureUsageCallback
A function that takesStringandFeatureResultas arguments. A callback that will be invoked every time a feature is viewed. Listen for feature usage events -
getAttributesJson
String format of user attributes that are used to assign variations -
getExperimentHelper
-
getSavedGroups
@Nullable public com.google.gson.JsonObject getSavedGroups() -
getAttributes
@Nullable public com.google.gson.JsonObject getAttributes()Map of user attributes that are used to assign variations -
getEncryptionKey
Optional encryption key. If this is not null, featuresJson should be an encrypted payload. -
getForcedVariationsMap
Force specific experiments to always assign a specific variation (used for QA) -
getStickyBucketService
Service that provide functionality of Sticky Bucketing -
getStickyBucketAssignmentDocs
Map of Sticky Bucket documents -
getStickyBucketIdentifierAttributes
List of user's attributes keys -
setFeatures
public void setFeatures(@Nullable com.google.gson.JsonObject features) Keys are unique identifiers for the features and the values are Feature objects. Feature definitions - To be pulled from API / Cache -
setEnabled
Switch to globally disable all experiments. Default true. -
setUrl
The URL of the current page -
setIsQaMode
If true, random assignment is disabled and only explicitly forced variations are used. -
setAllowUrlOverride
Boolean flag to allow URL overrides (default: false) -
setTrackingCallback
A function that takesExperimentandExperimentResultas arguments. -
setFeatureUsageCallback
A function that takesStringandFeatureResultas arguments. A callback that will be invoked every time a feature is viewed. Listen for feature usage events -
setExperimentHelper
-
setSavedGroups
public void setSavedGroups(@Nullable com.google.gson.JsonObject savedGroups) -
setEncryptionKey
Optional encryption key. If this is not null, featuresJson should be an encrypted payload. -
setForcedVariationsMap
Force specific experiments to always assign a specific variation (used for QA) -
setStickyBucketService
Service that provide functionality of Sticky Bucketing -
setStickyBucketAssignmentDocs
public void setStickyBucketAssignmentDocs(@Nullable Map<String, StickyAssignmentsDocument> stickyBucketAssignmentDocs) Map of Sticky Bucket documents -
setStickyBucketIdentifierAttributes
public void setStickyBucketIdentifierAttributes(@Nullable List<String> stickyBucketIdentifierAttributes) List of user's attributes keys -
equals
-
hashCode
public int hashCode() -
toString
-