Skip to content

Surveys: Support linkedFlagVariant for targeting specific feature flag variants #388

@adboio

Description

@adboio

Summary

The Android SDK does not support linkedFlagVariant for surveys. Currently, the SDK only checks if a linked feature flag is enabled (isFeatureEnabled), but does not support targeting users in a specific variant of that flag.

Current State

In PostHogSurveysIntegration.kt, the survey matching logic (line ~203) only checks:

val featureFlagsMatch = allKeys.all { postHog.isFeatureEnabled(it) }

This is a boolean check that verifies the flag is enabled, but ignores the linkedFlagVariant condition.

Expected Behavior

When a survey has conditions.linkedFlagVariant set (e.g., "variant-a"), the SDK should:

  1. Get the actual flag value: flags[linkedFlagKey]
  2. Compare it to the variant: flagValue === linkedFlagVariant || linkedFlagVariant === "any"

Reference Implementation

See posthog-react-native: packages/react-native/src/surveys/getActiveMatchingSurveys.ts lines 77-83:

const linkedFlagVariant = survey.conditions?.linkedFlagVariant
let linkedFlagVariantCheck = true
if (linkedFlagVariant) {
  linkedFlagVariantCheck = survey.linked_flag_key
    ? flags[survey.linked_flag_key] === linkedFlagVariant || linkedFlagVariant === ANY_FLAG_VARIANT
    : true
}

Tracking

This is tracked in the survey SDK feature parity issue: PostHog/posthog#45658

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions