Skip to content

Instantly share code, notes, and snippets.

@doublejosh
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save doublejosh/59ec87a8fb1083c98661 to your computer and use it in GitHub Desktop.

Select an option

Save doublejosh/59ec87a8fb1083c98661 to your computer and use it in GitHub Desktop.
AB test a new JS feature
var should_show = $.cookie('testNameSpace');
// Allow A/B test override.
if ($('body.override').length > 0) should_show = 1;
// User is a yes OR no choice yet.
if (should_show == 1 || (should_show == null && Math.random() < 0.2)) {
//Set cookie to yes.
$.cookie('testNameSpace', 1, { path : '/' });
thingToTest();
}
else {
// Hide form untested users.
$.cookie('testNameSpace', 0, { path : '/' });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment