Skip to content

Commit

Permalink
Merge pull request #1 from mat-b-/mat-b--patch-1
Browse files Browse the repository at this point in the history
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']);
}
  • Loading branch information
mat-b- committed Feb 19, 2015
2 parents 673d79f + 5cd81e6 commit 45e266e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions phpab.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 45e266e

Please sign in to comment.