javascript - How to reliably send tracking event on link click? -
i have tracking event (in form of http call tracking server) fires on clicking of link, fired onclick event.
however, appears often, event not registered tracking server because browser cuts off (long-running) event call when loads new page.
i'm reluctant wait reply before forwarding user new page, in case reply delayed , user has wait.
is there way ensure event call completes , forward user on immediately?
maybe preventdefault
helps you. don't share code, it's because explain way:
$('a.link').on('click', function(e) { e.preventdefault(); var trackinglink = $(this).attr('href'); // ajax stuff $.ajax().success(function() { window.location.href = trackinglink; }); });
with preventdefault()
avoid links load page, make ajax requests , if it's successful redirects page of link
Comments
Post a Comment