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
Modifier and TypeClassDescriptionstatic class
The builder class to help create a context. -
Constructor Summary
ConstructorDescriptionGBContext
(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.GBContextBuilder
is recommended for constructing a Context. -
Method Summary
Modifier and TypeMethodDescriptionstatic GBContext.GBContextBuilder
builder()
The builder class to help create a context.boolean
Boolean flag to allow URL overrides (default: false)com.google.gson.JsonObject
Map 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.JsonObject
Keys are unique identifiers for the features and the values are Feature objects.A function that takesString
andFeatureResult
as 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.JsonObject
Map of Sticky Bucket documentsList of user's attributes keysService that provide functionality of Sticky BucketingA function that takesExperiment
andExperimentResult
as arguments.getUrl()
The URL of the current pageint
hashCode()
void
setAllowUrlOverride
(Boolean allowUrlOverride) Boolean flag to allow URL overrides (default: false)void
setAttributes
(com.google.gson.JsonObject attributes) You can update the attributes with new user attributes to evaluate against.void
setAttributesJson
(String attributesJson) You can update the attributes JSON with new user attributes to evaluate against.void
setEnabled
(Boolean enabled) Switch to globally disable all experiments.void
setEncryptionKey
(String encryptionKey) Optional encryption key.void
setExperimentHelper
(ExperimentHelper experimentHelper) void
setFeatures
(com.google.gson.JsonObject features) Keys are unique identifiers for the features and the values are Feature objects.void
setFeaturesJson
(String featuresJson) You can update the features JSON with new features to evaluate against.void
setFeatureUsageCallback
(FeatureUsageCallback featureUsageCallback) A function that takesString
andFeatureResult
as arguments.void
setForcedVariationsMap
(Map<String, Integer> forcedVariationsMap) Force specific experiments to always assign a specific variation (used for QA)void
setIsQaMode
(Boolean isQaMode) If true, random assignment is disabled and only explicitly forced variations are used.void
setSavedGroups
(com.google.gson.JsonObject savedGroups) void
setStickyBucketAssignmentDocs
(Map<String, StickyAssignmentsDocument> stickyBucketAssignmentDocs) Map of Sticky Bucket documentsvoid
setStickyBucketIdentifierAttributes
(List<String> stickyBucketIdentifierAttributes) List of user's attributes keysvoid
setStickyBucketService
(StickyBucketService stickyBucketService) Service that provide functionality of Sticky Bucketingvoid
setTrackingCallback
(TrackingCallback trackingCallback) A function that takesExperiment
andExperimentResult
as arguments.void
The URL of the current pagetoString()
static com.google.gson.JsonObject
transformEncryptedFeatures
(String featuresJson, String encryptionKey) static com.google.gson.JsonObject
transformFeatures
(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.GBContextBuilder
is 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 takesExperiment
andExperimentResult
as arguments.featureUsageCallback
- A function that takesString
andFeatureResult
as 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 takesExperiment
andExperimentResult
as arguments. -
getFeatureUsageCallback
A function that takesString
andFeatureResult
as 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 takesExperiment
andExperimentResult
as arguments. -
setFeatureUsageCallback
A function that takesString
andFeatureResult
as 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
-