Ship a feature behind a feature flag
To ship a feature behind a BillDog feature flag, create the flag under Experimentation → Feature Flags, wrap the new code in a getFeatureFlag check, and release the build with the flag off. Then turn it on and raise Rollout Percentage in the dashboard. The server computes every verdict, so rollouts and the kill switch need no app update.
Steps last checked against the SDK source on 15 Nov 2026.
What you'll build
- A flag that gates new code in your app, off by default
- A gradual rollout you control from the dashboard, with an off switch
- A release condition that targets users by a custom attribute
- Exposure counts per flag value
What you'll need
- An app with the BillDog SDK configured. Start with the iOS, Android or Flutter, React Native or web codelab if you haven't
- Access to the project's dashboard
1. Create the flag in the dashboard
3 min- Open Experimentation → Feature Flags and click New Flag.
- Enter a Flag Key such as
new_checkout_flow. This is the string your code reads, and it is case-sensitive. - Enter a Flag Name and, optionally, a Description, then click Create Flag.
A new flag is created Disabled with a rollout of 0%, so every user reads false until you change it. Flags belong to one project and are served only to that project's SDK keys.
Don't start a key with __exp_. Experiments create backing flags with that prefix, and they are hidden from this page.
2. Read the flag in your app
6 minClient SDKs never bucket users locally. They fetch the verdicts once and cache them. On iOS and Android the read is synchronous and answers from the cache, which is empty on a first launch (every flag reads false). Wait for the fetch before a read that must be fresh.
import BillDogFull
// After BillDog.shared.configure(...)
func applyCheckoutFlag() {
Task {
let flags = BillDog.shared.abTest
await flags.waitForFlags() // up to 5 s, then answers from the cache
if flags.getFeatureFlag(key: "new_checkout_flow") {
showNewCheckout()
} else {
showOldCheckout()
}
}
}
// showNewCheckout() and showOldCheckout() are your own functions.On Android, add io.billdog:billdog-ab-test at the same version as your other BillDog artifacts, register the module once after configure, and read it from a coroutine.
import android.app.Application
import io.billdog.abtest.BillDogABTest
import io.billdog.core.BillDog
lateinit var abTest: BillDogABTest
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
BillDog.configure(this, "bd_public_test_YOUR_KEY")
abTest = BillDogABTest(this)
BillDog.use(abTest)
}
}import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.launch
class CheckoutActivity : AppCompatActivity() {
override fun onStart() {
super.onStart()
lifecycleScope.launch {
abTest.waitForFlags() // suspend, up to 5 s
if (abTest.getFeatureFlag("new_checkout_flow")) showNewCheckout()
else showOldCheckout()
}
}
private fun showNewCheckout() { /* your UI */ }
private fun showOldCheckout() { /* your UI */ }
}import { ABTestManager } from '@billdog.io/react-native';
export async function applyCheckoutFlag() {
const flags = ABTestManager.getInstance();
await flags.waitForFlags(); // up to 5 s
if (await flags.getFeatureFlag('new_checkout_flow')) { // async: returns a Promise
showNewCheckout();
}
}
// showNewCheckout() is your own function.import 'package:billdog_flutter/billdog_flutter.dart';
Future<void> applyCheckoutFlag() async {
await BillDogFeatureFlags.waitForFlags(); // up to 5 s
if (await BillDogFeatureFlags.getFeatureFlag('new_checkout_flow')) {
showNewCheckout(); // your own function
}
}On the web, @billdog.io/web loads flags once the SDK has a customer id, so call logIn first. getFeatureFlag is synchronous and returns true, false, or the variant key for a multivariate flag.
import BillDog from '@billdog.io/web';
export async function applyCheckoutFlag(userId: string) {
await BillDog.logIn(userId);
await BillDog.reloadFeatureFlags();
if (BillDog.getFeatureFlag('new_checkout_flow') === true) {
showNewCheckout(); // your own function
}
}3. Turn it on and roll out gradually
3 min- On the flag's card, turn on the switch. The badge changes to Enabled. The Rollout Percentage slider only works while the flag is enabled.
- Drag Rollout Percentage to 10%. It moves in steps of 5.
- Raise it over the following days as your crash and error numbers stay flat.
Each user is hashed into a bucket from 0 to 99, salted with the flag key, and gets the flag when their bucket is below the percentage. Raising the percentage keeps everyone who already had it. Two flags at 50% don't expose the same half of your users.
Apps pick up a change the next time they fetch flags: at the next launch, after sign-in or sign-out, or when you call refreshExperiments() on iOS and Android (reloadFeatureFlags() on web and Flutter).
4. Use the switch as a kill switch
2 minIf the new code misbehaves, turn the flag's switch off. A disabled flag answers false for everyone, before targeting or rollout are even checked. Keep the old code path in the app until the flag has been at 100% for a while, so there is something to fall back to.
When the rollout is finished, remove the check from your code, ship that build, and then delete the flag with the trash icon on its card.
5. Target users by an attribute
5 minRelease conditions decide who qualifies. The rollout then decides what fraction of them get the flag, so 50% means half of the users who matched, not half of everyone.
- On the flag's card, under Audience Conditions, click Add condition.
- Choose Custom Attribute, type
planin Field andproin Value. - Click Save Audience Rule. With no conditions, the flag is offered to everyone.
A condition can only match data the server has. Attributes stored on the customer are read when flags are evaluated, so set them with setUserAttributes, then fetch flags again:
Task {
do {
try await BillDog.shared.setUserAttributes(["plan": "pro"])
BillDog.shared.abTest.refreshExperiments()
} catch {
print("Could not save attributes: \(error)")
}
}// Inside an Activity, e.g. after the user upgrades
lifecycleScope.launch {
BillDog.setUserAttributes(mapOf("plan" to "pro"))
.onSuccess { abTest.refreshExperiments() }
}The same picker also offers Country, Platform, App Version, Entitlement, Segment and more. Country comes from the request's edge location, so you don't need to send it.
6. See who got which value
3 minEvery SDK records a $feature_flag_called event the first time a user reads a flag value in a session, with the key in $feature_flag and the answer in $feature_flag_response. Those events are your exposure data.
With the BillDog MCP connector in an AI assistant, ask for get_feature_flag_results. It returns users and evaluations per flag value for the last 30 days by default (up to 90). It reads production unless you pass sandbox: true, so ask for sandbox while you test with a bd_public_test_ key. See Build a paywall with an AI agent to connect it.
Show get_feature_flag_results for new_checkout_flow over the last 7 days, sandbox.The connector can also create and change flags (create_feature_flag, update_feature_flag), including multivariate flags with a JSON payload per variant, which the dashboard card doesn't edit. On a live project, a change that affects users waits for an owner or admin to approve it. To compare conversion between two versions of a paywall, use an experiment instead: run a paywall A/B test.