Install the latest version of phpA/B
- Download the latest version of phpA/B.
Contact Brian Cray for commercial licensing requests - Unzip phpab.zip.
- Upload phpab.php anywhere on your web server.
-
Include phpab.php at the top of your PHP page.
- <?php
- require_once('/path/to/phpab.php'); // include phpab.php
Add variations to web pages
-
Setup the variation at the top of your PHP page.
- <?php
- $my_test = new phpab('my_test'); // set the name of the a/b test
- $my_test->add_variation('my_variation', '<p>My alternative content</p>'); // add a variation
-
Wrap control content in
{phpab}tags to run HTML variations. Whatever is inside{phpab}tags will be replaced with a variation or left alone if the user is in the control group.- {phpab my_test}<p>My control content</p>{/phpab my_test} <!-- Content wrapped in {phpab} tags -->
-
Add CSS variations. phpA/B will automatically add the name of the current variation as a class name to the
<body>tag.- p
- {
- color: black; /* control styles */
- }
- .phpab-my_variation p
- {
- color: red; /* variation styles */
- }
Track results in Google Analytics
phpA/B should automatically detect your Google Analytics tracking code and add the necessary lines of code. Give Google Analytics a few days to begin showing the results of your A/B tests.

- Open Google Analytics to the website running phpA/B.
- In the left menu, go to Visitors » Custom Variables.
- In the main content, you should see a list of the tests you're running. Drill down on a test by clicking it.
- The main content will list usage statistics on each of your variations.
For more advanced segments reporting based on your variations, read this article.