Skip to content

feat: Add getFeatureFlagResult API#279

Open
dustinbyrne wants to merge 5 commits intomainfrom
feat/get-feature-flag-result
Open

feat: Add getFeatureFlagResult API#279
dustinbyrne wants to merge 5 commits intomainfrom
feat/get-feature-flag-result

Conversation

@dustinbyrne
Copy link

@dustinbyrne dustinbyrne commented Feb 5, 2026

💡 Motivation and Context

Add a getFeatureFlagResult API that returns a unified PostHogFeatureFlagResult object containing the flag key, enabled state, variant (for multivariate flags), and payload in a single call. Previously, getting full flag information required separate calls to getFeatureFlag and getFeatureFlagPayload. This also supports a sendEvent parameter to suppress the $feature_flag_called event when only the payload is needed.

getFeatureFlagPayload is now deprecated in favor of this new method.

💚 How did you test it?

  • Added unit tests for PostHogFeatureFlagResult (fromValueAndPayload, fromMap, equality, toString, null/edge cases)
  • Added integration tests via a fake platform interface covering boolean flags, multivariate flags, payloads, null values, and sendEvent parameter forwarding
  • Updated the example app to exercise getFeatureFlagResult
  • Manually verified native Android and iOS implementations serialize the result map correctly via method channels

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

@dustinbyrne dustinbyrne requested a review from a team as a code owner February 5, 2026 18:38
@dustinbyrne dustinbyrne force-pushed the feat/get-feature-flag-result branch from 6458f44 to 7bf8fa6 Compare February 5, 2026 18:40
@dustinbyrne
Copy link
Author

CI will fail until PostHog/posthog-ios#459 is released

@dustinbyrne dustinbyrne changed the title feat: Add getFeatureFlagPayload API feat: Add getFeatureFlagResult API Feb 5, 2026
@dustinbyrne dustinbyrne force-pushed the feat/get-feature-flag-result branch from 7bf8fa6 to 483265d Compare February 5, 2026 19:03
result: Result,
) {
try {
val featureFlagKey: String = call.argument("key")!!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use !! otherwise the app will crash, either fallback to empty or return early

/// - `String`: Multivariate flag with the given variant
factory PostHogFeatureFlagResult.fromValueAndPayload(
String key,
Object? flagValue,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the value be null?

other.key == key &&
other.enabled == enabled &&
other.variant == variant &&
other.payload == payload;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not doing deep equality, should we?
you can check PHListEquality().equals(...) if payload is a collection

Copy link
Member

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a few comments otherwise LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants