Dear all,
I have a site that displays a set of rotating banners on the home page which are internally linked to other pages within the same site. I would like to track how many times each banner was clicked. So far, my solution is to use Event Tracking but my problem is with the redirects. Once the banner is clicked, I fire off the trackEvent, but I haven’t figured out how to “wait” until the tracking of the event is complete before issuing the redirect.
$("img.banner").click(function() {
var id = $(this).attr('data-banner-id');
_paq.push(['trackEvent', 'Banner', 'Click', id]);
// there's a race condition between the tracking of the event
// and the browser executing the following redirect
var url = $(this).attr("data-url");
window.location.href = url;
});
It appears there is a race condition between trackEvent and the redirect. I also tried ‘pushing’ a function into _paq but the results are the same. I simply cannot figure out a way to synchronously track the event, and then issue the redirect.
Am I missing something? Perhaps I am approaching the problem wrong?
Any help is greatly appreciated!
–mgb