Interface GrowthBookPlugin

All Known Implementing Classes:
GrowthBookTrackingPlugin

public interface GrowthBookPlugin
A plugin that can observe experiment and feature evaluations on a GrowthBook instance. Mirrors the plugin contracts in the GrowthBook Python and Go SDKs.

Implementations MUST be thread-safe. All methods default to no-ops so custom plugins only override what they need. Methods should return quickly (enqueue work, don't block evaluation). Exceptions thrown by these methods are caught by PluginRegistry so one failing plugin can't break evaluation or other plugins.

  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Invoked when the owning GrowthBook instance is closed.
    default void
    Called once when the plugin is registered with a GrowthBook instance.
    default <V> void
    onExperimentViewed(Experiment<V> experiment, ExperimentResult<V> result)
    Invoked after a user is bucketed into an experiment (once per unique hashAttribute/hashValue/experiment.key/variation combination).
    default <V> void
    onExperimentViewed(Experiment<V> experiment, ExperimentResult<V> result, com.google.gson.JsonObject userAttributes)
    Invoked after a user is bucketed into an experiment, with the user's attributes at evaluation time.
    default <V> void
    onFeatureEvaluated(String featureKey, FeatureResult<V> result)
    Invoked every time a feature is evaluated.
    default <V> void
    onFeatureEvaluated(String featureKey, FeatureResult<V> result, com.google.gson.JsonObject userAttributes)
    Invoked on every feature evaluation, with the user's attributes at evaluation time.
  • Method Details

    • init

      default void init()
      Called once when the plugin is registered with a GrowthBook instance. If this throws, the plugin is treated as failed and receives no further events (see PluginRegistry).
    • onExperimentViewed

      default <V> void onExperimentViewed(Experiment<V> experiment, ExperimentResult<V> result)
      Invoked after a user is bucketed into an experiment (once per unique hashAttribute/hashValue/experiment.key/variation combination).
    • onExperimentViewed

      default <V> void onExperimentViewed(Experiment<V> experiment, ExperimentResult<V> result, @Nullable com.google.gson.JsonObject userAttributes)
      Invoked after a user is bucketed into an experiment, with the user's attributes at evaluation time. The default delegates to onExperimentViewed(Experiment, ExperimentResult) so existing plugins keep working; override this overload to receive the attributes.
      Parameters:
      userAttributes - the evaluated user's attributes, or null when unavailable
    • onFeatureEvaluated

      default <V> void onFeatureEvaluated(String featureKey, FeatureResult<V> result)
      Invoked every time a feature is evaluated.
    • onFeatureEvaluated

      default <V> void onFeatureEvaluated(String featureKey, FeatureResult<V> result, @Nullable com.google.gson.JsonObject userAttributes)
      Invoked on every feature evaluation, with the user's attributes at evaluation time. The default delegates to onFeatureEvaluated(String, FeatureResult) so existing plugins keep working; override this overload to receive the attributes.
      Parameters:
      userAttributes - the evaluated user's attributes, or null when unavailable
    • close

      default void close()
      Invoked when the owning GrowthBook instance is closed. Implementations should flush any buffered work synchronously. MUST be safe to call multiple times and even if init() failed.