-
Notifications
You must be signed in to change notification settings - Fork 14
Client side AB Testing
In this section we will go through the steps and considerations that you must have when you want to set up a new test.
Psst! you can also set up server-side AB tests by following this guide.
The abtestDefinitions module contains definitions for client side AB tests. These definitions include information such as targeting (eg. should the test be targeting specific URLs or Regions), amount of cohorts included, audience size of test and whether a test is enabled.
The logic to allocate users to AB Test Participations sits in the abtest.ts module, this module exports the following methods:
This function is called on page initialisation and returns active test participations for a user which are then saved in Redux (common.abParticipations
) and logged in Ophan / Quantum Metric. AB participations are allocated by executing the following steps:
-
Read the MVT (multi variant testing) id from the users's cookie. If the user has no mvt in his or her browser, it generates a new MVTid and saves it in the cookie.
-
From the MVT generates a
participations
object. The steps to build that object are to combine test participations from tests defined inabtestDefinitions
, tests from theURL
and tests from server-side:
- Read tests from
abtestDefinitions
- Iterate over the
tests
object from abtestDefinitions and check whether each test is runnable.- A test can be marked as
referrerControlled
in it'sabtestDefinition
. If a test hasreferrerControlled
set totrue
we will only assign a user to the test if theacquisitionData
contains a reference to a corresponding test. Matching is done on test name.
- A test can be marked as
- If a test is runnable assign the user to a variant based on the value of their
mvtId
.
- Iterate over the
- Read tests from
URL
- A user can force themselves into a test / variant via a url fragment using the form:
#ab-[name_of_test]=[variant_name]
.
- A user can force themselves into a test / variant via a url fragment using the form:
- Read tests from server-side
- Read
window.guardian.serversideTests
allocations.
- Read
Like init()
this function is also called on page initialisation on pages where Amounts tests are applicable (eg. the Support checkout) and returns active Amounts test participations for a user which are then saved in Redux (common.abParticipations
) and logged in Ophan / Quantum Metric.
window.guardian.settings.amounts
contains configuration data related to RRCP configured βAmountsβ tests. Amounts tests define what choice cards are rendered on the Support checkout.
Amounts test participations are allocated by executing the following steps:
- Check URL for amounts test participation
- Check if the
acquisitionData
contains a reference to an amounts test participation, and the corresponding test and cohort is available in thewindow.guardian.settings.amounts
, if a match is found select that test / cohort
- Check if the
- Query
window.guardian.settings.amounts
for a matching targeted test- Amounts tests can be targeted by
Country
ORRegion
, search for aCountry
match first, if a match is found select that test / cohort otherwise search foraRegion
targeted test.
- Amounts tests can be targeted by
- Fallback to default amounts
- If we couldn't match an Amounts test on
Country
ORRegion
we fallback to the default amounts, which are defined in code and not in the RRCP.
- If we couldn't match an Amounts test on
AB Test participations are stored in Redux state once a user has been allocated to a test / cohort. You can read these participations as so:
const { abParticipations } = useContributionsSelector(
(state) => state.common,
);
const isUserInSupporterPlusOnlyVariant = abParticipations?.supporterPlusOnly === 'variant';
- Redux Glossary
- Why Redux Toolkit?
- Writing state slices with Redux Toolkit
- Handling action side effects in Redux
- Presentational and Container Components
- Scoped actions and reducers
- Server Side Rendering
- Form validation
- CI build process
- Post deployment testing
- Post deployment test runbook
- TIP Real User Testing
- Code testing and validation
- Visual testing
- Testing Apple Pay locally
- Test Users
- Deploying to CODE
- Automated IT tests
- Deploying Fastly VCL Snippets
- Archived Components
- Authentication
- Switchboard
- How to make a fake contribution
- The epic and banner
- Environments
- Tech stack
- Supported browsers
- Contributions Internationalisation
- Payment method internationalisation in Guardian Weekly
- Print fulfilment/delivery
- Updating the acquisitions model
- Runscope testing
- Scala Steward for dependency management
- Alarm Investigations
- Ticker data
- Ophan
- Quantum Metric
- [Google Tag Manager] (https://github.com/guardian/support-frontend/wiki/Google-Tag-Manager)