PostHog.FeatureFlags.Result (posthog v2.4.0)

View Source

Represents 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 flag
  • enabled - Whether the flag is enabled for this user
  • variant - 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

json()

@type json() ::
  String.t()
  | number()
  | boolean()
  | nil
  | [json()]
  | %{required(String.t()) => json()}

t()

@type t() :: %PostHog.FeatureFlags.Result{
  enabled: boolean(),
  key: String.t(),
  payload: json(),
  variant: String.t() | nil
}

Functions

value(result)

@spec value(t()) :: boolean() | String.t()

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