PostHog.FeatureFlags.Result (posthog v2.4.0)
View SourceRepresents the result of a feature flag evaluation.
This struct contains all the information returned when evaluating a feature flag:
key- The name of the feature flagenabled- Whether the flag is enabled for this uservariant- The variant assigned to this user (nil for boolean flags)payload- The JSON payload configured for this flag/variant (nil if not set)
Examples
# Boolean flag result
%PostHog.FeatureFlags.Result{
key: "my-feature",
enabled: true,
variant: nil,
payload: nil
}
# Multivariant flag result with payload
%PostHog.FeatureFlags.Result{
key: "my-experiment",
enabled: true,
variant: "control",
payload: %{"button_color" => "blue"}
}
Summary
Functions
Returns the value of the feature flag result.
Types
Functions
Returns the value of the feature flag result.
If a variant is present, returns the variant string. Otherwise, returns the enabled boolean status. This provides backwards compatibility with existing code that expects a simple value from feature flag checks.
Examples
iex> result = %PostHog.FeatureFlags.Result{key: "flag", enabled: true, variant: "control", payload: nil}
iex> PostHog.FeatureFlags.Result.value(result)
"control"
iex> result = %PostHog.FeatureFlags.Result{key: "flag", enabled: true, variant: nil, payload: nil}
iex> PostHog.FeatureFlags.Result.value(result)
true
iex> result = %PostHog.FeatureFlags.Result{key: "flag", enabled: false, variant: nil, payload: nil}
iex> PostHog.FeatureFlags.Result.value(result)
false