Skip to content

Commit 96c04ec

Browse files
efahkKwame Efah
andauthored
flag sdk doc fixes (#2134)
Co-authored-by: Kwame Efah <[email protected]>
1 parent 9d13868 commit 96c04ec

File tree

3 files changed

+24
-39
lines changed

3 files changed

+24
-39
lines changed

pages/docs/tracking-methods/sdks/android/android-flags.mdx

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,15 @@ Following initialization, you can reload feature flag assignments in a couple of
7171

7272
```java
7373
String updatedDistinctId = "";
74+
// Reload after login
7475
mixpanel.identify(updatedDistinctId);
7576
```
7677

77-
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:
78+
2) To refresh flag variants that may have changed during the lifetime of your app, you can manually reload flags:
7879

7980
```java
80-
JSONObject newCustomProperties = new JSONObject();
81-
newCustomProperties.put("platform", "android");
82-
83-
JSONObject newContext = new JSONObject();
84-
newContext.put("company_id", "Y");
85-
newContext.put("customProperties", newCustomProperties);
86-
87-
// Update the context and reload flags
88-
mixpanel.getOptions().featureFlagsContext = newContext;
89-
mixpanel.getFlags().loadFlags();
81+
// Manually reload flags if desired
82+
mixpanel.flags.loadFlags();
9083
```
9184
## Flag Evaluation
9285

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

10093
```java
10194
// Get just the flag value asynchronously
102-
mixpanel.getFlags().getVariantValue("my-feature-flag", "control", new FlagCompletionCallback<Object>() {
95+
mixpanel.flags.getVariantValue("my-feature-flag", "control", new FlagCompletionCallback<Object>() {
10396
@Override
10497
public void onComplete(Object value) {
10598
// This runs on the main thread
10699
if (value.equals("variant_a")) {
107-
showExperimentForVariantA();
100+
showExperienceForVariantA();
108101
} else if (value.equals("variant_b")) {
109-
showExperimentForVariantB();
102+
showExperienceForVariantB();
110103
} else {
111104
showDefaultExperience();
112105
}
@@ -118,7 +111,7 @@ mixpanel.getFlags().getVariantValue("my-feature-flag", "control", new FlagComple
118111

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

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

142135
// Use flag value in your application logic
143136
if (flagValue.equals("variant_a")) {
144-
showExperimentForVariantA();
137+
showExperienceForVariantA();
145138
} else if (flagValue.equals("variant_b")) {
146-
showExperimentForVariantB();
139+
showExperienceForVariantB();
147140
} else {
148141
showDefaultExperience();
149142
}
@@ -152,7 +145,7 @@ if (flagValue.equals("variant_a")) {
152145
**Feature Gates: Check if Flag is Enabled/Disabled**
153146
```java
154147
// Check if a boolean flag is enabled
155-
boolean isEnabled = mixpanel.getFlags().isEnabledSync("my-boolean-flag", false);
148+
boolean isEnabled = mixpanel.flags.isEnabledSync("my-boolean-flag", false);
156149

157150
if (isEnabled) {
158151
showNewFeature();

pages/docs/tracking-methods/sdks/javascript/javascript-flags.mdx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ updated_distinct_id = ""
7474
mixpanel.identify(updated_distinct_id)
7575
```
7676

77-
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
77+
2) To refresh flag variants that may have changed during the lifetime of your app, you can manually reload flags with a new context:
7878

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

100100
// Use flag value in your application logic
101101
if (variant_value == "variant_a") {
102-
showExperimentForVariantA();
102+
showExperienceForVariantA();
103103
} else if (variant_value == "variant_b") {
104104
showExperienceForVariantB();
105105
} else if (variant_value == "control") {
@@ -110,15 +110,13 @@ if (variant_value == "variant_a") {
110110
**Feature Gates: Check if Flag is Enabled/Disabled**
111111
```javascript
112112
// 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.
113-
const variant_value = await mixpanel.flags.get_variant_value("my-feature-flag", "control");
113+
const isEnabled = await mixpanel.flags.is_enabled("my-feature-flag", control");
114114
115-
// Use flag value in your application logic
116-
if (variant_value == "variant_a") {
117-
showExperimentForVariantA();
118-
} else if (variant_value == "variant_b") {
119-
showExperienceForVariantB();
120-
} else if (variant_value == "control") {
121-
showDefaultExperience();
115+
// Use the result in your application logic.
116+
if (isEnabled) {
117+
showNewFeature();
118+
} else {
119+
showOldFeature();
122120
}
123121
```
124122

pages/docs/tracking-methods/sdks/swift/swift-flags.mdx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ Mixpanel.mainInstance().identify(distinctId: updatedDistinctId)
7373
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:
7474

7575
```swift
76-
Mixpanel.mainInstance().flags.delegate?.getOptions().featureFlagsContext = [
77-
"company_id": "Y",
78-
"customProperties": [
79-
"platform": "ios"
80-
]
81-
]
8276
Mixpanel.mainInstance().flags.loadFlags()
8377
```
8478

@@ -99,9 +93,9 @@ Mixpanel.mainInstance().flags.getVariantValue("my-feature-flag", fallbackValue:
9993
if let stringValue = value as? String {
10094
switch stringValue {
10195
case "variant_a":
102-
showExperimentForVariantA()
96+
showExperienceForVariantA()
10397
case "variant_b":
104-
showExperimentForVariantB()
98+
showExperienceForVariantB()
10599
default:
106100
showDefaultExperience()
107101
}
@@ -135,9 +129,9 @@ let flagValue = Mixpanel.mainInstance().flags.getVariantValueSync("my-feature-fl
135129

136130
// Use flag value in your application logic
137131
if flagValue as? String == "variant_a" {
138-
showExperimentForVariantA()
132+
showExperienceForVariantA()
139133
} else if flagValue as? String == "variant_b" {
140-
showExperimentForVariantB()
134+
showExperienceForVariantB()
141135
} else {
142136
showDefaultExperience()
143137
}

0 commit comments

Comments
 (0)