I wish to use event tracking to record clicks on a specific type of link to another website. I am using jQuery, and the code I currently have is:
$('a.website').click(function(event) {
var href = $(this).attr('href');
try {
_gaq.push(['_trackEvent', 'website', 'click', href]);
} catch(err) {}
});
However, after seeing referrer information from the other site, I don't belive this is accurately tracking the clicks, probably because _gaq.push
is asynchronous, and the request has not been received before the browser navigates to the url, and terminates any javascript running on the current page.
Is there any way to detect that the _gaq.push
function has completed successfully, so I can use event.preventDefault()
and document.location
to navigate to the link after the event has been recorded?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…