Skip to content

Initial Feature Flags Support #859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

jaredmixpanel
Copy link
Collaborator

@jaredmixpanel jaredmixpanel commented May 9, 2025

This PR adds initial support for using Mixpanel Feature Flags to the Android SDK. As part of this work we introduce the MixpanelOptions object to encapsulate all optional initialization parameters, i.e. instanceName, optOutTrackingDefault, superProperties, featureFlagsEnabled and featureFlagsContext... in order to avoid further constructor and getInstance signature proliferation. All of the existing signatures will be supported for backwards compatibility by ultimately building a MixpanelOptions object to be passed into the new canonical/designated constructor which expects a MixpanelOptions instance.

Example usage (in Kotlin, note that Kotlin automatically converts Java getters like getFlags() into properties like flags):

val flagsContext = JSONObject()
flagsContext.put("my_context_key", "my_context_value")
val mpOptionsBuilder = MixpanelOptions.Builder().featureFlagsEnabled(true).featureFlagsContext(flagsContext)
val mpOptions = mpOptionsBuilder.build()
val mixpanel = MixpanelAPI.getInstance(context, MIXPANEL_PROJECT_TOKEN, true, mpOptions)
mixpanel.flags.loadFlags()  // called automatically during SDK initialization
val ready = mixpanel.flags.areFlagsReady()
if (ready) {
    val featureFlagData = mixpanel.flags.getVariantSync(featureName, fallback)
}
mixpanel.flags.getVariant(featureName, fallback,
    FlagCompletionCallback { result -> 
        println("Key: ${result.key}")
        println("Value: ${result.value}")
    }
)
if (mixpanel.flags.areFlagsReady()) {
    val value = mixpanel.flags.getVariantValueSync(featureName, fallbackValue)
}
mixpanel.flags.getVariantValue(featureName, fallbackValue,
    FlagCompletionCallback { value -> 
        println("Value: $value")
    }
)
if (mixpanel.flags.areFlagsReady()) {
    val isEnabled = mixpanel.flags.isFlagEnabledSync(featureName, fallbackValue)
}
mixpanel.flags.isFlagEnabled(featureName, fallbackValue,
    FlagCompletionCallback { isEnabled -> 
        println("Is Enabled: $isEnabled")
    }
)

@jaredmixpanel jaredmixpanel requested a review from Copilot May 14, 2025 18:27
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces initial support for feature flags in the Mixpanel Android SDK along with several API enhancements and configuration updates.

  • Adds new parameters and method documentation in RemoteService and HttpService for handling feature flags and raw request bodies.
  • Introduces feature flag parsing in JsonUtils, new configuration classes (FlagsConfig, FeatureFlagData), and integrates feature flag management in MixpanelAPI and MPConfig.
  • Updates tests and demo code to work with the new flags functionality.

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/main/java/com/mixpanel/android/util/RemoteService.java Updated performRequest method with extended parameters and added detailed Javadoc.
src/main/java/com/mixpanel/android/util/MPConstants.java Added FLAG endpoint constant for feature flags.
src/main/java/com/mixpanel/android/util/JsonUtils.java Enhanced JSON parsing for feature flags responses.
src/main/java/com/mixpanel/android/util/HttpService.java Revised HTTP request handling to support both URL-encoded and raw request body with custom headers.
src/main/java/com/mixpanel/android/mpmetrics/MixpanelOptions.java Integrated feature flag options in MixpanelOptions builder.
src/main/java/com/mixpanel/android/mpmetrics/MixpanelAPI.java Integrated the feature flag manager and added feature flag API methods.
src/main/java/com/mixpanel/android/mpmetrics/MPConfig.java Added support for flags endpoint configuration.
src/main/java/com/mixpanel/android/mpmetrics/FlagsConfig.java New configuration class for feature flags.
src/main/java/com/mixpanel/android/mpmetrics/FeatureFlagData.java Added data class for representing feature flag data.
Other test and demo files Updated to work with changes in HTTP and feature flag API methods.
Comments suppressed due to low confidence (1)

src/main/java/com/mixpanel/android/mpmetrics/FeatureFlagData.java:18

  • In the fallback constructor, 'this.value' is mistakenly set to 'key' instead of null. Consider changing it to 'this.value = null;' to correctly reflect a missing value.
public FeatureFlagData(@NonNull String key) { this.key = key; this.value = key; // Defaulting value to null if not provided }

@jaredmixpanel jaredmixpanel requested a review from Copilot May 14, 2025 20:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces initial support for feature flags into the Mixpanel Android SDK along with a new options builder and configuration settings. Key changes include:

  • Enhancements to HTTP request handling in RemoteService and HttpService (support for headers and raw body).
  • Additions for feature flags handling via new APIs, configurations, and associated models (MixpanelOptions, MPConfig, FlagsConfig, FeatureFlagData, FlagCompletionCallback).
  • Updates to tests and demo code to support the new feature flags interfaces and a minor Gradle wrapper upgrade.

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/main/java/com/mixpanel/android/util/RemoteService.java Updated performRequest API with additional parameters and documentation.
src/main/java/com/mixpanel/android/util/MPConstants.java Added endpoints and key constants for feature flags.
src/main/java/com/mixpanel/android/util/JsonUtils.java Added helper method for parsing feature flags JSON response.
src/main/java/com/mixpanel/android/util/HttpService.java Updated performRequest signature and improved error handling with additional logging.
src/main/java/com/mixpanel/android/mpmetrics/MixpanelOptions.java Introduced new options for toggling feature flags support and context.
src/main/java/com/mixpanel/android/mpmetrics/MixpanelAPI.java Integrated feature flags load and access methods into the API.
src/main/java/com/mixpanel/android/mpmetrics/MPConfig.java Added support for configuring flags endpoint.
src/main/java/com/mixpanel/android/mpmetrics/FlagsConfig.java Added a configuration class for feature flags.
src/main/java/com/mixpanel/android/mpmetrics/FeatureFlagData.java Added model class representing feature flag data.
Other test and demo files Updated mocks and demo interactions to use the new performRequest signature and feature flag APIs.
gradle/wrapper/gradle-wrapper.properties Updated Gradle wrapper version for compatibility.

@jaredmixpanel jaredmixpanel requested a review from Copilot May 14, 2025 23:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request implements initial support for feature flags in the Mixpanel Android SDK and updates various network and configuration components accordingly. Key changes include:

  • Extending network operations with additional parameters (e.g. headers and raw body support) and updated documentation.
  • Adding new classes and interfaces for feature flag management (FeatureFlagData, Flags, FlagCompletionCallback) along with relevant API methods.
  • Updating configuration (MPConfig) and sample/test code to integrate feature flag support and endpoint settings.

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main/java/com/mixpanel/android/util/RemoteService.java Updated interface with expanded performRequest signature and thorough Javadoc documentation.
src/main/java/com/mixpanel/android/util/HttpService.java Refactored performRequest with additional parameters and enhanced error reporting and resource cleanup.
src/main/java/com/mixpanel/android/mpmetrics/MixpanelAPI.java Adjusted instantiation and API overloads to pass MixpanelOptions for feature flags.
src/main/java/com/mixpanel/android/mpmetrics/MPConfig.java Added settings for FlagsEndpoint and updated endpoint URLs accordingly.
Other files (tests, demo, utility classes) Updated to use the new API signature and integrate feature flags throughout the codebase.

@jaredmixpanel jaredmixpanel marked this pull request as ready for review May 15, 2025 04:07
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