Skip to content

Instantly share code, notes, and snippets.

@mikesurowiec
Forked from frankpinto/maybe_on.js
Created October 11, 2012 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesurowiec/3871843 to your computer and use it in GitHub Desktop.
Save mikesurowiec/3871843 to your computer and use it in GitHub Desktop.
Conditional Synapse Embed
<script type="text/javascript">
var onswipeSometimes = function() {
var usr = "f";
var numToRedirect = 0.75; // percent of people to redirect
var randomNumber = Math.random(); // [0, 1)
if (randomNumber <= numToRedirect) {
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