Rollout Using Kotlin SDK

Rollout enables you to release new features gradually and reduce risk. Instead of pushing updates to all users at once, you can use a feature flag to expose a new feature to a small segment, measure business impact, and then scale up safely. If anything goes wrong, do an instant rollback — no redeploy required.

This capability is powered by the Choose API using the Rollout selector. The call returns a variation that includes the following rolloutFlag conditions for each user:

  • rolloutFlag = true → user is included the rollout test and should see the new feature
  • rolloutFlag = false → user is in the rollout test but is assigned to the control group (feature off)
  • no flag returned → user isn’t included in the rollout campaign
🚧

Best practice

Put Rollout campaigns in a selector group, fetch all flag statuses at session start, and cache them for the session if they don’t change. Don’t mix campaign types in the same Choose call.

📘

For more information:

Code example

import android.util.Log 
import com.dynamicyield.sdk.wrapper.core.DYSdk 
import com.dynamicyield.sdk.wrapper.core.enums.ResultStatus 
import com.dynamicyield.sdk.wrapper.core.models.choose.response.CustomVariation 
import com.dynamicyield.sdk.wrapper.core.models.common.payload.Page 

// Example: Fetch multiple rollout flags in one call (selector group recommended) 

private suspend fun fetchRolloutFlags() { 
    val chooseResult = DYSdk.getInstance().choose.chooseVariations( 
        page = Page.homePage(pageLocation = "MainActivity"), 
        selectorNames = listOf("example-campaign-1", "example-campaign-2") 
        // or selectorGroups = listOf("feature_flags") when configured 
    ) 

    when (chooseResult.status) { 
        ResultStatus.SUCCESS, ResultStatus.WARNING -> { 
            chooseResult.choices?.forEach { choice -> 
                val variation = choice.variations.firstOrNull() 
                if (variation is CustomVariation) { 
                    val payload = variation.payload 
                    val rolloutFlag = variation.rolloutFlag ?: false 
                    Log.d("Rollout", "selector=${choice.name} rolloutFlag=$rolloutFlag") 
                    Log.d("Rollout", "payloadData=${payload.data}") 
                } 
            } 
        } 

        ResultStatus.ERROR -> { 
            chooseResult.error?.let { e -> 
                Log.e("Rollout", "chooseVariations error: ${e.message}") 
            } 
        } 
    } 
}