What are Apptimize Dynamic Variables?
An Apptimize dynamic variable is a programming variable that has been defined in your code, whose value can be changed from our server. At the time of definition, a dynamic variable is assigned a default value and a name, and its value can be changed via the Apptimize server by running experiments.
Why are they important?
Apptimize Dynamic Variables give you the ability to make modifications to code variables on-the-fly so your users immediately reap the benefits of a change without the need for an App store release. Integrating dynamic variables empowers continuous improvement as they can be used across multiple experiments, without any need to redefine them.
What can a dynamic variable be?
Dynamic variables can be strings, integers, doubles, floats, booleans, arrays, and dictionaries (note for Dictionaries, the keys must be Strings). Their types are set when you define Dynamic Variables in your code. Tech note 1, Tech note 2
Why would I use dynamic variables instead of a code block?
Dynamic variables simplify the coding. Implementing code blocks requires a separate explicitly named section of executing code for each variant, and each experiment. Dynamic variables allow you to declare a variable with a single code snippet, and easily integrate it with the rest of your code. The next time Apptimize pairs with your device, the new variable will appear so that you can use it and modify it in any future experiment.
We’ll walk through a dynamic variable A/B experiment example that modifies the number of catalog categories to show a user. Our example app, Urban Attic, is a retail commerce app that lets user log in, browse the catalog, and make purchases. In our experiment, we’ll change the number of categories the user sees on opening the app from the original value of 3, to showing 5 or 8 categories. Let’s get started!
Here is the original variant in the app, 3 categories, followed by the variants with 5 and 8 categories:
- First, let’s setup the dynamic variable in the app code for this experiment. The dynamic variable(s) will need to be declared during app startup to let Apptimize know what variable(s) can be changed. In this example we will set an integer variable with name ‘categoryCount’ to a default value of 3, and add in code logic to modify the layout when other values (e.g. 5 or 8) are specified for the category count.
- First import Apptimize into the class that’s going to use it.
- Then, in AppDelegate’s didFinishLaunchingWithOptions method, declare a dynamic integer variable to be used for number of categories to show and set its default value.
[ApptimizeVariable integerWithName:@"categoryCount" andDefaultInteger:3];
- Finally, retrieve the dynamic variable and query its value in the code to set the number of categories to be displayed.
ApptimizeVariableInteger *categoryCount = [ApptimizeVariable getIntegerForName:@"categoryCount"]; NSInteger categoryCountInteger = [categoryCount integerValue];
After the app is run for the first time with the Apptimize dashboard open, the new Dynamic Variable becomes visible in your Dynamic Variable list for the App via WebSocket pairing. If your dynamic variable doesn’t appear in the Apptimize dashboard, see our FAQ answer for help.
- First import Apptimize into the class that’s going to use it.
- In the Apptimize Dashboard, you are now ready to create a new experiment. You can do this by clicking on the Create button on the top right of the dashboard list, and select the A/B Experiment project type.
- In Step 1 Details, the default experiment name will be “New Experiment 1,” but you can change it to something more meaningful. We’ll call our example experiment “Category Count,” and can enter notes or tags to help describe the experiment for other users.
- Next, we’ll continue to Step 2 Goals and set our primary goal. In this case, our goal is to maximize purchases by presenting users with the optimal number of item categories. We may set the primary goal as a purchasing funnel tracking the events from “Select Category” to “View Item” to “Add Item to Bag” to “Checkout” to “Finish Payment”.
- Continue to Step 3 Configuration. Under “Experiment type,” select Dynamic Variables. You will now be asked to select the dynamic variable you want for the experiment. For this example we see our variable, categoryCount, and will select the checkmark next to it and click Select Variables.
- Now, setup the variant and variant values for the experiment. By default, your experiment will have one variant called “original” which shows the dynamic variable’s default value and will be displayed to users not participating in the experiment. In this case, the default version of our app shows only 3 categories on the first screen. Note: the dashboard does not display the original value since the value is set in code and not pushed from Apptimize servers. For each additional variant you wish to add, click the Add Variant button, and then name the resulting variant. In this example, we name the first variant “5 categories” and the second variant “8 categories”. In the variable table, we enter in the values 5 and 8 for each variant. You can add screenshots to each variant to remind yourself of the experiment change you are testing.
- Click Continue to Targeting at the bottom or Step 4 Targeting in the upper sub-navigation to setup who will see the experiment. In this case, we set the allocation to 10% of our users exclusively, and add no targeting filters.
- Next, we’ll continue to Step 5 Launchpad, which shows a summary of our dynamic variable experiment. We can see the variant name, allocation percent (10%), our targets (no targets), and have the option to preview variants with the Preview Variants tool. When we’re ready, we can start the experiment by clicking the Launch Experiment button at the bottom, which will make the experiment move from “draft” to “running” state, and end users will see the experiment on their devices within about 15 minutes.
- You can find more information about stopping the experiment, setting a winner and interpreting/reading results in 6. Results.
Tech note 1. Apptimize dynamic variable dictionaries and arrays need to contain items of the same type.↩
Tech note 2. String variable variants specified through the web interface use the same escaping as JSON strings. This means you can use any unicode character, with special treatment for the control characters backslash () and double quote (“). Backslashes are used to specify string formatting: for example, n begins a new line. To specify a literal backslash, use the escape sequence \. Double quotes must be escaped as ” to appear in string variables. For convenience, the web interface automatically escapes unescaped double quotes when saving the variant: so ” becomes ”.↩