Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io
    Experiments
    Any platform
    Beginner
    22 min

    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

    1. Create the flag in the dashboard

    3 min
    1. Open Experimentation → Feature Flags and click New Flag.
    2. Enter a Flag Key such as new_checkout_flow. This is the string your code reads, and it is case-sensitive.
    3. 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 min

    Client 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.

    iOS (Swift)
    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.

    MyApplication.kt
    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)
        }
    }
    CheckoutActivity.kt
    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 */ }
    }
    React Native / Expo
    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.
    Flutter
    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.

    Web
    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
    1. 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.
    2. Drag Rollout Percentage to 10%. It moves in steps of 5.
    3. 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 min

    If 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 min

    Release 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.

    1. On the flag's card, under Audience Conditions, click Add condition.
    2. Choose Custom Attribute, type plan in Field and pro in Value.
    3. 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:

    iOS (Swift)
    Task {
        do {
            try await BillDog.shared.setUserAttributes(["plan": "pro"])
            BillDog.shared.abTest.refreshExperiments()
        } catch {
            print("Could not save attributes: \(error)")
        }
    }
    Android (Kotlin)
    // 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 min

    Every 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.

    Prompt
    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.

    Frequently asked questions

    The first read on a fresh install answers from an empty cache while the fetch runs. Await waitForFlags() before a read that must be fresh. It returns false if the fetch fails or the timeout passes, and the read then answers from the cache.

    No. Verdicts are computed on the server and fetched by the app, so the new percentage applies the next time the app fetches flags.

    On iOS, Android and the web SDK, yes: they read a cached map. The React Native and Flutter bridges return a Promise or Future because they call into the native SDK.

    No. Evaluation is metered once per request, however many flags it returns. The $feature_flag_called exposure events are ordinary analytics events, deduplicated per flag value per session, and can be turned off with sendFeatureFlagEvents.

    Reference

    Ship it on a free project

    Create a project, grab your SDK key and follow along. Sandbox purchases and data stay separate from production, so test transactions never mix with real revenue.

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.