From the Google documentation for universal analytics (new version, as most other answers to this question). Now you can easily specify a callback.
var trackOutboundLink = function(url) { ga('send', 'event', 'outbound', 'click', url, {'hitCallback': function () { document.location = url; } }); }
For clarity, I would recommend using this syntax, which allows you to specify which properties you are sending, and itβs easier to add more:
ga('send', 'event', { 'eventCategory': 'Homepage', 'eventAction': 'Video Play', 'eventLabel': label, 'eventValue': null, 'hitCallback': function() { // redirect here }, 'transport': 'beacon', 'nonInteraction': (interactive || true ? 0 : 1) });
[Here is a complete list of parameters for all possible ga calls.]
In addition, I added the transport parameter to the beacon value (actually not needed, because it is automatically set if necessary):
Specifies the transport mechanism with which hits will be sent. The options are: beacon, xxr, or image. By default, analytics.js will try to figure out the best method based on the size of the hits and the browser. If you specify "beacon" and the user browser does not support the navigator.sendBeacon method, it will drop to 'image' or 'xhr' depending on the size of the strokes.
Therefore, when using navigator.beacon navigation does not interrupt tracking. Unfortunately, Microsoft beacon support does not exist , so you have to put the redirect in a callback.