|
| 1 | +# 🙋♀️ Abby |
| 2 | + |
| 3 | +Abby is a simple but powerful A/B testing library. |
| 4 | + |
| 5 | +The library lets you easily setup your **experiments** and their **control** and **variation** groups, **track** your visitors and assign them to a group, get detailed statistics including recommended **sample sizes** and determining the confidence of your results, including when an experiment have achieved **statistical significance**. |
| 6 | + |
| 7 | +The confidence is calculated using the [z-score](https://en.wikipedia.org/wiki/Standard_score) and [p-value](https://en.wikipedia.org/wiki/P-value) of your results, to see if the [null hypothesis](http://en.wikipedia.org/wiki/Null_hypothesis) can be rejected. An accompanying minimum [sample size](https://en.wikipedia.org/wiki/Sample_size_determination) is also calculated using a [two-tailed test](https://en.wikipedia.org/wiki/One-_and_two-tailed_tests) to control the [false discovery rate](https://en.wikipedia.org/wiki/False_discovery_rate). |
| 8 | + |
| 9 | +Abby is dependency free, and completely database agnostic, meaning it simply works with data you provide it with, and exposes a variety of methods for you to store the result in your own storage of choice. |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +- PHP 5.4.0 or higher |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +``` |
| 18 | +composer require andreekeberg/abby |
| 19 | +``` |
| 20 | + |
| 21 | +## Basic usage |
| 22 | + |
| 23 | +### Tracking a user |
| 24 | + |
| 25 | +```php |
| 26 | +// Setup a new Token instance |
| 27 | +$token = new Abby\Token(); |
| 28 | + |
| 29 | +// If we can't find an existing token cookie, generate one and set tracking cookie |
| 30 | +if (!$token->getValue()) { |
| 31 | + $token->generate()->setCookie(); |
| 32 | +} |
| 33 | + |
| 34 | +// Setup a User instance |
| 35 | +$user = new Abby\User(); |
| 36 | + |
| 37 | +// Associate the token with our user |
| 38 | +$user->setToken($token); |
| 39 | +``` |
| 40 | + |
| 41 | +### Adding existing user experiments to a user instance |
| 42 | + |
| 43 | +```php |
| 44 | +// List of experiments associated with a tracking token |
| 45 | +$data = [ |
| 46 | + [ |
| 47 | + 'id' => 1, |
| 48 | + 'group' => 1, |
| 49 | + 'converted' => false |
| 50 | + ] |
| 51 | +]; |
| 52 | + |
| 53 | +// Loop through users existing experiments and add them to our user instance |
| 54 | +foreach ($data as $item) { |
| 55 | + // Setup experiment instance based on an existing experiment |
| 56 | + $experiment = new Abby\Experiment([ |
| 57 | + 'id' => $item['id'] |
| 58 | + ]); |
| 59 | + |
| 60 | + // Setup a group instance based on stored data |
| 61 | + $group = new Abby\Group([ |
| 62 | + 'type' => $item['group'] |
| 63 | + ]); |
| 64 | + |
| 65 | + // Add the experiment (including their group and whether they have |
| 66 | + // already converted) to our user instance |
| 67 | + $user->addExperiment($experiment, $group, $item['converted']); |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +### Including the using in new experiments |
| 72 | +```php |
| 73 | +// Experiment data |
| 74 | +$data = [ |
| 75 | + 'id' => 2 |
| 76 | +]; |
| 77 | + |
| 78 | +// Make sure the experiment isn't already in the users list |
| 79 | +if (!$user->hasExperiment($data['id'])) { |
| 80 | + // Setup a new experiment instance |
| 81 | + $experiment = new Abby\Experiment([ |
| 82 | + 'id' => $data['id'] |
| 83 | + ]); |
| 84 | + |
| 85 | + // Assign the user to either control or variation in the experiment |
| 86 | + $group = $user->assignGroup($experiment); |
| 87 | + |
| 88 | + // Add the experiment (including assigned group) to our user instance |
| 89 | + $user->addExperiment($experiment, $group); |
| 90 | +} |
| 91 | + |
| 92 | +// Getting updated user experiment list |
| 93 | +$user->getExperiments(); |
| 94 | + |
| 95 | +// Store updated experiment list for our user |
| 96 | +``` |
| 97 | + |
| 98 | +### Delivering a custom experience based on group participation |
| 99 | + |
| 100 | +```php |
| 101 | +// Experiment data |
| 102 | +$data = [ |
| 103 | + 'id' => 1 |
| 104 | +]; |
| 105 | + |
| 106 | +// If the user is part of the variation in our experiment |
| 107 | +if ($user->inVariation($data['id'])) { |
| 108 | + // Apply a custom class to an element, load a script, etc. |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +### Defining a user conversion in an experiment |
| 113 | + |
| 114 | +```php |
| 115 | +// Experiment data |
| 116 | +$data = [ |
| 117 | + 'id' => 1 |
| 118 | +]; |
| 119 | + |
| 120 | +// On a custom experiment goal, check if user is a participant and define a conversion |
| 121 | +if ($user->isParticipant($data['id'])) { |
| 122 | + $user->setConverted($data['id']); |
| 123 | +} |
| 124 | + |
| 125 | +// Getting updated user experiment data |
| 126 | +$user->getExperiments(); |
| 127 | + |
| 128 | +// Store updated data for our user |
| 129 | +``` |
| 130 | + |
| 131 | +### Getting experiment results |
| 132 | + |
| 133 | +```php |
| 134 | +// Setup experiment instance with stored results |
| 135 | +$experiment = new Abby\Experiment([ |
| 136 | + 'groups' => [ |
| 137 | + [ |
| 138 | + 'name' => 'Control', |
| 139 | + 'size' => 3000, |
| 140 | + 'conversions' => 300 |
| 141 | + ], |
| 142 | + [ |
| 143 | + 'name' => 'Variation', |
| 144 | + 'size' => 3000, |
| 145 | + 'conversions' => 364 |
| 146 | + ] |
| 147 | + ] |
| 148 | +]); |
| 149 | + |
| 150 | +// Retrieve the results |
| 151 | +$result = $experiment->getResult(); |
| 152 | + |
| 153 | +// Get the winner |
| 154 | +$winner = $result->getWinner(); |
| 155 | + |
| 156 | +/** |
| 157 | + * Get whether we can be confident of the result (even if we haven't |
| 158 | + * reached the minimum group size for each variant) |
| 159 | + */ |
| 160 | + |
| 161 | +$confident = $result->isConfident(); |
| 162 | + |
| 163 | +/** |
| 164 | + * Get the minimum sample size required for each group to reach statistical |
| 165 | + * significance, given the control groups current conversion rate (based on |
| 166 | + * the configured minimumDetectableEffect) |
| 167 | + */ |
| 168 | + |
| 169 | +$minimum = $result->getMinimumGroupSize(); |
| 170 | + |
| 171 | +/** |
| 172 | + * Get whether the results are statistically significant |
| 173 | + */ |
| 174 | + |
| 175 | +$significant = $result->isSignificant(); |
| 176 | + |
| 177 | +/** |
| 178 | + * Get complete experiment result |
| 179 | + */ |
| 180 | + |
| 181 | +$summary = $result->getAll(); |
| 182 | +``` |
| 183 | + |
| 184 | +## Documentation |
| 185 | + |
| 186 | +* [Experiment](docs/Experiment.md) |
| 187 | +* [Token](docs/Token.md) |
| 188 | +* [User](docs/User.md) |
| 189 | +* [Group](docs/Group.md) |
| 190 | +* [Result](docs/Result.md) |
| 191 | + |
| 192 | +## Changelog |
| 193 | + |
| 194 | +Refer to the [changelog](CHANGELOG.md) for a full history of the project. |
| 195 | + |
| 196 | +## License |
| 197 | + |
| 198 | +Abby is licensed under the [MIT license](LICENSE). |
0 commit comments