Last active
December 19, 2015 20:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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