I have a button on a page (id = "searchButton"), that, when clicked submits a form (post). Before the post occurs, I want to log some information to Google Analytics. So I have the following JS code to do this:
$(document).ready(function () {
// Log some information to GA
$('#searchButton').click(function (e) {
LogSearch();
LogDestinations();
LogTourTypes();
LogIndependent();
});
});
I'm wondering if I'm doing this correctly? Specifically, I'm curious whether the actual post is occurring before all four function calls are made. Or will all four function calls complete before the form actually posts, consistently, across all browsers? I want the form to post, but I also want these four JS functions to execute first.
In case it helps, I'm calling Google Analytics using their standard method of sending events:
ga('send', 'event', "Accommodation Search", "Accommodation Search Counter", "", 0);
And the HTML where the button is defined:
<div class="col-xs-12">
<input type="submit" value="Search" class="btn btn-primary" id="searchButton" />
</div>