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:1.0.0'
    implementation 'dev.openfeature:kotlin-sdk-android:0.7.2'
}

Usage

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

Using the Convenience Constructor

import com.mixpanel.android.openfeature.MixpanelProvider
import com.mixpanel.android.mpmetrics.MixpanelOptions
import dev.openfeature.sdk.OpenFeatureAPI
 
// Create provider (internally creates a MixpanelAPI instance)
val provider = MixpanelProvider(context, "YOUR_PROJECT_TOKEN", MixpanelOptions())
OpenFeatureAPI.setProvider(provider)
 
val client = OpenFeatureAPI.getClient()
val showNewUI = client.getBooleanValue("new-ui", false)
 
// Access the underlying Mixpanel instance for identify/track
provider.mixpanel?.identify("user-123")

Using an Existing MixpanelAPI Instance

import com.mixpanel.android.mpmetrics.MixpanelAPI
import com.mixpanel.android.openfeature.MixpanelProvider
 
val mixpanel = MixpanelAPI.getInstance(context, "YOUR_PROJECT_TOKEN")
 
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.

The provider forwards the global OpenFeature context to the Mixpanel SDK via setContext() during initialization and whenever the global context changes.

  • 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() or provider.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?