Skip to content

Commit

Permalink
Merge pull request #5 from innocraft/renamesplittestvariation
Browse files Browse the repository at this point in the history
Rename split test variation to url redirect variation
  • Loading branch information
tsteur authored Dec 22, 2016
2 parents 11b9170 + 3b60368 commit 8a0ee23
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $activated = $experiment->getActivatedVariation();
echo $activated->getName();
```

Running a split test can be as easy as:
Running a split URL test can be as easy as:

```php
$variations = [
Expand Down
16 changes: 7 additions & 9 deletions docs/InnoCraft-Experiments-Experiment.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Get the set storage.

### trackVariationActivation

mixed InnoCraft\Experiments\Experiment::trackVariationActivation(\stdClass|\PiwikTracker $tracker, string $experimentName, string $variation)
mixed InnoCraft\Experiments\Experiment::trackVariationActivation(\stdClass|\PiwikTracker $tracker)

Tracks the activation of a variation using for example the Piwik Tracker. This lets Piwik know which variation
was activated and should be used if you track your application using the Piwik Tracker server side. If you are
Expand All @@ -164,19 +164,17 @@ usually tracking using the JavaScript Tracker, have a look at {@link getTracking


* Visibility: **public**
* This method is **static**.


#### Arguments
* $tracker **stdClass|PiwikTracker**
* $experimentName **string**
* $variation **string**
* $tracker **stdClass|PiwikTracker** - <p>The passed object needs to implement a <code>doTrackEvent</code> method accepting
three parameters $category, $action, $name</p>



### getTrackingScript

string InnoCraft\Experiments\Experiment::getTrackingScript(string $experimentName, string $variation)
string InnoCraft\Experiments\Experiment::getTrackingScript(string $experimentName, string $variationName)

Returns the JavaScript tracking code that you can echo in your website to let Piwik know which variation was
activated server side.
Expand All @@ -185,11 +183,11 @@ Do not pass variables from $_GET or $_POST etc. Make sure to escape the variable
to this method as you would otherwise risk an XSS.

* Visibility: **public**
* This method is **static**.


#### Arguments
* $experimentName **string**
* $variation **string**
* $experimentName **string** - <p>ExperimentName and VariationName needs to be passed cause we do not yet have a way
here to properly escape it to prevent XSS.</p>
* $variationName **string**


4 changes: 2 additions & 2 deletions docs/InnoCraft-Experiments-Variations-CallableVariation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Methods

### getCallable

mixed InnoCraft\Experiments\Variations\CallableVariation::getCallable()

callable InnoCraft\Experiments\Variations\CallableVariation::getCallable()

Returns a callable if the option was passed.



Expand Down
111 changes: 111 additions & 0 deletions docs/InnoCraft-Experiments-Variations-UrlRedirectVariation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
InnoCraft\Experiments\Variations\UrlRedirectVariation
===============






* Class name: UrlRedirectVariation
* Namespace: InnoCraft\Experiments\Variations
* Parent class: [InnoCraft\Experiments\Variations\StandardVariation](InnoCraft-Experiments-Variations-StandardVariation.md)







Methods
-------


### __construct

mixed InnoCraft\Experiments\Variations\StandardVariation::__construct(array $variation)





* Visibility: **public**
* This method is defined by [InnoCraft\Experiments\Variations\StandardVariation](InnoCraft-Experiments-Variations-StandardVariation.md)


#### Arguments
* $variation **array** - <p>eg array('name' => 'blueColor', 'percentage' => 50).
A name has to be given and can be also an ID, eg "4". Percentage is optional.
If given, it defines how much traffic this variation should get. For example defining
50 means, this variation will be activated in 50% of overall experiment activations.</p>



### getUrl

mixed InnoCraft\Experiments\Variations\UrlRedirectVariation::getUrl()





* Visibility: **public**




### getUrlWithExperimentParameters

mixed InnoCraft\Experiments\Variations\UrlRedirectVariation::getUrlWithExperimentParameters()





* Visibility: **public**




### run

void InnoCraft\Experiments\Variations\VariationInterface::run()

Runs / executes the given variation. Depending on the variation type a different action may be executed.

For example a redirect or calling a callable.

* Visibility: **public**
* This method is defined by [InnoCraft\Experiments\Variations\VariationInterface](InnoCraft-Experiments-Variations-VariationInterface.md)




### getName

string InnoCraft\Experiments\Variations\VariationInterface::getName()

Get the name of the variation.



* Visibility: **public**
* This method is defined by [InnoCraft\Experiments\Variations\VariationInterface](InnoCraft-Experiments-Variations-VariationInterface.md)




### getPercentage

string InnoCraft\Experiments\Variations\VariationInterface::getPercentage()

Get the percentage allocated to this variation. Only returns a percentage if a fixed percentage was allocated
to this variation. If no percentage is allocated, it will use the default percentage of a variation which depends
on the number of set variations within an experiment.



* Visibility: **public**
* This method is defined by [InnoCraft\Experiments\Variations\VariationInterface](InnoCraft-Experiments-Variations-VariationInterface.md)



2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ API Index
* [Transient](InnoCraft-Experiments-Storage-Transient.md)
* [Variations](InnoCraft-Experiments-Variations.md)
* [CallableVariation](InnoCraft-Experiments-Variations-CallableVariation.md)
* [SplitTestVariation](InnoCraft-Experiments-Variations-SplitTestVariation.md)
* [StandardVariation](InnoCraft-Experiments-Variations-StandardVariation.md)
* [UrlRedirectVariation](InnoCraft-Experiments-Variations-UrlRedirectVariation.md)
* [VariationInterface](InnoCraft-Experiments-Variations-VariationInterface.md)

2 changes: 1 addition & 1 deletion docs/generateDocs.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
./vendor/phpdocumentor/phpdocumentor/bin/phpdoc -d ../src/ -t xml/ --visibility="public" --template="xml"
./vendor/evert/phpdoc-md/bin/phpdocmd xml/structure.xml . --index="README.md"
./vendor/evert/phpdoc-md/bin/phpdocmd xml/structure.xml . --index README.md
rm -rf xml
2 changes: 1 addition & 1 deletion examples/ab_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* To see how to allocate different traffic to variations, how to force a variation and more have a look at
* the other examples. If you want to fully customize the behaviour of an experiment, have a look at
* "customize_and_extend.php". If you want to perform a split test, have a look at "split_test.php".
* "customize_and_extend.php". If you want to perform a split test, have a look at "url_redirect_test.php".
*/

date_default_timezone_set('utc');
Expand Down
2 changes: 1 addition & 1 deletion examples/callable_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
// and possible other tools to know which variation was activated, 2 url parameters will be appended to the
// URL
$activated = $experiment->getActivatedVariation();
$activated->run();
$activated->run();
2 changes: 0 additions & 2 deletions examples/split_test.php → examples/url_redirect_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* 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.
*
* To learn more about all the possible configs have a look at "ab_test_withConfig.php".
*/

date_default_timezone_set('utc');
Expand Down
4 changes: 2 additions & 2 deletions src/Variations.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use InvalidArgumentException;
use InnoCraft\Experiments\Variations\CallableVariation;
use InnoCraft\Experiments\Variations\SplitTestVariation;
use InnoCraft\Experiments\Variations\UrlRedirectVariation;
use InnoCraft\Experiments\Variations\StandardVariation;
use InnoCraft\Experiments\Variations\VariationInterface;

Expand Down Expand Up @@ -49,7 +49,7 @@ public function addVariation($variation)
if (is_array($variation)) {
// could be moved to a factory or so
if (isset($variation['url'])) {
$this->variations[] = new SplitTestVariation($this->experimentName, $variation);
$this->variations[] = new UrlRedirectVariation($this->experimentName, $variation);
} elseif (isset($variation['callable'])) {
$this->variations[] = new CallableVariation($variation);
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/Variations/CallableVariation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

class CallableVariation extends StandardVariation {

/**
* Returns a callable if the option was passed.
* @return callable
*/
public function getCallable()
{
if (isset($this->variation['callable'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

namespace InnoCraft\Experiments\Variations;

class SplitTestVariation extends StandardVariation {
class UrlRedirectVariation extends StandardVariation {

/**
* @var string|int
*/
private $experimentName;

/**
* SplitTestVariation constructor.
* A variation that can perform a redirect when passing a URL and executing the run method.
*
* @param string|int $experimentName
* @param array $variation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

use InnoCraft\Experiments\Variations\SplitTestVariation;
use InnoCraft\Experiments\Variations\UrlRedirectVariation;

include_once 'StandardVariationTest.php';

class SplitTestVariationTest extends StandardVariationTest {
class UrlRedirectVariationTest extends StandardVariationTest {

private $experimentName = 'myExperimentName';
private $variationName = 'myName';
Expand Down Expand Up @@ -56,7 +56,7 @@ private function buildSplitTestVariation($callable)

private function makeVariation($variation)
{
return new SplitTestVariation($this->experimentName, $variation);
return new UrlRedirectVariation($this->experimentName, $variation);
}

}
8 changes: 4 additions & 4 deletions tests/VariationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use InnoCraft\Experiments\Variations;
use InnoCraft\Experiments\Variations\StandardVariation;
use InnoCraft\Experiments\Variations\SplitTestVariation;
use InnoCraft\Experiments\Variations\UrlRedirectVariation;
use InnoCraft\Experiments\Variations\CallableVariation;

class CustomVariations extends Variations {
Expand Down Expand Up @@ -50,7 +50,7 @@ public function test_shouldConvertVariationsToInstances()
$this->assertCount(4, $variations);
$this->assertTrue($variations[0] instanceof StandardVariation);
$this->assertTrue($variations[1] instanceof StandardVariation);
$this->assertTrue($variations[2] instanceof SplitTestVariation);
$this->assertTrue($variations[2] instanceof UrlRedirectVariation);
$this->assertTrue($variations[3] instanceof CallableVariation);
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public function test_setVariations_overwritesExistingVariations_WorksFromArrayOr
$this->assertSame(2, $variations->getNumVariations());

$allVariations = $variations->getVariations();
$this->assertTrue($allVariations[0] instanceof SplitTestVariation);
$this->assertTrue($allVariations[0] instanceof UrlRedirectVariation);
$this->assertSame('variation4', $allVariations[0]->getName());
$this->assertTrue($allVariations[1] instanceof StandardVariation);
$this->assertSame('variation5', $allVariations[1]->getName());
Expand All @@ -112,7 +112,7 @@ public function test_addVariation_canAddNewVariationFromArray()
$allVariations = $variations->getVariations();

// verify variation added and converted to VariationInterface
$this->assertTrue($allVariations[1] instanceof SplitTestVariation);
$this->assertTrue($allVariations[1] instanceof UrlRedirectVariation);
$this->assertSame('variation4', $allVariations[1]->getName());

// verify old one not removed
Expand Down

0 comments on commit 8a0ee23

Please sign in to comment.