Class GrowthBookTrackingPlugin
- All Implemented Interfaces:
GrowthBookPlugin
POST {ingestorHost}/track?client_key={clientKey} with a JSON array
of events as the body.
Resources (HTTP client, scheduler, flush executor) are created in
init(), not the constructor, so an unregistered plugin never leaks
threads. A flush is triggered when either the buffer reaches
TrackingPluginConfig.resolvedBatchSize() or a timer fires after
TrackingPluginConfig.resolvedBatchTimeout(). close()
performs a final synchronous flush.
Delivery is best-effort: the owned flush executor uses a bounded queue and
drops the newest batch (with a warning) under sustained backpressure, and
failed POSTs are logged but not retried. If the configured clientKey
is blank the plugin is disabled: no resources are created, event methods are
no-ops, and close() still completes cleanly.
Create one instance per SDK client. A plugin instance owns a single
buffer, scheduler, executor, and lifecycle flag, so sharing one instance
across multiple GrowthBook/GrowthBookClient instances means the
first close()/shutdown() disables tracking for all of them.
Evaluations still running while the owning instance is shutting down may lose
their telemetry event; stop evaluating before shutdown for complete delivery.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Invoked when the owning GrowthBook instance is closed.voidinit()Called once when the plugin is registered with a GrowthBook instance.static GrowthBookTrackingPluginof(TrackingPluginConfig config) <V> voidonExperimentViewed(Experiment<V> experiment, ExperimentResult<V> result) Invoked after a user is bucketed into an experiment (once per unique hashAttribute/hashValue/experiment.key/variation combination).<V> voidonExperimentViewed(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.<V> voidonFeatureEvaluated(String featureKey, FeatureResult<V> result) Invoked every time a feature is evaluated.<V> voidonFeatureEvaluated(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
-
of
-
init
public void init()Description copied from interface:GrowthBookPluginCalled once when the plugin is registered with a GrowthBook instance. If this throws, the plugin is treated as failed and receives no further events (seePluginRegistry).- Specified by:
initin interfaceGrowthBookPlugin
-
onExperimentViewed
Description copied from interface:GrowthBookPluginInvoked after a user is bucketed into an experiment (once per unique hashAttribute/hashValue/experiment.key/variation combination).- Specified by:
onExperimentViewedin interfaceGrowthBookPlugin
-
onExperimentViewed
public <V> void onExperimentViewed(Experiment<V> experiment, ExperimentResult<V> result, @Nullable com.google.gson.JsonObject userAttributes) Description copied from interface:GrowthBookPluginInvoked after a user is bucketed into an experiment, with the user's attributes at evaluation time. The default delegates toGrowthBookPlugin.onExperimentViewed(Experiment, ExperimentResult)so existing plugins keep working; override this overload to receive the attributes.- Specified by:
onExperimentViewedin interfaceGrowthBookPluginuserAttributes- the evaluated user's attributes, ornullwhen unavailable
-
onFeatureEvaluated
Description copied from interface:GrowthBookPluginInvoked every time a feature is evaluated.- Specified by:
onFeatureEvaluatedin interfaceGrowthBookPlugin
-
onFeatureEvaluated
public <V> void onFeatureEvaluated(String featureKey, FeatureResult<V> result, @Nullable com.google.gson.JsonObject userAttributes) Description copied from interface:GrowthBookPluginInvoked on every feature evaluation, with the user's attributes at evaluation time. The default delegates toGrowthBookPlugin.onFeatureEvaluated(String, FeatureResult)so existing plugins keep working; override this overload to receive the attributes.- Specified by:
onFeatureEvaluatedin interfaceGrowthBookPluginuserAttributes- the evaluated user's attributes, ornullwhen unavailable
-
close
public void close()Description copied from interface:GrowthBookPluginInvoked when the owning GrowthBook instance is closed. Implementations should flush any buffered work synchronously. MUST be safe to call multiple times and even ifGrowthBookPlugin.init()failed.- Specified by:
closein interfaceGrowthBookPlugin
-