Skip to content

Instantly share code, notes, and snippets.

@Mindgames
Last active July 25, 2016 14:41
Show Gist options
  • Save Mindgames/f10ba7be5f8019ffc04bab5c97953508 to your computer and use it in GitHub Desktop.
Save Mindgames/f10ba7be5f8019ffc04bab5c97953508 to your computer and use it in GitHub Desktop.
When user click link send it to one of X random Y
<!-- Add this where you want your link, if you already have a element or button you would like to use, just add onClick="randomMe" to the element code, see example -->
<a onClick="randomMe()" rel="nofollow" href="#">Link do ankiety</a>
<!-- Add this script anywhere on page, it will exectue when user click link / element and will give user a random number between 1 and 100 where we send all with 50 or less to one url and the others with more then 50 to the other one, that should give us a likley 50/50 splitt over time -->
<script>
function randomMe() {
// Generate a number between 1 and 100
var myNumber = Math.floor((Math.random() * 100) + 1);
// If number is over 50..
if (myNumber > 50) {
// Add first url
location.href = "https://ankiety.kozminski.edu.pl/index.php/844712/lang-pl";
// If number is 50 or less..
} else {
// Add second url
location.href = "https://ankiety.kozminski.edu.pl/index.php/126449/lang-pl";
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment