I am considering attaching onclick events to internal links on my site to do some Google Analytics event tracking. But I am concerned about performance. My understanding is that the workflow will change:
I am concerned about the delay introduced by steps 2 and 3. So the questions are:
Event tracking works by making an image request from the Google servers. A problem is that following a link to a new URL stops any pending/in-progress requests.If the browser is opening a link to a new URL in the same window before the tracking request has been made, you can loose analytics data.
So step 3 isn't a wait, but a delay that has to be added in to allow the tracking image request to complete (or at least start). 100-150 milliseconds is long enough for the request, but short enough not to be noticed by users.
I use some variation of the following event tracking code (jQuery code):
$('.someClassForTracking').click(function(e){
_gaq.push(['_trackEvent', category, action, ...]);
if (this.target != '_blank') {
e.preventDefault();
var url = this.href;
setTimeout(function(){location.href = url}, 150);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With