forked from innocraft/php-experiments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_redirect_test.php
34 lines (26 loc) · 1.24 KB
/
url_redirect_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
* Example for a very simple split test where we have the original version (added automatically),
* a layout1 variation and a layout2 variation. Each variation will be activated in 33.3% of the time
* randomly.
*/
date_default_timezone_set('utc');
use InnoCraft\Experiments\Experiment;
include_once '../vendor/autoload.php';
$variations = [
['name' => 'layout1', 'url' => 'https://www.innocraft.com/layout1'],
['name' => 'layout2', 'url' => 'https://www.innocraft.com/layout2']
// ['name' => 'original'] is added in the background
];
$experiment = new Experiment('experimentName', $variations);
// to get a randomly activated variation or a previously forced variation call "getActivatedVariation"
$activated = $experiment->getActivatedVariation();
// will either not redirect if the original version gets activated, or execute a redirect to one of the
// two specified urls "https://www.innocraft.com/layout1" or "https://www.innocraft.com/layout2". For Piwik
// and possible other tools to know which variation was activated, 2 url parameters will be appended to the
// URL
$activated->run();
// ALTERNATIVELY you could handle the logic manually
if ($activated->getName() === 'layout1') {
header('Location: ' . $activated->getUrl());
}