Rich-text Reply

Infinite Scroll Reload JS

belsmore 07-02-14
Accepted Solution

Infinite Scroll Reload JS

I am currently working on the Optimizely A/B Headline Test Plugin for Wordpress and the site i'm working on is testing every headline on the site. The problem I'm running into is that the their is infinite scroll on many areas of the site and when the new post elements are added to the DOM the JS is not firing and switching the titles for those posts because the JS is run on page load. My question is, is there a way to reload the JS for all experiments in a project with one call? I was going to loop through all the expirements in the project and then pull the expirement JS for each and use it that way but that is going to be about 20 api calls every time the infinite scroll posts are loaded. Any guidance is much appreciated.

Level 2

JonN 07-02-14
 

Re: Infinite Scroll Reload JS

I don't think we have anyway to reload the JS for all experiments in one call, but you can definitely avoid making API calls. You can get the list of all active experiments on a page using our Javascript API right in the client, see http://developers.optimizely.com/javascript/#experiments-23.

Another way of getting the list of all the experiments is doing a single API call for all the experiments in a project: http://developers.optimizely.com/rest/#list-experiments-in-project-16
Optimizely
Amanda 07-02-14
 

Re: Infinite Scroll Reload JS

Hey @belsmore ,

 

You are right - the snippet executes on intial page load. So, if content is added after the page has already loaded, the snippet does not re-run by default. 

 

Are you familiar with Optimizely's manual activation setting? This allows you to force the experiment to run when you want it to. When you call "activate", the given experiment is run if the visitor meets the experiment's targeting conditions. You have the option to activate all manual experiments on the page, or just one specific experiment. 

 

You can find details on it in our Knowledge Base article here.  Please let me know if either this or @JonN 's suggestion will do the trick for you. If not, I'm happy to dig into this deeper.

Optimizely
belsmore 07-07-14
 

Re: Infinite Scroll Reload JS

Thanks for the responses @Amanda and @JonN !

 

I ended up using the manual activation with the JavaScript API and everything is working as it needs to. 

Level 2