Rich-text Reply

Optimizely's editor and _optimizely_evaluate=force

wbk 10-19-14

Optimizely's editor and _optimizely_evaluate=force

Disclaimer:  I'm extremely fresh to Optimizely's product.

I'm trying to split test differences between a two-page and three-page signup process on our site.  All of the "pages" are in a single-page angular.js app.

In order to get this to work, I created a "Giant Single Page Form" experiment and variation, with the intention of implementing the variation itself outside of optimizely's editor.

 

The variation's code performs:

 

/*_optimizely_evaluate=force*/
window.splitTests = !!window.splitTests ? window.splitTests : {};
window.splitTests.homeTemplateUrl = 'modules/core/views/full-signup.client.view.html';
window.splitTests.afterValidate = 'choose-your-path';
window.splitTests.signupStepTwoName = 'Verify Email';
/*_optimizely_evaluate=safe*/

 

My application logic handles this just fine, as long as the application's "bootstrap" function is called at some point after optimizely's variation code.

Optimizely's editor allows the page to execute javascript before activating a variation, as best I can tell. Optimizely's "preview" mode seems to have similar behavior.

 

My first thought is that I should defer bootstrapping the application when it's loaded in Optimizely's editor or preview mode, but I have no idea how to accomplish it.  Is there a value I can watch?  Is there an event I could hook?  How do I know if I'm being loaded inside of Optimizely's editor?

 

As a second thought, Is there any way for my application to say, "Wow, some experiment just activated.  I'll double-check what I'm presenting."?

wbk
Level 1

Brett 10-21-14
 

Re: Optimizely's editor and _optimizely_evaluate=force

Here is how Optimizely's default behavior works:

As soon as Optimizely loads on the page it will evaluate for experiments and attempt to run any javascript/jQuery in the variation code. If the the line of code in the variation code is javascript Optimizely will wait till DOM ready- which is why you've added /*_optimizely_evaluate=force*/ /*_optimizely_evaluate=safe*/ around your code so it will execute before DOM ready.

Optimizely's Preview works a bit differently and actually defers to run variation code so it is not a true one to one method for previewing. Which is why you're seeing issues when you do the preview. An alternative to preview would be to use the optimizely_x parameter. The basic query parmaeter format is optimizely_x<EXPERIMENTID>=<VARIATIONID>
Check out this Optimizely KB article to see exactly how that parameter works: https://help.optimizely.com/hc/en-us/articles/200107480#force

Optimizely's variation code will only run once and we don't have a callback function to know when the variation code has ran/finished. What I might recommend is either use manual activation API call so you can tell Optimizely exactly when you want it to trigger. You could also scope a function to the window level in the variation code. Then use function as your call back to know when the variation code has completed. But Optimizely doesn't have anything like that build in.

Hope that helps!

Thanks!
Brett
Optimizely