Using Optimizely with GWT
I'm testing out some experiments with a GWT application. I can set up variations in the editor but they don't show up when I preview them.
Solved! Go to Solution.
Great question. If you try running the code that is in the editor directly into the browser console while on the page, do you see the changes apply? If so, then most likely you're correct in that its a timing issue.
By default, Optimizely executes right when the page is loaded and tries to make all of the changes prior to DOM ready. While the page is loading, we make changes to elements if they exist on the page and if not, we wait until the element loads before making the change (checking every 50ms). However, once the DOM is ready, we run all of the remaining variation code regardless of whether the elements are there. Its possible that the elements you're trying to change get added after Optimizely's variation code runs so nothing actually changes.
Typically, you can solve this issue by either using manual activation (https://help.optimizely.com/hc/en-us/articles/2000
Hope this helps!
Thanks Juan. The "Here's what's happening" section on the manual activation link sounds like that's exactly what's happening with us. I was concerned about having to use the API but the required code snippet looks innocuous enough.
We need to call window.optimizely.push(["activate"]); in each page and dialog in our app where we might potentially want to run experiments in the future. So I was wondering what happens behind the scenes when you make the push call. I would assume it would at least need to go to the server to check for any running experiments and get the details of those experiments. But does it do that on every call or does it cache them so that they are available locally after the first call?
Hey Kyle -
We actually don't need to go back to the server when this call is made. The Optimizely snippet has already loaded on the first page load and within that, it knows which experiments were set to manual activation and "on" at the time. When Optimizely runs the first time on page load, it will actually skip over evaluating any manually activated experiments until the window.optimizely.push(["activate"]); call is made. When this call is made, it will tell Optimizely to evaluate these manually activated experiments based on the information already contained within the Optimizely snippet from the first page load.
FYI - On a single page load, you can call window.optimizely.push(["activate"]); as many times as you need (no additional loads of the Optimizely snippet). It will just keep re-evaluating any experiments set to manual activation and "on".