DocsTracking MethodsSDKsAndroidOpenFeature Provider (Android)

OpenFeature Provider (Android)

Overview

The Mixpanel OpenFeature provider allows you to use Mixpanel Feature Flags through the standardized OpenFeature API. This provider wraps the Mixpanel Android SDK’s MixpanelAPI.Flags, letting you use the OpenFeature Kotlin SDK with Mixpanel as the backend.

For the core Feature Flags SDK guide, see Feature Flags (Android).

Prerequisites

Installation

Add the OpenFeature provider and SDK to your build.gradle:

dependencies {
    implementation 'com.mixpanel:mixpanel-android-openfeature-provider:1.0.0'
    implementation 'dev.openfeature:android-sdk:0.3.0'
}

Usage

The provider wraps MixpanelAPI.Flags from the Mixpanel Android SDK.

import com.mixpanel.android.mpmetrics.MixpanelAPI
import com.mixpanel.openfeature.MixpanelProvider
import dev.openfeature.sdk.OpenFeatureAPI
 
// Initialize Mixpanel
val mixpanel = MixpanelAPI.getInstance(context, "YOUR_PROJECT_TOKEN")
 
// Register the OpenFeature provider
val provider = MixpanelProvider(mixpanel.flags)
OpenFeatureAPI.setProvider(provider)
 
val client = OpenFeatureAPI.getClient()
val showNewUI = client.getBooleanValue("new-ui", false)

Supported Flag Types

OpenFeature MethodKotlin Type
getBooleanValue / getBooleanDetailsBoolean
getStringValue / getStringDetailsString
getIntegerValue / getIntegerDetailsInt
getDoubleValue / getDoubleDetailsDouble
getObjectValue / getObjectDetailsValue

Context and Identity

Context is set globally when registering the provider, not per-evaluation. Per-evaluation context passed to individual flag evaluations is ignored.

  • targetingKey has no special meaning in this provider. It is treated as a regular context property.
  • Identity should be managed through the Mixpanel SDK via mixpanel.identify().

Error Handling

The provider returns the default value on all errors, with an error code indicating the cause:

Error CodeCondition
PROVIDER_NOT_READYThe provider has not been initialized
FLAG_NOT_FOUNDThe requested flag does not exist
TYPE_MISMATCHThe flag value does not match the requested type

Use getDetails() methods instead of getValue() to inspect error codes:

val details = client.getBooleanDetails("my-flag", false)
if (details.errorCode != null) {
    Log.d("Flags", "Flag error: ${details.errorCode} - ${details.errorMessage}")
}

Lifecycle

  • shutdown() is a no-op. The Mixpanel SDK manages its own lifecycle.
  • The reason code for successful evaluations is STATIC.

Was this page useful?