Rich-text Reply

Tips on how to force yourself into a variation of an experiment

JDahlinANF 12-02-14

Tips on how to force yourself into a variation of an experiment

[ Edited ]

Tired of clearing cookies and hoping you get into a specific version of an experiment?

Stop clearing your cookies and start setting them!

The code below is set up to control which variation of community.optimizely.com's "[Community] New Here (All traffic to Variation)" experiment.  In the B group, you will see a "NEW HERE?" widget next to "Hello, <username>" in the gray bar near the top of the page.

 

I've color-coded the text that you will need to change to make this work for you.

You do not need to update the names of the experiment and variations, but I find it helpful to do this since I save a copy of this script as part of our experiment setup (for ease of distributing this to our UAT team).

 

 

/**********  INSTRUCTIONS **********
0- update the idExperiment, idA and idB values so that they are for the experiment you want to get into
1- visit the site / page where you want to see the test
2- run the code below in your browser's console.

 **********  CONFIGURATION **********/
var variation = 'B'			//which variation do you want to be in
var idExperiment = '1592330777';	//[Community] New Here (All traffic to Variation)
var idA = '1591410738';		//Original
var idB = '1587970770';		//Variation #1

/**********  THE CODE **********/
var now = new Date(); 
var keepUntil = new Date(); 
keepUntil.setDate(now.getDate() + 3650);
var thisDomain = (function(){
	var arrHost = window.location.host.split('.');
	for (x=0;x<arrHost.length;x++){
		//e.g., if your site is www.yourDomainHere.com, use "yourDomainHere"
		if (arrHost[x] == 'optimizely') {
			var xPos = x;
		}
	}
	return '.' + arrHost.slice(parseFloat(xPos-arrHost.length)).join('.');
})();

if (variation == 'A'){
	document.cookie = 'optimizelyBuckets=' + encodeURIComponent('{'+idExperiment+':'+idA+'}')+ '; domain='+thisDomain+'; expires=' + keepUntil.toUTCString()+ '; path=/'; 

}
if (variation == 'B'){
	document.cookie = 'optimizelyBuckets=' + encodeURIComponent('{'+idExperiment+':'+idB+'}')+ '; domain='+thisDomain+'; expires=' + keepUntil.toUTCString()+ '; path=/'; 
}

 

Aisha 12-02-14
 

Re: How to force yourself into a variation of an experiment

Hi nap0leon,

Thanks for this awesome write-up. I wanted to add that if users are looking to view a specific variation for testing purposes, they could also use force parameters, which are outlined here: https://help.optimizely.com/hc/en-us/articles/200107480-Force-a-specific-variation-to-run-and-other-... These allow you to use URLs based on a test's experiment/targeted URL(s) to view a variation as a visitor would see it.

Thanks again for the suggestion!

Cheers,

Aisha
Customer Success and Technical Support @ Optimizely!
Optimizely
JDahlinANF 12-03-14
 

Re: How to force yourself into a variation of an experiment

@Aisha- Absolutely! 

This is more for when users want to see what an experiment looks like across a variety of pages and not have to alter their URL every time they reach a specific page.

 

For single-page type tests, the force parameters (which we have not disabled) is still our preferred method.