From 5cd81e6366330f0d712a3f3dc937edf78b663e97 Mon Sep 17 00:00:00 2001 From: Mateusz Barucha Date: Thu, 19 Feb 2015 18:36:17 +0100 Subject: [PATCH] Update phpab.php New set_current_variation () function. It's now possible to redirect users to specific experiment (e.g. from newsletter, or another page) using string queries, like www.example.com?experiment=control if (isset($_GET['experiment'])) { $phpab->set_current_variation($_GET['experiment']); } --- phpab.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/phpab.php b/phpab.php index 4802bc1..2271451 100644 --- a/phpab.php +++ b/phpab.php @@ -150,6 +150,30 @@ public function set_tag ($t) $this->tag = $t; } + public function set_current_variation ($new) + { + if($this->current_variation != '!unset' && $this->current_variation_key != -1) + { + return FALSE; + } + + array_unshift($this->variations, array('name' => 'control', 'value' => '')); + + $this->current_variation_key = 0; + foreach($this->variations as $n => $v) + { + if($v['name'] == $new) + { + $this->current_variation = $new; + return TRUE; + } + $this->current_variation_key++; + } + + unset($this->current_variation_key); + return FALSE; + } + public function add_variation ($n, $v = '') { $n = trim(strtolower($n));