Skip to content

Instantly share code, notes, and snippets.

@thomasfl
Created December 20, 2011 14:06
Show Gist options
  • Select an option

  • Save thomasfl/1501670 to your computer and use it in GitHub Desktop.

Select an option

Save thomasfl/1501670 to your computer and use it in GitHub Desktop.
Simple A/B split testing template.
<html>
<head>
<script language="javascript">
var regex = /uio_a_b_test=([^\;]+)/;
var match = regex.exec(document.cookie);
if(match === null){
var randomnumber = Math.floor(Math.random()*100);
var days=14;
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
if( randomnumber > 50 ){
document.cookie = "uio_a_b_test=index_a.html" + expires;
location.replace("index_a.html");
} else {
document.cookie = "uio_a_b_test=index_b.html" + expires;
location.replace("index_b.html");
}
} else {
location.replace(match[1]);
}
</script>
<meta http-equiv="refresh" content="1; url=index_a.html">
</head>
<body>
<a href="index_a.html">Fortsett / Continue</a>
</body>
</html>
@thomasfl
Copy link
Author

Redirects users randomly to two different pages. Uses cookies to redirect users to same page as previously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment