Our SDK helps you to decouple product experiences from code on your app in real-time with product variables. These product variables lets you change the behavior as well as the appearance of the app without requiring users to download an app update.
When using this feature, you essentially create in-app product variables and their default values that control the behavior and appearance of the app. You can later use the Hansel dashboard to change these default values and update product variables for all or segments of your app user base.
This guide will help you with the steps related to product variables. Product variables for a given feature are configs having a key name, default value, and defined data type.
Let's first understand product variables and their types.
|Type of product variable||What is it?||When to choose this?|
|String||This product variable is simply a collection of characters and numbers which helps you to perform text-based changes in run-time.||Whenever you are customizing the content of your app or website, you can choose string product variable type.|
|Number||Number product variables are used to define decimal or integer values.||If you are about to make numeric changes in your app or website, select a Number product variable type.|
|Boolean||This product variable is used to represent one of the two values - True or False.||When you to want to turn OFF/ ON the features and functions of your app or website, do it in one stroke with a Boolean product variable type.|
|JSON||This product variable is a collection of Key-Value pairs used to define an object for structuring data.||You can use JSON product variable type for managing entire data sets from Hansel dashboard in order to store and organize site or app content for e.g while creating a homepage.|
1: Head over to the Product Variables section from the left menu
2: Click on Create Feature Module button. A feature module refers to a particular feature where you want to define certain product variables. As an example, let's take the example of "Wishlist" as a feature module.
3: Once you are done creating a feature module, you can start adding product variables. Product variable consists of a key name, the data type of its value such as string, number, boolean, and json, and the default value for this key.
Continuing our example of "Wishlist" feature module, the below screenshot shows how we can add product variable "wishlist_feature_enabled" having boolean datatype and default value as false.
- In a similar manner, you can add multiple product variables to the given feature module.
- Otherwise, you can also create unassigned product variables, and add them to any already added feature module later on.
- You can also optionally enter a short “Description” for these product variables.
Once you are done with the above step of creating the product variables, you need to implement the below code snippets based on the applicable data type and relevant feature module where you want to add these product variables.
Please take a note following parameters when it comes to adding below mentioned code snippets to your app
- key : This is the name of the product variable on the Hansel Dashboard
- fallbackValue(optional) : This is a fallback value to use if the key doesn't exist or the connection with the Netcore backend hasn't been established. Although fallback value is optional it is recommended that you provide one.
1. Fetching the boolean product variable
//import io.hansel.actions.configs.HanselConfigs //Use the deep config you created on the dashboard boolean featureEnabled = HanselConfigs.getBoolean("config_name_here", false); //Use featureEnabled to show/hide the feature
//import io.hansel.actions.configs //Use the deep config you created on the dashboard val featureEnabled = HanselConfigs.getBoolean("config_name_here", false) //Use featureEnabled to show/hide the feature
2. Fetching the string product variable
//Use the deep config you created on the dashboard String featureName = HanselConfigs.getString("config_name_here","Default string");
//Use the deep config you created on the dashboard val featureName = HanselConfigs.getString("config_name_here", "Default String")
3. Fetching the Double or Number product variable
//Use the deep config you created on the dashboard Double value = HanselConfigs.getDouble("config_name_here",10.0);
//Use the deep config you created on the dashboard val featureValue = HanselConfigs.getDouble("config_name_here", 10.0)
4. Fetching the Json Object product variable
//Use the deep config you created on the dashboard JSONObject jsonObj = HanselConfigs.getJSONObject("config_name_here", null);
//Use the deep config you created on the dashboard val jsonObj = HanselConfigs.getJSONObject("config_name_here", null)
5. Fetching the Json Array product variable
//Use the deep config you created on the dashboard JSONArray array = HanselConfigs.getJSONArray("config_name_here", null);
//Use the deep config you created on the dashboard val array = HanselConfigs.getJSONArray("config_name_here", null)
Once you are done with the above steps, you can proceed to your hansel dashboard and start creating your first journey under the Feature Management option from the left menu.
Updated over 1 year ago