# `PostHog.FeatureFlags.Result`
[🔗](https://github.com/posthog/posthog-elixir/blob/v2.18.0/lib/posthog/feature_flags/result.ex#L1)

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)
- `id` - Numeric flag ID from the PostHog backend (when available)
- `version` - Flag version from the PostHog backend (when available)
- `reason` - Reason describing why this evaluation produced its value
- `request_id` - Request ID returned by the `/flags` endpoint (useful for experiment exposure tracking)
- `evaluated_at` - Server-side evaluation timestamp from the response
- `has_experiment` - Whether the flag is linked to an experiment. `nil` when
  the server does not report the field (older deployments). Forwarded as
  `$feature_flag_has_experiment` on `$feature_flag_called` events only when
  the server reported it.
- `errors_while_computing` - Whether the response signaled
  `errorsWhileComputingFlags`; values for some flags may be incomplete or
  stale. Forwarded as `$feature_flag_error: "errors_while_computing_flags"`
  on `$feature_flag_called` events.
- `minimal_flag_called_events` - Whether the response signaled the top-level
  `minimalFlagCalledEvents` gate. When `true` and `has_experiment` is
  explicitly `false`, `$feature_flag_called` events for this flag are sent
  with a minimal, allowlisted property shape. `false` whenever the server
  did not report the gate.
- `locally_evaluated` - Whether this result was resolved from local flag
  definitions rather than the remote `/flags` response.

The metadata fields are populated when the `/flags` response includes them
and are forwarded as `$feature_flag_id`, `$feature_flag_version`, `$feature_flag_reason`,
`$feature_flag_request_id`, and `$feature_flag_evaluated_at` properties on
`$feature_flag_called` events.

## Examples

    # Boolean flag result
    %PostHog.FeatureFlags.Result{
      key: "my-feature",
      enabled: true,
      variant: nil,
      payload: nil
    }

    # Multivariant flag result with payload and metadata
    %PostHog.FeatureFlags.Result{
      key: "my-experiment",
      enabled: true,
      variant: "control",
      payload: %{"button_color" => "blue"},
      id: 154_429,
      version: 4,
      reason: %{"code" => "condition_match", "description" => "Matched condition set 1"},
      request_id: "0d23f243-399a-4904-b1a8-ec2037834b72",
      evaluated_at: 1_234_567_890
    }

# `json`

```elixir
@type json() ::
  String.t()
  | number()
  | boolean()
  | nil
  | [json()]
  | %{required(String.t()) =&gt; json()}
```

JSON-compatible value used for feature flag payloads.

# `t`

```elixir
@type t() :: %PostHog.FeatureFlags.Result{
  enabled: boolean(),
  errors_while_computing: boolean(),
  evaluated_at: integer() | nil,
  has_experiment: boolean() | nil,
  id: integer() | nil,
  key: String.t(),
  locally_evaluated: boolean(),
  minimal_flag_called_events: boolean(),
  payload: json(),
  reason: map() | String.t() | nil,
  request_id: String.t() | nil,
  variant: String.t() | nil,
  version: integer() | nil
}
```

Result for a single evaluated feature flag.

The struct fields mirror the data returned by PostHog's `/flags` endpoint and
the metadata emitted on `$feature_flag_called` events.

# `value`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
