Created
November 14, 2014 14:30
-
-
Save simondahla/9f4c3981db53841c56cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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