We have a WordPress installation and we’re trying to track in Google analytics whenever a form field is clicked in Gravity Forms.
To do this we’ve got to push Analytics variables whenever the field is focussed. Here is the code we are using:-
<script type="text/javascript">
jQuery('#input_1_3').focus(function() {
_gaq.push(['_trackEvent', 'Form Tracking', 'Sidebar Quick Contact Form: Homepage', 'Name']);
});
jQuery('#input_1_4').focus(function() {
_gaq.push(['_trackEvent', 'Form Tracking', 'Sidebar Quick Contact Form: Homepage', 'Company Name']);
});
jQuery('#input_1_5').focus(function() {
_gaq.push(['_trackEvent', 'Form Tracking', 'Sidebar Quick Contact Form: Homepage', 'Email']);
});
jQuery('#input_1_11').focus(function() {
_gaq.push(['_trackEvent', 'Form Tracking', 'Sidebar Quick Contact Form: Homepage', 'Telephone']);
});
jQuery('#input_1_6').focus(function() {
_gaq.push(['_trackEvent', 'Form Tracking', 'Sidebar Quick Contact Form: Homepage', 'Questions/Comments']);
});
The input ID’s match up fine with the relevant ID’s on elements in the form, but it isn’t resulting in tracking in Analytics. There doesn’t appear to be any conflict with jQuery in WordPress, and no errors are resulting in Firebug.
Do you have any ideas as to why nothing is tracking?
First you can check if this events really fired:
If they not, use
on()
method to bind focus event: