Skip to content

Initial support for Feature Flags #670

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

Merged
merged 20 commits into from
May 28, 2025
Merged

Initial support for Feature Flags #670

merged 20 commits into from
May 28, 2025

Conversation

jaredmixpanel
Copy link
Contributor

@jaredmixpanel jaredmixpanel commented Apr 22, 2025

This PR introduces initial support for Mixpanel Feature Flags in the Swift SDK. As part of this work we've introduced a new MixpanelOptions object to encapsulate all of the various arguments that can be passed into the SDK initializer.

Example usage:

let mixpanelOptions = MixpanelOptions(token: "MY TOKEN", trackAutomaticEvents: false, featureFlagsEnabled: true, featureFlagsContext: ["key": "value"])
Mixpanel.initialize(options: mixpanelOptions)
let mixpanel = Mixpanel.mainInstance()
mixpanel.flags.loadFlags()  // called automatically on SDK initialization
let ready = mixpanel.flags.areFlagsReady()
if (ready) {
    mxipanel.flags.getVariantSync(flagName, fallback: fallback)
}
mixpanel.flags.getVariant(flagName, fallback: fallback) { variant in
    print("Key: \(variant.key), Value: \(String(describing: variant.value))")
}
if (mixpanel.flags.areFlagsReady()) {
    let flagValue = mixpanel.flags.getVariantValueSync(flagName, fallbackValue: fallbackValue) as! String
}
mixpanel.flags.getVariantValue(flagName, fallbackValue: fallbackValue) { value in
    flagValue = value as! String
    print("Flag Value: \(flagValue)")
}
if (mixpanel.flags.areFlagsReady()) {
    let enabled = mixpanel.flags.isEnabledSync(flagName, fallbackValue: fallbackValue)
}
mixpanel.flags.isEnabled(flagName, fallbackValue: fallbackValue) { isEnabled in
    print("Feature Enabled: \(isEnabled)")
}

@jaredmixpanel jaredmixpanel requested a review from Copilot April 22, 2025 18:40
Copy link
Contributor

@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 adds initial support for feature flags by persisting flag data, integrating a feature flag manager into the instance, and updating configuration and initialization methods.

  • Added new keys and methods in MixpanelPersistence.swift to save/load flags.
  • Updated MixpanelInstance.swift to conform to FeatureFlagDelegate and integrate FeatureFlagManager.
  • Introduced a new MixpanelConfig class with flag configuration and updated initialization flows in Mixpanel.swift and the demo AppDelegate.

Reviewed Changes

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

Show a summary per file
File Description
Sources/MixpanelPersistence.swift Added new key for flags and methods for archiving/unarchiving flag data.
Sources/MixpanelInstance.swift Integrated FeatureFlagManager and conformed to FeatureFlagDelegate.
Sources/MixpanelConfig.swift Introduced a new configuration class with flag support.
Sources/Mixpanel.swift Updated initialization methods to work with the new config and flags.
MixpanelDemo/MixpanelDemo/AppDelegate.swift Updated demo to initialize with MixpanelConfig including flags.
Files not reviewed (2)
  • Mixpanel.xcodeproj/project.pbxproj: Language not supported
  • MixpanelDemo/MixpanelDemo.xcodeproj/project.pbxproj: Language not supported
Comments suppressed due to low confidence (2)

Sources/Mixpanel.swift:21

  • The conditional block is redundant since both branches call the same initializer; simplifying this will improve code clarity.
if let proxyServerConfig = config.proxyServerConfig { return MixpanelManager.sharedInstance.initialize(config: config) } else { return MixpanelManager.sharedInstance.initialize(config: config) }

Sources/MixpanelPersistence.swift:201

  • The call to 'UserDefaults.synchronize()' is deprecated and may lead to unnecessary performance overhead; consider removing it to rely on the system's automatic synchronization.
defaults.synchronize()

Copy link

@ketanmixpanel ketanmixpanel left a comment

Choose a reason for hiding this comment

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

LGTM

@jaredmixpanel jaredmixpanel requested a review from Copilot May 16, 2025 00:33
Copy link
Contributor

@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. It adds APIs for saving and loading flags in persistence, updates MixpanelOptions and MixpanelInstance to support feature flag functionality, and integrates new demo cases and project file references for feature flag testing.

  • Added persistence support for feature flags in MixpanelPersistence.
  • Extended MixpanelOptions and MixpanelInstance to include feature flag configurations and delegation.
  • Updated demo and project configuration files to incorporate feature flag testing and new file references.

Reviewed Changes

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

Show a summary per file
File Description
Sources/MixpanelPersistence.swift Adds keys and methods to save/load feature flags in UserDefaults.
Sources/MixpanelOptions.swift Introduces new options for enabling and configuring feature flags.
Sources/MixpanelInstance.swift Integrates feature flag API and delegate support into the instance.
Sources/Mixpanel.swift Adds a new initializer to accept MixpanelOptions.
MixpanelDemo/TrackingViewController.swift Adds multiple demo cases to exercise the feature flag APIs.
MixpanelDemo/AppDelegate.swift Updates initialization to use the new MixpanelOptions instance.
MixpanelDemo/MixpanelDemo.xcodeproj/project.pbxproj & Mixpanel.xcodeproj/project.pbxproj Updates project configuration to include new feature flag test files and related source files.
Mixpanel-swift.podspec Updates podspec to include the new MixpanelOptions and FeatureFlags sources.

@jaredmixpanel jaredmixpanel marked this pull request as ready for review May 16, 2025 00:46
@jaredmixpanel jaredmixpanel requested a review from Copilot May 22, 2025 20:03
Copy link
Contributor

@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 Mixpanel Feature Flags in the Swift SDK through the addition of new persistence functions, a new MixpanelOptions class with feature flag configuration, and corresponding integration into the MixpanelInstance lifecycle and tests.

  • Added persistence methods for saving and loading feature flags in MixpanelPersistence.swift.
  • Introduced MixpanelOptions with properties for feature flag configuration.
  • Updated MixpanelInstance, Mixpanel, and tests to integrate feature flags usage.

Reviewed Changes

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

Show a summary per file
File Description
Sources/MixpanelPersistence.swift Added persistence methods for feature flags with minor spelling typo in a comment.
Sources/MixpanelOptions.swift New class exposing feature flag options and related configurations.
Sources/MixpanelInstance.swift Integrated feature flags into instance initialization and identification flows.
Sources/Mixpanel.swift Updated initialization to use the new options class.
MixpanelDemoTests/MixpanelDemoTests.swift Added a mock flags implementation and tests verifying flag load behavior.
AppDelegate.swift Updated demo app initialization to support feature flags via options.
Project Files (.pbxproj, podspec) Added new files to project configuration supporting feature flags.

jaredmixpanel and others added 2 commits May 22, 2025 13:04
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jaredmixpanel jaredmixpanel merged commit 330b471 into master May 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants