We are using Unleash to run A/B Testing experiments at Artsy. In order to create an experiment, we will need to first add it to the Unleash dashboard then make code adjustments to use it.
- To login to our Unleash instance, use your Artsy Google account to proceed past the Cloudflare Access prompt and then use the shared admin credentials in 1Password to login to the dashboard.
- Tap on New feature toggle and fill in required details.
- Tap on Variants and define your different variations that users can get.
- Tap on Strategies and define how many/who can be part of that experiment.
- Try turning it on for
development
and test on eigen.
- In the file
experiments.ts
add your new experiment.
"our-new-experiment": {
description: "Experiment description",
payloadSuggestions: ["payload-1", "payload-2"] // If applicable
},
or if we want a variant we can use something like
"our-new-experiment": {
description: "Experiment description",
payloadSuggestions: ["payload-1", "payload-2"] // If applicable
},
value | description |
---|---|
description |
(string ) a string describing your experiment |
variantSuggestions |
(string[] ) a list of variant options, for use via the Dev Menu interface |
payloadSuggestions |
(string[] ) a list of payload options, for use via the Dev Menu interface |
Don't forget to add some tracking on this, using reportExperimentVariant
. Look for other examples in the code.
In order to use an experiment, we have two custom hooks that we created that support querying for a flag (useExperimentFlag
) or an experiment (useExperimentVariant
). The first one returns a boolean, the second returns a small object for variants and their payloads etc.
You can access the flag value in a functional react component using useExperimentFlag
.
+ const ourNewFlagEnabled = useExperimentFlag("our-new-flag")
return (
<>
+ {ourNewFlagEnabled && <ConditionallyShownComponent />}
<>
)
You can access the variant value in a functional react component using useExperimentVariant
.
+ const { variant } = useExperimentVariant("our-new-experiment")
+
+ return (
+ <>
+ {variant.enabled ? (
+ {variant.name === "control" && <ControlComponent />}
+ {variant.name === "variant-b" && <ExperimentComponent payload={variant.payload} />}
+ {variant.name === "variant-c" && <ExperimentComponent payload={variant.payload} />}
+ ) : (
+ <ControlComponent />
+ )}
+ <>
+ )
Note: Avoid using
experiment.variant
and instead use theexperiment.payload
for rendering your UI! it's more future proof and it's more convenient this way to create multiple experiments using the same flag where you update the control variant
In order to track an experiment, you can use the trackExperiment
helper that comes from useExperimentVariant
hook,
+ const { trackExperiment } = useExperimentVariant("our-new-experiment")
+
+ trackExperiment({
+ context_owner_screen: OwnerType.artist,
+ context_owner_id: "4d8b92b34eb68a1b2c0003f4",
+ context_owner_slug: "andy-warhol",
+ context_owner_type: OwnerType.artist,
+ })
Once an experiment is done, we'll have a winning variant. In order to roll out the winning variant for everyone, we can promote the variant to 100% of users in the Unleash dashboard.
For example, in the previous experiment, we were testing if the variant-b
variant performed better than control
we'd promote variant-b
to 100% of variant requests.
Afterwards we can update Eigen to remove the experiment code, leaving only the winning variant in place.
We should leave the experiment active in Unleash until clients are no longer requesting a variant for the experiment. This can take some time as users naturally upgrade.
Our infra supports adding admin overrides from the dev menu. In order to add an override:
- Open the dev menu
- Tap on Experiments
- Tap on ✏️ next to the payload or the variant name.
- Add your own
variant
/payload
override or select from the list of suggestions. - Tap Save
Ask for help in the #practice-mobile 🔐 slack channel, we will be happy to assist!