Last active
March 9, 2017 17:13
-
-
Save cballou/dbbe7e181a52edd8b7dead7196b28f45 to your computer and use it in GitHub Desktop.
Example of using Winston, a PHP AB/split testing library which utilizes machine learning and Redis.
This file contains hidden or 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
<?php | |
$config = array( | |
'tests' => array( | |
'signup-submit-button-test' => array( | |
'description' => 'A sample test', | |
'variations' => array( | |
array( | |
'id' => 'submit-default', | |
'text' => '<button type="submit" {{click}}>Submit</button>' | |
), | |
array( | |
'id' => 'submit-signup-now', | |
'text' => '<button type="submit" {{click}}>Signup Now</button>' | |
), | |
) | |
) | |
) | |
); |
This file contains hidden or 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
<?php | |
// returns: onclick="POP.Winston.event('name-of-your-test', 'SELECTED_VARIATION_ID', 'click');" | |
// where SELECTED_VARIATION_ID is the variation id found to be optimal/randomized by Winston | |
$winston->event('name-of-your-test', 'click'); |
This file contains hidden or 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
# example of adding a firewall whitelist rule using UFW on Ubuntu | |
sudo ufw allow from XXX.XXX.XXX to any port 6379 | |
# example of adding a firewall firewall using iptables | |
sudo iptables -A INPUT -s XXX.XXX.XXX -p tcp -m tcp --dport 6379 -j ACCEPT | |
sudo bash -c 'iptables-save > /etc/sysconfig/iptables' |
This file contains hidden or 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
<form <?php echo $winston->event('name-of-your-test', 'submit'); ?>> | |
<?php echo $winston->variation('name-of-your-test'); ?> | |
<button type="submit">Submit Form</button> | |
</form> |
This file contains hidden or 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
<?php | |
// include the composer autoloader | |
require_once 'vendor/autoloader.php'; | |
// load your configuration array from a file | |
$config = include('/path/to/config.php'); | |
// load the client library | |
$winston = new \Pop\Winston($config); | |
?> | |
<html> | |
<head><title>Sample</title></head> | |
<body> | |
<!-- show a test variation --> | |
<h1><?= $winston->test('my-first-headline-test'); ?></h1> | |
<!-- add an event separate from the test that also triggers a success --> | |
<button type="button" <?= $winston->event('my-first-headline-test', 'click'); ?>>Sample Button</button> | |
<!-- load the footer javascript (echo) --> | |
<?= $winston->javascript(); ?> | |
<!-- include the required jquery lib --> | |
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script type="text/javascript" src="/path/to/jquery.winston.js"></script> | |
</body> | |
</html> |
This file contains hidden or 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
# enable append-only file | |
appendonly yes | |
# enable fsync'ing every second (up to 1 second data loss) | |
# for no data loss, use 'appendfsync always' | |
appendfsync everysec | |
# disable snapshotting (RDB) | |
save "" |
This file contains hidden or 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
<?php | |
// include the composer autoloader | |
require_once 'vendor/autoloader.php'; | |
// load your configuration array from a file | |
$config = include('/path/to/config.php'); | |
// load the client library | |
$winston = new \Pop\Winston($config); | |
// we want the post data | |
$data = $_POST; | |
// determine which endpoint we're requesting | |
$uri = getenv('REQUEST_URI'); | |
if ($uri == 'winston/event') { | |
$winston->recordEvent($data); | |
} else if ($uri == 'winston/pageview') { | |
$winston->recordPageview($data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment