Rich-text Reply

Using Optimizely to test various setTimeout

fusion 02-10-15

Using Optimizely to test various setTimeout



We would like to setup an experiment about popup but we would like to have different timers. For example, we would want to experiment with 5s, 10s and 15s. Is there anyway to achieve this in Optimizely?


   // Do something
}, 5000 );

 if I could make 5000 a varialbe that I could experiement. That'd be great. 

Level 1

greg 02-10-15

Re: Using Optimizely to test various setTimeout

[ Edited ]

You can set the variable in the variation code (in editor, click <edit code>), but you have to force Optimizely to evaluate it before loading the DOM. Try this:


/* _optimizely_evaluate=force */
window.popupTimeDelay = 5000;
/* _optimizely_evaluate=safe */


More info on this here:

Level 2

Re: Using Optimizely to test various setTimeout

You could write your methods to build the popup in your experiment JavaScript, attach this to the window, and then run a setTimeout with different times for each piece of variation JavaScript. 


For example, here's a screenshot of custom code I wrote to build a popup (most code removed from this snippet for spacing/clarity):


In that example, the variable NEWSLETTER_MODAL is set to an anonymous, self-invoking function that returns a popup object with methods. This then gets attached to the global window object such that it can be called from the variation JavaScript.


Then, each variation runs this popup at different times. For example, variation #2 runs it after 30 seconds:


There are many other ways to approach this... this is just one possible solution. 

-- Sean
UI Developer @ Blue Acorn

optimizely developer certification