-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Added badges to indicate various package status docs: Added missing docs for `react-ab-testing` and `py-ab-testing`, so the `NPM` and `PYPI` web interface will show proper descriptions.
- Loading branch information
BananaWanted
authored and
BananaWanted
committed
Mar 16, 2020
1 parent
23ca5d9
commit 245955b
Showing
4 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Py AB Testing | ||
|
||
AB testing library supporting multi-variance testing with a deterministic algorithm not requiring any complex backend or database. | ||
|
||
The segmentation logic is maintained in the AB testing client and based itself on a centralized configuration. The cohort assignment logic is deterministic and follows a simple hash pattern based on the `crc32c` algorithm (`crc32c(userId, crc32c(experimentName)) % 100`) | ||
|
||
# Installation | ||
|
||
```sh | ||
pip install py-ab-testing | ||
# or | ||
pipenv install py-ab-testing | ||
``` | ||
|
||
# Usage | ||
|
||
Note: The `config` variable holds an `dict` with [configuration file format that documented here](../../README.md). | ||
|
||
```python | ||
from ABTesting import ABTestingController | ||
|
||
user_profile = { | ||
'persona': user.persona, | ||
'employee': user.isEmployee, | ||
} | ||
|
||
controller = ABTestingController(config, user.id, user_profile) | ||
cohort = controller.get_cohort('experiment-name') | ||
|
||
if cohort == 'blue': | ||
do_something() | ||
elif cohort == 'red': | ||
do_something_else() | ||
else: | ||
do_default_behavior() | ||
``` | ||
|
||
# Protecting Private Information | ||
|
||
Similar to the Javascript SDKs, the package comes with an optional util for hashing private information with `sha256`. | ||
|
||
## Prepare config file BEFORE make it public | ||
|
||
```python | ||
from ABTesting.utils import hash_dict | ||
|
||
config['salt'] = salt | ||
for experiment in config['experiments']: | ||
for cohort in experiment['cohorts']: | ||
cohort['force_include'] = hash_dict(cohort['force_include'], salt) | ||
``` | ||
|
||
## In runtime | ||
|
||
```python | ||
from ABTesting.utils import hash_dict | ||
|
||
hashed_user_profile = hash_dict( | ||
{ | ||
'persona': user.persona, | ||
'employee': user.isEmployee, | ||
}, | ||
salt | ||
) | ||
|
||
# Make sure config is hashed with the same salt | ||
controller = ABTestingController(config, user.id, hashed_user_profile) | ||
``` | ||
|
||
# Credits | ||
|
||
Made with ❤️ by [Zhang Tao](https://github.com/BananaWanted) and [Simon Boudrias](https://github.com/SBoudrias) from the App Annie Beijing office. | ||
|
||
Available for public use under the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# React AB Testing | ||
|
||
# Installation | ||
|
||
```sh | ||
npm install @appannie/react-ab-testing | ||
# or | ||
yarn add @appannie/react-ab-testing | ||
``` | ||
|
||
# Getting Started | ||
|
||
Wrap your app with the `ABTestingController` | ||
|
||
```js | ||
import { ABTestingController } from '@appannie/react-ab-testing'; | ||
|
||
const MyApp = ({ user }) => { | ||
const profile = { | ||
persona: user.persona, | ||
employee: user.isEmployee, | ||
}; | ||
|
||
return ( | ||
<ABTestingController config={testConfig} userId={user.id} userProfile={profile}> | ||
<App /> | ||
</ABTestingController> | ||
); | ||
}; | ||
``` | ||
|
||
The required props are: | ||
|
||
1. `config`: the configuration object. | ||
2. `userId`: a unique identifier for your current user. This ID should be the same across visits to make sure your user always end up in the same cohorts. It can a `string` or a `number`. | ||
3. `userProfile`: a key/value map used to force include a user in given cohorts. | ||
|
||
Then within your app, check the cohort a user is assigned to using the `useCohortOf` hook. | ||
|
||
```js | ||
import { useCohortOf } from '@appannie/react-ab-testing'; | ||
|
||
const Component = () => { | ||
const cohort = useCohortOf('experiment-name'); | ||
|
||
switch (cohort) { | ||
case 'blue': | ||
return <BlueButton />; | ||
case 'red': | ||
return <RedButton />; | ||
// 'control' is the default cohort. All experiments have a control cohort. | ||
case 'control': | ||
default: | ||
return <Default />; | ||
} | ||
}; | ||
``` | ||
|
||
Note: The [configuration file format is documented here](../../README.md). | ||
|
||
# Credits | ||
|
||
Made with ❤️ by [Zhang Tao](https://github.com/BananaWanted) and [Simon Boudrias](https://github.com/SBoudrias) from the App Annie Beijing office. | ||
|
||
Available for public use under the MIT license. |