Skip to content

Instantly share code, notes, and snippets.

@Pephers
Last active December 15, 2015 19:18
Show Gist options
  • Save Pephers/5309886 to your computer and use it in GitHub Desktop.
Save Pephers/5309886 to your computer and use it in GitHub Desktop.
<script>
(function() {
var forms = document.forms;
function gaTrackPageview(number) {
_gaq.push(['_trackPageview', document.location.pathname + '-form-' + number]);
}
for (var i = 0; i < forms.length; i++) {
if (forms[i].attachEvent) {
forms[i].attachEvent('onsubmit', function () {
gaTrackPageview(i + 1);
});
}
else {
forms[i].addEventListener('submit', function () {
gaTrackPageview(i + 1);
}, false);
}
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment