Skip to content

Instantly share code, notes, and snippets.

@frankpinto
Created October 11, 2012 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save frankpinto/3870081 to your computer and use it in GitHub Desktop.
Save frankpinto/3870081 to your computer and use it in GitHub Desktop.
Conditional Synapse Embed
<script type="text/javascript">
var onswipeSometimes = function() {
var usr = "f";
var fractionToRedirect = '3/4';
var parts = fractionToRedirect.split('/');
var total = parseInt(parts[1]);
var redirect = parseInt(parts[0]);
var randomNumber = Math.floor(Math.random()*total + 1); // Number between 1 and total inclusive
if (randomNumber <= redirect) {
var synapse = 'http://assets.onswipe.com/synapse/on.js?usr=' + usr;
var embed = document.createElement('script');
embed.setAttribute('type', 'text/javascript');
embed.setAttribute('id', 'onswipe_synapse');
embed.setAttribute('src', synapse);
var parent = document.getElementsByTagName('head')[0];
var first = parent.firstChild;
parent.appendChild(embed, first);
}
}();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment