I'm tracking the Download button click on a website featuring a project of mine with this code:
function trackDownload(link) {
try {
_gaq.push(['_trackEvent', 'Downloads', 'Click', 'Setup executable']);
setTimeout('document.location = "' + link.href + '"', 100);
} catch (err) {}
return false;
}
And the button is something as:
<a href="files/setup.exe" onclick="return trackDownload(this);">Download</a>
So, when a user clicks it, an event is pushed to Analytics and then the user is redirected to the file.
This is applicable also on external link tracking, no differences.
And now my question. Can I be sure that the Analytics event is "processed" before the user is redirect? If not, that redirection cause the event to be lost? Currently events are being tracked, but I cannot be sure that all of them are.
I read I can also try something a little bit different, pushing the redirection function into Analytics queue:
_gaq.push(function() { document.location = link.href; });
But it's not clear if this works or if it's just equivalent to the previous one. In fact, here it's said that "calls to _gaq.push [...] executes commands as they are pushed".