Skip to content

Instantly share code, notes, and snippets.

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

  • Save seekshreyas/fb3aa18bad7a97ed5069 to your computer and use it in GitHub Desktop.

Select an option

Save seekshreyas/fb3aa18bad7a97ed5069 to your computer and use it in GitHub Desktop.
JS-variation.js template for A/B tests
// Experiment Jira Id: WAT-195
// Optimizely Experiment Id: 2767601388
// Experiment Name: "(WAT-195) Bitbucket: homepage messaging + small signupform";
// Experiment URL: https://bitbucket.org
// ------------
// VARIATION:: HEADER 1
// ------------
// Author: Shreyas
// Email: [email protected]
;
var EXP = EXP || {}; //wac experiment namespace.
EXP.wtf12918 = (function() {
var init = function() {
console.log("Initiating Experiment: WTF-12918");
console.log("DEV LOG::building the experiment"); // to keep track of OPTIMIZELY's deployment
variationScript();
evtHandler(); //bind events
};
var variationScript = function() {
console.log("exp variation starts");
};
var evtHandler = function() {
console.log("events bound");
};
// ----------------
// helper methods
// ----------------
var getCookie = function(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
};
var setCookie = function(name, val) {
//reference: http://stackoverflow.com/a/8733385/1887264
var expiration_date = new Date();
var cookie_string = '';
expiration_date.setFullYear(expiration_date.getFullYear() + 1);
// Build the set-cookie string:
cookie_string = name + '=' + val + '; path=/; expires=' + expiration_date.toGMTString();
// Create/update the cookie:
document.cookie = cookie_string;
};
// ----------------
// exposed methods
// ----------------
return {
'init': init,
'getCookie': getCookie,
'setCookie': setCookie
};
})();
jQuery(document).ready(function() {
var resetStyle = (function() {
console.log("reset style");
jQuery('body').addClass('wtf12918');
})();
EXP.wtf12918.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment