Skip to content

Instantly share code, notes, and snippets.

@cballou
Last active March 9, 2017 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cballou/dbbe7e181a52edd8b7dead7196b28f45 to your computer and use it in GitHub Desktop.
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.
<?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>'
),
)
)
)
);
<?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');
# 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'
<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>
<?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>
# 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 ""
<?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