Split Help > Feature Flags > How do feature flags work in Split?

How do feature flags work in Split?

Split uses feature flags to control your code and launch features to groups of customers.

Split lets teams slowly release features and run experiments targeted to subsets of the overall user base. To do this, Split employs 'feature flags' or custom 'if / else' statements that connect to Split's SDKs and enable any feature to be turned on or off from the Split web console. 

Here's how the feature flag looks, in every language Split supports:

Java Javascript PHP Ruby Javascript Python .NET
							String treatment = sdk.getTreatment("CUSTOMER_ID","FEATURE_NAME");

if (treatment.equals("on")) {
    // insert code here to show on treatment
} else if (treatment.equals("off")) {
    // insert code here to show off treatment 
} else {
    // insert your control treatment code here
}
						
							var treatment = sdk.getTreatment("FEATURE_NAME");

if (treatment == "on") {
    // insert code here to show on treatment
} else if (treatment == "off") {
    // insert code here to show off treatment
} else {
    // insert your control treatment code here
}
						
							<?php
$treatment = $splitSdk->getTreatment('CUSTOMER_ID','FEATURE_NAME');

if ($treatment === 'on') {
    // insert code here to show on treatment
} elseif ($treatment === 'off') {
    // insert code here to show off treatment
} else {
    // insert your control treatment code here
}
						
							treatment = split_client.get_treatment("CUSTOMER_ID", "FEATURE_NAME");

if treatment == "on"
  # insert code here to show on treatment
elsif treatment == "off"
  # insert code here to show off treatment
else
  # insert your control treatment code here
end
						
							var treatment = sdk.getTreatment("CUSTOMER_ID", "FEATURE_NAME");

if (treatment == "on") {
    // insert code here to show on treatment
} else if (treatment == "off") {
    // insert code here to show off treatment
} else {
    // insert your control treatment code here
}
						
							treatment = split.get_treatment('CUSTOMER_ID', 'FEATURE_NAME')

if treatment == "on": 
    # insert code here to show on treatment
elif treatment == "off":
    # insert code here to show off treatment
else:
    # insert your control treatment code here
						
							var treatment = sdk.GetTreatment("CUSTOMER_ID","FEATURE_NAME");

if (treatment == "on") {
    // insert code here to show on treatment
} else if (treatment == "off") {
    // insert code here to show off treatment 
} else {
    // insert your control treatment code here
}
						

Browsing through the examples above, take a look at the one that makes the most sense for your app. As you'll see, Split's feature flags constitute a basic 'if / else' statement, with the principle difference of including a name for the feature, and being written in a particular syntax that will tie it back to the SDK.

In Split, these feature flags are automatically generated by the web console when you name a new feature within Split. Of course they can be manually typed out as well, so long as the name used in your code matches the name of the feature in the Split UI.

The feature flag defines the 'on' and 'off' states for that feature, as well as the 'control treatment'. The control treatment is just a safe default to use in case a user doesn't meet either of your on or off-state definitions. For example, if your new feature is a new search algorithm that incorporates a recommendation engine based on previous searches, your on state might be the new one, your off might be the current version, and your control state might be vanilla search, with no recommendation algorithm. 

To get started with Split's feature flags, visit our documentation.

Published May 31, 2017