Rich-text Reply

Preview working but live experiment does not

gaurav_saraf 06-23-14
Accepted Solution

Preview working but live experiment does not



I'm currently performing A/B testing on a dynamically loaded web-page. I rearranged a couple of elements on the web-page, and am able to preview the variation correctly. However, then I start the experiement, users are still able to see only the original page. The variation is not loading. I do have js files in my code which are responsible for the positioning of the elements on the web-page. Clearly, there's a conflict between my js files and jQuery used by Optimizely to arrange the same elements. But I believe Optimizely already takes care of this by using noConflict(). Is there anything I can do to get my users to see the variation? Any help will be appreciated.



AdamA 06-23-14

Re: Preview working but live experiment does not

Hi Gaurav, if your elements are being controlled via JavaScript after pageload, what may be happening is that your page first loads Optimizely, which checks for the elements, but the elements aren't available until DOM ready, so Optimizely doesn't detect the elements and can't change them.

If this is the case, then you should find the selector for the element you want to test, and add the following code into the <Edit Code> box in Optimizely:

window.myInterval = setInterval(function() {
if ($("#selector").length > 0) {
}, 50);

Just change #selector to the selector of the element you want to edit, then replace $("#selector").dosomething(); with the variation code that you were already using to change the element in Optimizely.

Essentially, what this code does is:
(1) Checks for the presence of your element on the site
(2) If it finds it, then executes the changes
(3) Checks again every 50 milliseconds if it's not found

Please let me know if that works for you, Gaurav! And for other readers out there, if you're having a similar problem where elements load dynamically and won't appear in your variation, you can use this same code.

Re: Preview working but live experiment does not

Thanks Adam! It worked alright. My biggest concern was how Optimizely takes care of handling changes to elements which are getting changed in some JS code. Now it all makes sense.


Thanks again for your help.