Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simondahla/9f4c3981db53841c56cf to your computer and use it in GitHub Desktop.
Save simondahla/9f4c3981db53841c56cf to your computer and use it in GitHub Desktop.
(function() {
var url = window.location.host;
if(window.location.pathname === ""){
url = window.location.host + "/" + window.location.pathname;
}
function trackField(){
$( "input" ).each(function() {
var name = $(this).attr( "name" )
$( this ).blur(function() {
ga('send', 'event', 'formFieldAnalytics', name, url);
});
});
}
var counter = 1;
function checkIfAnalyticsLoaded() {
if (window.ga) {
//LOADED!
trackField();
} else {
counter = counter + 1;
if (counter < 6){
setTimeout('checkIfAnalyticsLoaded()', 200);
} else {
//LOADED!
trackField();
}
}
}
window.onload = checkIfAnalyticsLoaded();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment