Split testing script?

muslickzz

Junior Member
Joined
May 23, 2008
Messages
110
Reaction score
46
Anyone got or know of a decent script or bit of code that will effectively let me split test from a redirect?

IE: click the link.. get to the page and be redirected on a 50/50 basis to two offers?

Thanks!
-Mus
 
I understand that this thread is wicked old, but I was about to start one with the same question and figured I would ask here first. Anyone know?
 
Not sure if I get the question, but it seems pretty easy to me.

Basically you set a variable with a random value between 1 and 2 (each programming language has a command to generate a random number).

Then use a switch (or a if, given it's just 2 options) to choose where to redirect.
 
In plain php english :)

something like this:

PHP:
$urls = array("http://yourUrl/landingpage1.html", "http://yourUrl/landingpage2.html");
header("Location: " . $urls[rand(0,count($urls)-1)]);

This will split test any number of pages uniformly (on a large enough scale). Read more about rand if you want.... Additionally, you can use a DB or a file to write number of visits and then read this number each time you visit the page... something like

PHP:
// read the next number
$number = intval(@file_get_contents('file_path')); // write a number to this
$urls = array("http://yourUrl/landingpage1.html", "http://yourUrl/landingpage2.html");
header("Location: " . $urls[$number % (count($urls)-1)]);

// now write (number+1) to a file
$fh = fopen('file_path', 'w');
fwrite($fh, ($number+1));
fclose($fh);

I like the first version better, since rand should do the good job... the problem with second one is that I'm not very sure what would happen if you get too much visits to the script - what if it comes to some rewriting and parallel access to your file with number... Database could solve this problem, but I'm too lazy to write this :)
 
PHP:
$urls = array("http://yourUrl/landingpage1.html", "http://yourUrl/landingpage2.html");
header("Location: " . $urls[rand(0,count($urls)-1)]);
This will split test any number of pages uniformly (on a large enough scale). Read more about rand if you want....
Much more elegant than the one I would have done.

Rep given ;)
 
Cheers for reps mate.

This solution evolved through time ;)
 
Back
Top