Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions pages/docs/tracking-methods/sdks/android/android-flags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,15 @@ Following initialization, you can reload feature flag assignments in a couple of

```java
String updatedDistinctId = "";
// Reload after login
mixpanel.identify(updatedDistinctId);
```

2) If variant assignment keys or properties used in Runtime Targeting change during the lifetime of your application, you can manually reload flags by updating the context:
2) To refresh flag variants that may have changed during the lifetime of your app, you can manually reload flags:

```java
JSONObject newCustomProperties = new JSONObject();
newCustomProperties.put("platform", "android");

JSONObject newContext = new JSONObject();
newContext.put("company_id", "Y");
newContext.put("customProperties", newCustomProperties);

// Update the context and reload flags
mixpanel.getOptions().featureFlagsContext = newContext;
mixpanel.getFlags().loadFlags();
// Manually reload flags if desired
mixpanel.flags.loadFlags();
```
## Flag Evaluation

Expand All @@ -99,14 +92,14 @@ This action triggers tracking an exposure event, `$experiment_started` to your M

```java
// Get just the flag value asynchronously
mixpanel.getFlags().getVariantValue("my-feature-flag", "control", new FlagCompletionCallback<Object>() {
mixpanel.flags.getVariantValue("my-feature-flag", "control", new FlagCompletionCallback<Object>() {
@Override
public void onComplete(Object value) {
// This runs on the main thread
if (value.equals("variant_a")) {
showExperimentForVariantA();
showExperienceForVariantA();
} else if (value.equals("variant_b")) {
showExperimentForVariantB();
showExperienceForVariantB();
} else {
showDefaultExperience();
}
Expand All @@ -118,7 +111,7 @@ mixpanel.getFlags().getVariantValue("my-feature-flag", "control", new FlagComple

```java
// Check if a boolean flag is enabled asynchronously
mixpanel.getFlags().isEnabled("my-boolean-flag", false, new FlagCompletionCallback<Boolean>() {
mixpanel.flags.isEnabled("my-boolean-flag", false, new FlagCompletionCallback<Boolean>() {
@Override
public void onComplete(Boolean isEnabled) {
// This runs on the main thread
Expand All @@ -137,13 +130,13 @@ mixpanel.getFlags().isEnabled("my-boolean-flag", false, new FlagCompletionCallba

```java
// Get just the flag value synchronously
Object flagValue = mixpanel.getFlags().getVariantValueSync("my-feature-flag", "control");
Object flagValue = mixpanel.flags.getVariantValueSync("my-feature-flag", "control");

// Use flag value in your application logic
if (flagValue.equals("variant_a")) {
showExperimentForVariantA();
showExperienceForVariantA();
} else if (flagValue.equals("variant_b")) {
showExperimentForVariantB();
showExperienceForVariantB();
} else {
showDefaultExperience();
}
Expand All @@ -152,7 +145,7 @@ if (flagValue.equals("variant_a")) {
**Feature Gates: Check if Flag is Enabled/Disabled**
```java
// Check if a boolean flag is enabled
boolean isEnabled = mixpanel.getFlags().isEnabledSync("my-boolean-flag", false);
boolean isEnabled = mixpanel.flags.isEnabledSync("my-boolean-flag", false);

if (isEnabled) {
showNewFeature();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ updated_distinct_id = ""
mixpanel.identify(updated_distinct_id)
```

2) If variant assignment keys or properties used in Runtime Targeting change during the lifetime of your application, you can manually reload with those new properties
2) To refresh flag variants that may have changed during the lifetime of your app, you can manually reload flags with a new context:

```javascript
mixpanel.flags.update_context({
Expand All @@ -99,7 +99,7 @@ const variant_value = await mixpanel.flags.get_variant_value("my-feature-flag",

// Use flag value in your application logic
if (variant_value == "variant_a") {
showExperimentForVariantA();
showExperienceForVariantA();
} else if (variant_value == "variant_b") {
showExperienceForVariantB();
} else if (variant_value == "control") {
Expand All @@ -110,15 +110,13 @@ if (variant_value == "variant_a") {
**Feature Gates: Check if Flag is Enabled/Disabled**
```javascript
// Fetch the variant value once flags are ready and track an exposure event *if* the user context is in a rollout group for the feature flag.
const variant_value = await mixpanel.flags.get_variant_value("my-feature-flag", "control");
const isEnabled = await mixpanel.flags.is_enabled("my-feature-flag", control");

// Use flag value in your application logic
if (variant_value == "variant_a") {
showExperimentForVariantA();
} else if (variant_value == "variant_b") {
showExperienceForVariantB();
} else if (variant_value == "control") {
showDefaultExperience();
// Use the result in your application logic.
if (isEnabled) {
showNewFeature();
} else {
showOldFeature();
}
```

Expand Down
14 changes: 4 additions & 10 deletions pages/docs/tracking-methods/sdks/swift/swift-flags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ Mixpanel.mainInstance().identify(distinctId: updatedDistinctId)
2) If variant assignment keys or properties used in Runtime Targeting change during the lifetime of your application, you can manually reload flags by updating the context:

```swift
Mixpanel.mainInstance().flags.delegate?.getOptions().featureFlagsContext = [
"company_id": "Y",
"customProperties": [
"platform": "ios"
]
]
Mixpanel.mainInstance().flags.loadFlags()
```

Expand All @@ -99,9 +93,9 @@ Mixpanel.mainInstance().flags.getVariantValue("my-feature-flag", fallbackValue:
if let stringValue = value as? String {
switch stringValue {
case "variant_a":
showExperimentForVariantA()
showExperienceForVariantA()
case "variant_b":
showExperimentForVariantB()
showExperienceForVariantB()
default:
showDefaultExperience()
}
Expand Down Expand Up @@ -135,9 +129,9 @@ let flagValue = Mixpanel.mainInstance().flags.getVariantValueSync("my-feature-fl

// Use flag value in your application logic
if flagValue as? String == "variant_a" {
showExperimentForVariantA()
showExperienceForVariantA()
} else if flagValue as? String == "variant_b" {
showExperimentForVariantB()
showExperienceForVariantB()
} else {
showDefaultExperience()
}
Expand Down