I am building an A/B test plugin for WordPress to be used on some landing pages.
A landing page allows the admin to create any number on A/B test variations.
On the landing page edit screen there will be some meta fields used to store what will trigger a conversion
on an A/B test variation.
One of the options will be something like:
A button or link on the page that has a CSS Class name ____ OR CSS ID ____ is clicked on.
Where the name of the CSS class or ID is saved to the landing page meta field.
On the frontend of the site in the page template. I then want to inject some JavaScript with a click event on the provided class or ID which will then fire of an AJAX post which creates a conversion record on this A/B test variation of the landing page.
So my question is in my JavaScript click event which will fire the AJAX post. After that happens, I want to continue on with the action the link or button with that ID or class was supposed to do.
So I would think there would need to also be some sort of delay to make sure my AJAX post has time to post and then continue loading the page/link or whatever the action is.
How can I delay and continue with the button clicks I am attaching click events to?
$("#id_from_meta_field").on("click", function(e){
// Prevent the button or link from triggering a form submission or loading a URL link so that the AJAX below can run
e.preventDefault();
$.ajax({
url: '/create_conversion_record_on_this_ab_test_variation',
success: function(date) {
// continue on loading button action or link URL
}
});
});