Skip to content

Instantly share code, notes, and snippets.

@abhiyerra
Created September 15, 2016 21:17
Show Gist options
  • Select an option

  • Save abhiyerra/e24637d3ede79fcda2307311e9ad58db to your computer and use it in GitHub Desktop.

Select an option

Save abhiyerra/e24637d3ede79fcda2307311e9ad58db to your computer and use it in GitHub Desktop.
var experiments = {
"YvvWWQlbSLSUqKvi6YD": [
function() {},
function() {
$("#support-nav").html("Support");
}
],
"CeK01Si7S_m_c7iYjyu9Nw": [
function() {},
function() {
$("h1").addClass("new-header-font");
}
]
};
function getExperiment() {
var acksinExp = localStorage.getItem("acksinExperiments");
// Get a new experiment
if(acksinExp == null) {
var expKeys = Object.keys(experiments);
acksinExp = expKeys[Math.floor(Math.random() * expKeys.length)];
localStorage.setItem("acksinExperiments", acksinExp);
return acksinExp;
}
// Check if experiment is still running, if it is get it.
if(acksinExp in experiments) {
return acksinExp;
}
// Remove the existing experiment and recurse so we can get the new experiment.
localStorage.removeItem("acksinExperiments");
return getExperiment();
}
$.getScript("//www.google-analytics.com/cx/api.js?experiment=" + getExperiment(), function(){
chosenVariation = cxApi.chooseVariation();
experiments[getExperiment()][chosenVariation]();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment