Class GBContext

java.lang.Object
growthbook.sdk.java.GBContext

public class GBContext extends Object
Context object passed into the GrowthBook constructor. The builder() is recommended for constructing a Context. Alternatively, you can use the class's constructor.
  • 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)
      The GBContext.GBContextBuilder is recommended for constructing a Context. Alternatively, you can use this static method instead of the builder.
      Parameters:
      attributesJson - User attributes as JSON string
      attributes - 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 takes Experiment and ExperimentResult as arguments.
      featureUsageCallback - A function that takes String and FeatureResult as arguments. A callback that will be invoked every time a feature is viewed. Listen for feature usage events
      stickyBucketService - Service that provide functionality of Sticky Bucketing.
      stickyBucketAssignmentDocs - Map of Sticky Bucket documents.
      stickyBucketIdentifierAttributes - List of user's attributes keys.
  • Method Details

    • setAttributesJson

      public void setAttributesJson(String attributesJson)
      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

      public void setFeaturesJson(String featuresJson)
      You can update the features JSON with new features to evaluate against.
      Parameters:
      featuresJson - updated features
    • builder

      public static GBContext.GBContextBuilder builder()
      The builder class to help create a context. You can use this builder or the constructor
      Returns:
      GBContext.CustomGBContextBuilder
    • transformFeatures

      @Nullable public static com.google.gson.JsonObject transformFeatures(String featuresJsonString)
    • transformEncryptedFeatures

      public static com.google.gson.JsonObject transformEncryptedFeatures(@Nullable String featuresJson, @Nullable String encryptionKey)
    • 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

      @Nullable public Boolean getEnabled()
      Switch to globally disable all experiments. Default true.
    • getUrl

      @Nullable public String getUrl()
      The URL of the current page
    • getIsQaMode

      public Boolean getIsQaMode()
      If true, random assignment is disabled and only explicitly forced variations are used.
    • getAllowUrlOverride

      public Boolean getAllowUrlOverride()
      Boolean flag to allow URL overrides (default: false)
    • getTrackingCallback

      @Nullable public TrackingCallback getTrackingCallback()
      A function that takes Experiment and ExperimentResult as arguments.
    • getFeatureUsageCallback

      @Nullable public FeatureUsageCallback getFeatureUsageCallback()
      A function that takes String and FeatureResult as arguments. A callback that will be invoked every time a feature is viewed. Listen for feature usage events
    • getAttributesJson

      @Nullable public String getAttributesJson()
      String format of user attributes that are used to assign variations
    • getExperimentHelper

      public ExperimentHelper 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

      @Nullable public String getEncryptionKey()
      Optional encryption key. If this is not null, featuresJson should be an encrypted payload.
    • getForcedVariationsMap

      @Nullable public Map<String,Integer> getForcedVariationsMap()
      Force specific experiments to always assign a specific variation (used for QA)
    • getStickyBucketService

      @Nullable public StickyBucketService getStickyBucketService()
      Service that provide functionality of Sticky Bucketing
    • getStickyBucketAssignmentDocs

      @Nullable public Map<String,StickyAssignmentsDocument> getStickyBucketAssignmentDocs()
      Map of Sticky Bucket documents
    • getStickyBucketIdentifierAttributes

      @Nullable public List<String> 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

      public void setEnabled(@Nullable Boolean enabled)
      Switch to globally disable all experiments. Default true.
    • setUrl

      public void setUrl(@Nullable String url)
      The URL of the current page
    • setIsQaMode

      public void setIsQaMode(Boolean isQaMode)
      If true, random assignment is disabled and only explicitly forced variations are used.
    • setAllowUrlOverride

      public void setAllowUrlOverride(Boolean allowUrlOverride)
      Boolean flag to allow URL overrides (default: false)
    • setTrackingCallback

      public void setTrackingCallback(@Nullable TrackingCallback trackingCallback)
      A function that takes Experiment and ExperimentResult as arguments.
    • setFeatureUsageCallback

      public void setFeatureUsageCallback(@Nullable FeatureUsageCallback featureUsageCallback)
      A function that takes String and FeatureResult as arguments. A callback that will be invoked every time a feature is viewed. Listen for feature usage events
    • setExperimentHelper

      public void setExperimentHelper(ExperimentHelper experimentHelper)
    • setSavedGroups

      public void setSavedGroups(@Nullable com.google.gson.JsonObject savedGroups)
    • setEncryptionKey

      public void setEncryptionKey(@Nullable String encryptionKey)
      Optional encryption key. If this is not null, featuresJson should be an encrypted payload.
    • setForcedVariationsMap

      public void setForcedVariationsMap(@Nullable Map<String,Integer> forcedVariationsMap)
      Force specific experiments to always assign a specific variation (used for QA)
    • setStickyBucketService

      public void setStickyBucketService(@Nullable StickyBucketService stickyBucketService)
      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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object