Variables enable you to dynamically define any element in your mobile application from within Experience OS. Just paste a snippet of code in your mobile application and define the value in Dynamic Yield. For example, you might use a variable for a headline, image, or any other snippet of code you want to replace. This lets you make fast changes to your app without the need to redeploy it and submit it for approval to the app store.
Variable sets are groups of variables that also enable you to create variations and experiences to target different users with different values. For example, if you want to group a variable for a headline and one for an image, you could create a variable set that displays a particular headline/image combination for one audience, and a different combination for other audiences. You could also create a number of variations and use A/B testing to determine the best values for your variables.
Note: In most cases, retrieving the variable does not entail a round trip to the Dynamic Yield server, because the values are already loaded within the init process and are already cached within the SDK. The only case where a round trip is needed is when a user loads the app for the very first time and the experience using the required variable is on the app’s first screen.
Create a variable
- Go to Settings › Variables and click Add New.
- Enter a name and labels (optional) to help organize your variables.
- Specify if the value is a string or a number.
- If the variable will be part of a variable set, check the Set possible values optional box and enter all of the potential values for the variable (one per line).
- The current value will be used if the variable is not part of a variable set as the value definition as long as there is no technical problem. In the event of a technical issue (e.g. internet connectivity), the fallback value will be used.
Note: The fallback value will be hardcoded in your app and cannot be dynamically changed later. This is by design as it should only be used in the event that a value cannot be retrieved from Dynamic Yield. The value can be null, but make sure that this does not negatively impact your app.
- Click Save and Get Code and paste the code in your app where you want to use the variable. For more details, see the Variable Sets API for iOS and Android.
Create a variable set
- Create more than one variable as described in the previous section. If you want the variables to have multiple values, make sure you use the Set possible values optional checkbox and enter more than one potential value.
- Go to App Personalization › Variable Sets and click Add New.
- Specify a name and select the variables you want to include in the set. You can only include variables that are not part of another variable set.
- Click Next and then click New Variation.
- Define the values to use for each variable in the variation for your default experience. Create as many variations as desired. The default experience is used if a user is not targeted by any other experience you create in this campaign to make sure that the variables always have some value.
- Configure the settings for the default experience such as allocation, primary metric, and advanced settings. When you are done, Save the experience.
- Click the plus icon to create an additional targeted experience.
- Make sure that all of the variables you used in the variable set are already pasted in your app, and then click Save and Publish when you’re ready to go.