Last active
October 18, 2018 05:19
-
-
Save ortense/3fd99640b1ac918e75f1 to your computer and use it in GitHub Desktop.
Google Analytics Track Form Interactions
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
(function($){ | |
var forms = $("form"); | |
forms.on("submit", function(){ | |
var form = $(this); | |
ga("send", "event", "forms", | |
form.attr("name") || form.attr("id"), | |
"submit"; | |
); | |
}); | |
forms.find(":input").on("change", function(){ | |
var form = $(this).closest("form"); | |
ga("send", "event", "forms", | |
form.attr("name") || form.attr("id"), | |
(this.name || this.id) + "(change)"; | |
); | |
}); | |
forms.find(":button").on("mousedown", function(){ | |
var form = $(this).closest("form"); | |
ga("send", "event", "forms", | |
form.attr("name") || form.attr("id"), | |
(this.name || this.id) + "(click)"; | |
); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment