Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ali asaria
authored and
ali asaria
committed
Mar 15, 2010
1 parent
02c127f
commit c6030db
Showing
86 changed files
with
14,618 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<buildpath> | ||
<buildpathentry kind="src" path=""/> | ||
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/> | ||
</buildpath> |
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,3 @@ | ||
.svn | ||
.DS_Store | ||
|
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>php_ab_testing_redis</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.wst.validation.validationbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.dltk.core.scriptbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.php.core.PHPNature</nature> | ||
</natures> | ||
</projectDescription> |
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,3 @@ | ||
#Sat Feb 20 14:02:16 EST 2010 | ||
eclipse.preferences.version=1 | ||
include_path=0;/php_ab_testing_redis |
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,24 @@ | ||
Author: | ||
This project is by Ali Asaria created for Well.ca Inc. 2010. The idea for the program is based on the | ||
project "Vanity" by Assaf Arkin -- a Rails A/B testing tool. | ||
|
||
The philosophy behind this program is | ||
|
||
|
||
About Well.ca: | ||
Well.ca is Canada's largest online health and beauty store. | ||
|
||
|
||
License: | ||
|
||
|
||
|
||
Credits: | ||
|
||
- Idea and style inspired by Vanity for Rails by Assaf Arkin http://vanity.labnotes.org/ | ||
- See Assaf's credits here: http://vanity.labnotes.org/credits.html | ||
- Redis client library - Redis PHP Bindings - http://code.google.com/p/redis/ - Copyright 2009 Ludovico Magnocavallo, Copyright 2009 Salvatore Sanfilippo - Released under the same license as Redis. | ||
- jQuery by John Resig - http://jquery.com/ - MIT License or (GPL) Version 2. | ||
- Flot copyright of IOLA and Ole Laursen, released under the MIT license. | ||
- Buttons http://www.halmatferello.com/lab/pure-css-buttons/ Licensed under GPL and MIT. | ||
|
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,13 @@ | ||
A/B TESTING FOR PHP USING REDIS | ||
|
||
To set up this project: | ||
|
||
1. Start up redis. Specify the host name and db number in config/configure.php | ||
2. Define things to measure in config/metrics.php following the declaration pattern in the file's example | ||
3. Define the tests you'd like to perform in config/tests.php following the pattern there. Specify a metric for each test as shown in the example | ||
4. include core.php in your code. | ||
5. make sure to set ab_participant_specify_id("a_unique_id_for_this_user") at least once | ||
6. for every metric, call: ab_track("name_of_your_metric"); | ||
7. every time you need a choice, call: ab_test("name_of_your_ab_test"); and it will return a string represing the alternative to use | ||
|
||
that is all. |
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,12 @@ | ||
|
||
- Add author and credit information | ||
- Add notion of statistical significance based on Vanity ala http://20bits.com/articles/statistical-analysis-and-ab-testing/ | ||
- Allow ability to clear the data from a test | ||
- Add IP restriction on report.php | ||
- Have metrics that can have size, and related results that would be distributions : E.g. # of Pages viewed. This would be more complicated. | ||
- Fix date_time issues where I just use unicode time and not proper date math (can't find docs for date match in PHP 5.2) | ||
|
||
|
||
Suggestions | ||
- Have an option on a metric so that it is only initialized upon request | ||
- Have a flag where this runs without redis for debugging (e.g. file-based or sqlite) |
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,18 @@ | ||
<?php | ||
|
||
$config['redis_host'] = 'localhost'; | ||
$config['redis_port'] = 6379; //redis's default port is 6379 | ||
$config['redis_db_number'] = 0; | ||
|
||
|
||
$config['USE_AUTHENTICATION'] = true; // Use (internal) authentication - best choice if | ||
// no other authentication is available | ||
// If set to 0: | ||
// There will be no further authentication. You | ||
// will have to handle this by yourself! | ||
// If set to 1: | ||
// You need to change ADMIN_PASSWORD to make | ||
// this work! | ||
$config['ADMIN_USERNAME'] = 'admin'; // Admin Username | ||
$config['ADMIN_PASSWORD'] = 'elephant'; // Admin Password - CHANGE THIS TO ENABLE!!! | ||
|
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,19 @@ | ||
<?php | ||
|
||
//example: | ||
/* | ||
$ab_metrics['conversion'] = array( | ||
"name" => "conversion", //this must be the same as the key above. Whitespace is not allowed | ||
"description" => "When someone completes checkout" | ||
); | ||
*/ | ||
|
||
$ab_metrics['conversion'] = array( | ||
"name" => "conversion", | ||
"description" => "When someone completes checkout" | ||
); | ||
|
||
$ab_metrics['signup'] = array( | ||
"name" => "signup", | ||
"description" => "When someone signsup for a newsletter" | ||
); |
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,26 @@ | ||
<?php | ||
//example: | ||
/* | ||
$ab_tests['checkout_button_color'] = array( | ||
"name" => "checkout_button_color", //must be the same as the key above. Whitespace is not allowed | ||
"description" => "What colour should we make the checkout button", | ||
"alternatives" => array("green", "red", "blue"), //all possible alternatives | ||
//as an array of strings | ||
"metrics" => array('conversion') //what metrics refer to a conversion here? this is an array of strings | ||
//that correspond to metrics in the config/metrics file | ||
); | ||
*/ | ||
|
||
$ab_tests['checkout_button_color'] = array( | ||
"name" => "checkout_button_color", | ||
"description" => "What colour should we make the checkout button", | ||
"alternatives" => array("green", "red", "blue"), | ||
"metrics" => array('conversion', 'signup') | ||
); | ||
|
||
$ab_tests['checkout_button_size'] = array( | ||
"name" => "checkout_button_size", | ||
"description" => "How big should we make it?", | ||
"alternatives" => array("small", "medium", "large"), | ||
"metrics" => array('conversion') | ||
); |
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,137 @@ | ||
<?php | ||
|
||
/* | ||
* This is the file you include in order to use the AB testing suite | ||
* | ||
* Three functions are exposed to the public: | ||
* ab_participant_id(...) | ||
* ab_test(...) | ||
* ab_track(...) | ||
* | ||
* Run ab_partipant_id before anything else | ||
*/ | ||
|
||
/* | ||
* INCLUDES | ||
*/ | ||
//include the redis connector | ||
include_once('redis/redis.php'); | ||
|
||
include('config/configure.php'); | ||
|
||
//bring in the custom defined metrics and tests | ||
include('config/metrics.php'); | ||
include('config/tests.php'); | ||
|
||
include('lib/metrics.php'); | ||
include('lib/tests.php'); | ||
|
||
$ab_participant_id = -1; | ||
|
||
/* | ||
* Try to connect to redis | ||
*/ | ||
$r =& new Redis($config['redis_host'],$config['redis_port']); | ||
$redis_connected = $r->connect(); | ||
|
||
|
||
if ($redis_connected) | ||
{ | ||
$r->select_db($config['redis_db_number']); | ||
//$r->flushdb(); | ||
} | ||
else | ||
{ | ||
} | ||
|
||
|
||
/************************************ | ||
* CORE FUNCTIONS | ||
* | ||
* The following three functions | ||
* | ||
* ab_participant_id(...) | ||
* ab_test(...) | ||
* ab_track(...) | ||
* | ||
* are the only three functions exposed to the public. | ||
* | ||
* For documentation on how to use this, read README.txt | ||
*/ | ||
|
||
/** | ||
* | ||
* Sets the unique participant ID for the current visitor | ||
* this must be set once and must be done before using any | ||
* other of the ab testing functions. | ||
* @param $id - the unique ID of the visitor | ||
* @return (nothing) | ||
*/ | ||
function ab_participant_id ($id) | ||
{ | ||
global $ab_participant_id; | ||
global $redis_connected; | ||
|
||
$ab_participant_id = $id; | ||
|
||
if ($redis_connected) | ||
{ | ||
//set up the metrics (this should loop through them and link them to associated ab tests | ||
ab_metrics_initialize(); | ||
ab_tests_initialize(); | ||
} | ||
} | ||
|
||
/** | ||
* Runs a test. | ||
* @param $test is a string that specifieds the test to run | ||
* @return a string representing the alternative to run. will return null if the test isn't found | ||
*/ | ||
function ab_test($test) | ||
{ | ||
global $redis_connected; | ||
global $ab_tests; | ||
|
||
//test if the test exists, otherwise return null | ||
if (!array_key_exists($test, $ab_tests)) return null; | ||
|
||
if ($redis_connected) | ||
{ | ||
return ab_tests_test($test); | ||
} | ||
else | ||
{ | ||
//the following function will still work, even without | ||
//a connection to redis | ||
return ab_tests_test($test); | ||
} | ||
} | ||
|
||
/** | ||
* Track a metric. | ||
* @param $metric : a string representing the metric to track | ||
* @param $value : (optional) how many conversions happened (e.g. use this | ||
* for add to cart if the person adds 10 to the cart) default = 1 | ||
* @return nothing | ||
*/ | ||
function ab_track($metric, $value = 1) | ||
{ | ||
global $redis_connected; | ||
|
||
if ($redis_connected) | ||
{ | ||
if ($ab_participant_id != -1) | ||
{ | ||
ab_metrics_track($metric, $value = 1); | ||
} | ||
} | ||
else | ||
{ | ||
//do nothing | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.