AB-Test-Initialization
# AB Test Initialization
<!-- Output copied to clipboard! -->
<!-----
NEW: Check the "Suppress top comment" option to remove this info from the output.
Conversion time: 0.233 seconds.
Using this Markdown file:
1. Paste this output into your source file.
2. See the notes and action items below regarding this conversion run.
3. Check the rendered output (headings, lists, code blocks, tables) for proper
formatting and use a linkchecker before you publish this page.
Conversion notes:
* HTML and Markdown from Docs version 1.0
* Thu Oct 21 2021 09:45:04 GMT-0000 (UTC)
* Source doc: AB Test Initialization
----->
Currently AB initialization has a check on **each AB test** for whether a user is already in the AB, or that the user meets the entry criteria.
in_clean_ab_new_users = user_in_ab_test?('clean_ab_new_users')
individual_ab_test_initialization({
name: 'clean_ab_new_users',
groups: ['test_new_users', 'control'],
do_ab_test: in_clean_ab_new_users || is_new_user,
})
If the check for whether the user is already in the AB is left out (by mistake), then the user could enter an AB, and then exit the AB based on taking some action that does not meet the entry criteria.
individual_ab_test_initialization({
name: 'clean_ab_new_users',
groups: ['test_new_users', 'control'],
do_ab_test: in_clean_ab_new_users || is_new_user,
})
Once a user has entered an AB, we should not be removing them (and possibly re-adding them) to the AB test based on user actions. Once a user has entered an AB, they should remain in that AB.
**<span style="text-decoration:underline;">The suggestion:</span>** to make the check for whether a user is already in an AB to a higher level, so that the code does not need to be repeated on every new test.
Could add to this: \
` def individual_ab_test_initialization(ab_test)`
@globals ||= {}
if @globals["ACTIVE_AB_TESTS"].blank?
@globals["ACTIVE_AB_TESTS"] = {}
end
test_name = ab_test[:name]
if (ab_test[:do_ab_test] || cookies[test_name].present?)
popout_active = ab_test[:popout_active]
if cookies[test_name].present?
globals["ACTIVE_AB_TESTS"][test_name] = {
"name" => test_name,
"group" => cookies[test_name],
"popout_active" => popout_active,
}
else
powr_ab(test_name, *ab_test[:groups]) do |group|
globals["ACTIVE_AB_TESTS"][test_name] = {
"name" => test_name,
"group" => group,
"popout_active" => popout_active,
}
end
end
end
end
Followup/related question: \
- why would you ever use `add_ab_test` instead of `individual_ab_test_initialization` ?