Skip to content

Commit 4e90cb7

Browse files
guiwritehtessaro
andauthored
docs: Experimentation section (#5878)
Co-authored-by: htessaro <heitor@writechoice.io>
1 parent cb22673 commit 4e90cb7

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Experimentation",
3+
"position": 50
4+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: A/B Testing
3+
sidebar_label: A/B Testing
4+
sidebar_position: 10
5+
---
6+
7+
A/B testing enables you to experiment with design and functionality variants of your application. The data generated will allow you to make modifications to your app, safe in the knowledge that it will have a net positive effect.
8+
9+
You can use Flagsmith to perform A/B tests. Using a combination of [multivariate flags](/basic-features/managing-features.md#multi-variate-flags) and a 3rd party analytics tool like [Amplitude](https://amplitude.com/) or [Mixpanel](https://mixpanel.com/), you can easily perform complex A/B tests that will help improve your product.
10+
11+
Running A/B tests require two main components: a bucketing engine and an analytics platform. The bucketing engine is used to put users into a particular A/B testing bucket. These buckets will control the specific user experience that is being tested. The analytics platform will receive a stream of event data derived from the behaviour of the user. Combining these two concepts allows you to deliver seamless A/B test.
12+
13+
We have [integrations](/integrations) with a number of analytics platforms. If we don't integrate with the platform you are using, you can still manually send the test data to the downstream platform manually.
14+
15+
By the end of this tutorial, you will be able to:
16+
17+
- Set up a multivariate flag in Flagsmith for A/B testing.
18+
- Implement logic in your application to bucket users and display variants.
19+
- Send A/B test data to an analytics platform.
20+
- Understand how to use anonymous identities for A/B testing on unknown users.
21+
22+
## Before you begin
23+
24+
To follow this tutorial, you will need:
25+
26+
- A basic understanding of [multivariate flags](/basic-features/managing-features.md#multi-variate-flags) in Flagsmith.
27+
- Access to a third-party analytics platform (e.g., Amplitude, Mixpanel) where you can send custom events. You can explore Flagsmith [integrations](/integrations) for this purpose.
28+
- A development environment for your application where you can implement changes and integrate the Flagsmith SDK.
29+
30+
## Scenario - Testing a new Paypal button
31+
32+
For this example, lets assume we have an app that currently accepts credit card payments only. We have a hunch that we are losing out on potential customers that would like to pay with PayPal. We're going to test whether adding PayPal to the payment options increases our checkout rate.
33+
34+
We have a lot of users on our platform, so we don't want to run this test against our entire user-base. We want 90% of our users to be excluded from the test. Then for our test, 5% of our users will see the new Paypal button, and the remaining 5% will not see it. So we will have 3 buckets:
35+
36+
1. Excluded (Control) Users
37+
2. Paypal test button users
38+
3. Test users that don't see the Paypal button
39+
40+
Because Flagsmith flags can contain both boolean states as well as multivariate flag values, we can make use of both. We will use the boolean flag state to control whether to run the test. Then, if the flag is `enabled`, check the multivariate value. In this example, we will only show the PayPal button if the value is set to `show`.
41+
42+
## Steps
43+
44+
1. Create a new [multivariate flag](/basic-features/managing-features.md#multi-variate-flags) that will control which of the 3 buckets the user is put into. We'll call this flag `paypal_button_test`. We will provide 3 variate options:
45+
46+
1. Control - 90% of users
47+
2. Paypal button - 5% of users
48+
3. Test users that don't see the Paypal button - 5% of users
49+
50+
2. In our app, we want to [identify](/basic-features/managing-identities.md) each user before they start the checkout process. All Flagsmith multivariate flags need us to identify the user, so we can bucket them in a reproducible manner.
51+
3. When we get to the checkout page, check the `value` of the `paypal_button_test` flag for that user. If it evaluates to `show`, show the PayPal payment button. Otherwise, don't show the button.
52+
4. Send an event message to the analytics platform, adding the name/value pair of `paypal_button_test` and the value of the flag; in this case it would be one of either `control`, `show` or `hide`.
53+
5. Deploy our app, enable the flag and watch the data come in to your analytics platform.
54+
55+
Here is what creating the flag would look like.
56+
57+
![Image](/img/ab-test-paypal-example.png)
58+
59+
Once the test is set up, and the flag has been enabled, data will start streaming into the analytics platform. We can now evaluate the results of the tests based on the behavioral changes that the new button has created.
60+
61+
## Handling Anonymous/Unknown Identities
62+
63+
To do A/B testing you need to use identities. Without an identity to key from, it's impossible for the platform to serve a consistent experience to your users.
64+
65+
What if you want to run an A/B test in an area of your application where you don't know who your users are? For example on the homepage of your website? In this instance, you need to generate _anonymous identities_ values for your users. In this case we will generate a GUID for each user.
66+
67+
A GUID value is just a random string that has an extremely high likelihood of being unique. There's more info about generating GUID values [on Stack Overflow](https://stackoverflow.com/a/2117523).
68+
69+
The general flow would be:
70+
71+
1. A new browser visits your website homepage for the first time.
72+
2. You see that this is an anonymous user, so you generate a random GUID for that user and assign it to them.
73+
3. You send that GUID along with an identify call to Flagsmith. This will then segment that visitor.
74+
4. You add a cookie to the browser and store the GUID. That way, if the user returns to your page, they will still be in the same segment.
75+
76+
These techniques will be slightly different depending on what platform you are developing for, but the general concept will remain the same.
77+
78+
## Next steps
79+
80+
- Explore [Flagsmith's integrations](/integrations) with analytics platforms.
81+
- Learn more about [managing identities](/basic-features/managing-identities.md) in Flagsmith.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Flag Analytics
3+
sidebar_label: Flag Analytics
4+
sidebar_position: 20
5+
---
6+
7+
## Overview
8+
9+
Flag analytics allow you to track how often individual flags are evaluated within the Flagsmith SDK.
10+
11+
To view Analytics for a particular flag, browse to the relevant environment and click on a single flag to edit that flag.
12+
13+
![Image](/img/flag-analytics.png)
14+
15+
Flag analytics can be really useful when removing flags from Flagsmith. More often than not, flags can be removed from your codebase and platform once they have been rolled out and everyone is comfortable with them running in production.
16+
17+
Once you have removed the evaluation code from your code base, its nice to be sure that all references to that flag have been removed, and that removing the flag itself from Flagsmith will not cause any unforeseen issues. Flag analytics help with this.
18+
19+
Flag analytics can also be helpful when identifying integration issues. Occasionally errors can creep into your code that cause multiple needless evaluations of a flag. Again, these analytics can help isolate these situations.
20+
21+
## Enabling Flag Analytics?
22+
23+
:::info
24+
25+
The Flag Analytics data will be visible in the Dashboard between 30 minutes and 1 hour after it has been collected.
26+
27+
:::
28+
29+
Flag analytics are disabled by default in our SDKs. You need to explicitly enable it when you initialize the Flagsmith client. Please refer to the corresponding SDK documentation for more details. For the Javascript family SDKs please refer to [Initialisation options](https://docs.flagsmith.com/clients/javascript#initialisation-options).
30+
31+
## How does it work?
32+
33+
Every time a flag is evaluated within the SDK (generally a call to a method like `flagsmith.hasFeature("myCoolFeature")`), the SDK keeps a track of the flag name along with an evaluation count.
34+
35+
Every `n` seconds (currently set to 10 seconds in the JS SDK) the SDK sends a message to the Flagsmith API with the list of flags that have been evaluated and their count. If no flags have been evaluated in that time window, no message is sent.

0 commit comments

Comments
 (0)