I have Optimizely on a page that also has a Google Form on it, and I want to track events when the form is submitted. This is roughly the code I have now:
window.optimizely = window.optimizely || [];
$('#ss-form').on('submit', function() {
window.optimizely.push(['trackEvent', 'submit']);
});
The problem is that it's severely under-reporting the number of submits that actually happen.
The only explanation I could come up with (and so did Optimizely support) is that most of the time the form is getting submitted and the next page is getting loaded before the optimizely tracking code finishes running. It has to make a request to Optimizely before the form POST request is made to Google, so its running time is probably non-negligible.
How do I ensure that the whole callback will definitely run to completion before the form is submitted?
P.S.: Optimizely support mentioned this might also have something to do with the fact that the page is hosted on one domain and submits to a different one (Google's), but I'm not sure if that has anything to do with this.