Simple PHP Split Testing Script
Posted by: Chad in Internet Marketing, Testing & TrackingMany people use testing solutions that don’t perform well for testing. Some people just split Adwords traffic and disregard the rest of their traffic, which makes the test take longer and doesn’t give a truly valid result at the end of the test.
Instead of trying to sell you some overpriced, underperforming split testing product, I’ll just give you a good script I made about a year ago to do my testing.
I have another one that’s much more advanced, that is probably better than any other testing script available, but the problem is making it user friendly.
That’s going to be a problem with this one as well, because I make the scripts for me to use and making it user friendly is harder than making it functional.
I’ll try to explain how to set this script up as best as I can, but it might not be enough.
First we have the main testing script which will be named: index.php
You will place this in your home directory where your current index.htm or index.html file is located. It’s important that you rename your other index file to something else or this script will not work.
Browsers first look for index.htm and index.html before they look for index.php, so if one of those is still there, no one will get to the script.
The script begins with <#php and ends with #>
With this and the next script you will need to change the # to a ?. I couldn’t put the real begginning and end code here so I had to substitute the begginning and end of each script.
Just copy and paste it into notepad and then save it as index.php
Here it is:
<#php
header(”P3P: CP=\”CAO DSP AND SO ON\”");
$test = $HTTP_COOKIE_VARS[”test”];
$stats = file(”results.txt”);
if ($test == “”) {
$test = rand(1, 2);
setcookie(”test”,$test,time()+2419200);
if ($test == 1) {
$stats[0] = $stats[0] + 1;
$stats[0] = “$stats[0]\n”;
}
if ($test == 2) {
$stats[2] = $stats[2] + 1;
$stats[2] = “$stats[2]\n”;
}
}
if ($test == 1) {
$show = file_get_contents(”original.htm”);
}
if ($test == 2) {
$show = file_get_contents(”test.htm”);
}
$fp = fopen( “results.txt”, “w” );
fwrite( $fp, “$stats[0]$stats[1]$stats[2]$stats[3]” );
fclose( $fp );
echo $show;
#>
The reason for the header is because some browsers won’t except a cookie unless they recieve a privacy header.
The cookie is set for 2419200 seconds which works out to 4 weeks. You can edit this if you want, just remember to put the number in seconds.
Now what this script does is take new visitors to your website and randomly split them between your two pages and tag them with a cookie. The next time they return the cookie will tell the script that they have been there before and it will show them the same page they saw last time. It will continue to do this until the cookie expires.
This script does not use any redirects because they can mess up your SEO(Search Engine Optimization). The script runs the test Dynamicly which means the webpage is created on the fly.
Now you need understand the two files it draws the webpage from. The first is original.htm, which is your control, or current webpage. The second is test.htm, which is the second version of your webpage that has the changes your are testing.
Make sure both of these files are in the same directory as the testing script.
………………………………..
Now for the Thank You script that records sales. You will link to this script from your Thank You page(where customers are sent after ordering or subscribing) with a image link.
Just place the following code somewhere on your Thankyou page:
< img border=”0″ src=”thankyou.php” width=”1″ height=”1″ >
(you’ll need to remove the space after < and the space before >)
It won’t change the way it looks but it will run the thankyou.php script when the webpage is loaded.
Ok here’s the script for the Thank You Script… Just name it thankyou.php and place it in the same directory as your thank you page.
<#php
header(”P3P: CP=\”CAO DSP AND SO ON\”");
$test = $HTTP_COOKIE_VARS[”test”];
$done = $HTTP_COOKIE_VARS[”done”];
$stats = file(”results.txt”);
if ($done == 1) {
exit;
}
if ($test == 1) {
$stats[1] = $stats[1] + 1;
$stats[1] = “$stats[1]\n”;
}
if ($test == 2) {
$stats[3] = $stats[3] + 1;
$stats[3] = “$stats[3]\n”;
}
setcookie(”done”,1,time()+6048000);
$fp = fopen( “results.txt”, “w” );
fwrite( $fp, “$stats[0]$stats[1]$stats[2]$stats[3]” );
fclose( $fp );
#>
Now we’re almost done but we still need to talk about the results.txt file. This is the file that records your visits and sales for each page in the test.
You need to make this file by opening Notepad and putting the following in it:
Start
0
0
0
0
End
Don’t put the start or end in the file, I just put those there to make it easier to understand. Just put the four zeros with each one on a new line.
Now save this as results.txt and upload it to the same directory as your thank you page.
You will probably want to CHMOD it to 666. Most FTP software has a CHMOD option that will let you set this. If it doesn’t, it will still probably work anyway.
When you want to check the current stats of your test you will need to look at this file. You’ll probably see something like this:
1342
12
1356
15
Here’s what it means:
1342 - Number of people that saw original.htm
12 - Number of sales from people that saw original.htm
1356 - Number of people that saw test.htm
15 - Number of sales from people that saw test.htm
And there you have it… Pretty simple eh?(laugh)
I hope everyone will be able to understand this but I know it will be like gibberish to some people. I don’t have time to offer any support for people with trouble but if enough people have the same problem I’ll try to help.
TIP:
Another big mistake people make when testing is not waiting until their results are statistically valid. The whole “40 actions” or “1000 visitors” or “Super Lost Testing Algorithm” won’t cut it.
None of those are based on real accepted statistics. The real way to tell if a result is statistically valid is to use a statistics equation called Chi Squared and in our case we add a Yates Correction. Please don’t try to learn how to do this by hand unless your good in math. I learned it awhile back and it was a pain in the butt.
Instead I suggest you use the simple calculator I made: http://www.200proofmarketing.com/statcalc.php
Just follow the instructions, enter your test results and it will tell you how valid your results are.










Entries (RSS)