Skip to content

Instantly share code, notes, and snippets.

@domsammut
Last active December 19, 2015 20:59
Show Gist options
  • Save domsammut/6017152 to your computer and use it in GitHub Desktop.
Save domsammut/6017152 to your computer and use it in GitHub Desktop.
A solution for when hitCallback functions do not receive a response using Google Analytics (analytics.js) http://dsam.co/WQJUtY
var url = "http://dsam.co/WQJUtY";
/*
* Simply checks that the loaded property exists
* and that it has a value of true.
*/
if (ga.hasOwnProperty('loaded') && ga.loaded === true) {
//Success, ga is loaded
ga('send', 'event', {
'eventCategory' : 'Outbound',
'eventAction' : 'Link',
'eventLabel' : url,
'eventValue' : '1',
'hitCallback' : function () {
document.location = url;
}
});
} else {
//Not loaded, continue without tracking the data
document.location = url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment