Rich-text Reply

Ajax filter braking experiment — piggyback solution not working

famyklebust 04-24-15
Accepted Solution

Ajax filter braking experiment — piggyback solution not working

Hi everyone!

 

I've been trying to set up an experiment testing the styling of the sidebar search/product filter on our ecommerce site, but have come up against a little Ajax wall I hope someone could shine some light on.

 

The Optimizely variant code runs on page load, of course, so when a user applies a filter and the filters and results reload based on that selection, it happens using the original code instead of the variant. As our developers tend to be quite slow I'd rather not have to implement any code to the site itself, and have looked at the solutions floating around the Optiverse. 

 

I have set up my experiment with manual activation, and a piggyback experiment with the exact same URL targeting and audience and all traffic directed to one variant. In that variant I have the following code:

 

window.optimizely = window.optimizely || [];
window.optimizely.push(["activate", 2793282314]);
$(document).ajaxComplete(function() { 
 window.optimizely.push(["activate", 2793282314]); 
});

The experiment activates fine, so there's no problem with the first two lines of code, but the rest does absolutely nothing. I have tried with .ajaxComplete, .ajaxSuccess and .ajaxStop, but no go. However, if I run the snippet in the Chrome Dev Tools Console, everything works perfectly and the experiment is activated when filters are applied. I have also tried to bind the activation to the filter being clicked, but no go there either.

 

Your knowledge and skills would be greatly appreciated in solving this, great Optiverse, as I have now exhausted all ideas, fixes and knowledge resources I can think of.

 

Cheers,

Frode

td_evans 04-24-15
 

Re: Ajax filter braking experiment — piggyback solution not working

[ Edited ]

Try:

window.$(document).ajaxComplete(function() {
    window.optimizely.push(["activate", 2793282314]);
});

I don't think ajaxComplete is part of the trimmed Optimizely Jquery, so you need to reference the Jquery on your site

Thomas Evans
Technical Product Manager - Conversion @ Secret Escapes

Level 2
famyklebust 04-24-15
 

Re: Ajax filter braking experiment — piggyback solution not working

That worked like a charm. Thanks, Thomas!