PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Onclick Event Tracking for "Submit" Without Editing Plugin Code

  1. chasef

    I've been reading up on how to add onclick event tracking to the "submit" button on gravity forms, but most of the answers require me to write the tracking code into the actual code for the plugin. I don't want to get that technical and won't it be removed every time I update Gravity Forms? So what I want to know is if there is a way to just enter the onclick event tracking code for Google Analytics in the Form Editor?

    Posted 9 years ago on Sunday May 27, 2012 | Permalink
  2. David Peralty

    Have a look at the following:

    Posted 9 years ago on Tuesday May 29, 2012 | Permalink
  3. unodewaal

    We have a similar requirement, but one that the functions.php solution does not cater for.
    We have created multiple forms, and continue to create and archive forms on a continual basis (we use it for quick competition entry mechanisms and other on-the-fly usage).
    Our requirement is to have tracking on each form and not just a single one - the solution above only allows you to track conversions for a single form, and if you want to track other forms you'd need to change the form ID's.
    A simple solution for me would be to add tracking to the submit button that is something like this:
    _gaq.push(['_trackEvent', 'Forms', 'Submission', '<form name variable']);

    This then gets added to EVERY single submit button on every single form. The variable would allow you to track the different forms.

    I would imagine that a simple checkbox in the admin panel that says "track submissions" would let you pick if you want to track submissions on that form or not.

    Easier speculated than done, but this would be a fantastic feature or add-on.

    Posted 9 years ago on Sunday August 19, 2012 | Permalink
  4. If you eliminate line #6 in the pastie, the tracking code will be added to all forms. Would that work for you?

    Posted 9 years ago on Sunday August 19, 2012 | Permalink
  5. unodewaal

    I think it would - which variable/function would I use to echo out the form title? Assuming it would replace the 'GA Testing Form FINAL' in the ga.push below (line 10 in the paste)?

    _gaq.push(['_trackEvent', 'Forms', 'Submission', 'GA Testing Form FINAL']);

    Posted 9 years ago on Sunday August 19, 2012 | Permalink
  6. Here is the documentation for the form object:

    You can use:

    <?php echo $form["title"]; ?>

    To get the form title.

    Line 10 in the paste would look like this then:

    _gaq.push(['_trackEvent', 'Forms', 'Submission', '<?php echo $form["title"]; ?>']);

    I didn't try that to be sure the quotes are correct, but that is basically how you would do it.

    Posted 9 years ago on Sunday August 19, 2012 | Permalink
  7. unodewaal

    Thanks a lot - I've managed to paste it in and it looks like this now:
    I had some syntax errors initially, but it seems to be working OK now. I haven't been able to test it fully with Analytics (Will try debugging just now), but will have a look tomorrow. The demo form I have is up here:

    Thanks for your help!

    Posted 9 years ago on Sunday August 19, 2012 | Permalink
  8. That looks correct to me. Let us know here how that is working after a couple days. I submitted a test.

    You have an issue with the main form and sidebar newsletter form conflicting with the tabindex. Tabbing off the first name field I ended up in the sidebar, then tabbing again I was at the last name field. If this issue is present on your other forms (not just the test form) you can change the tabindex for the sidebar form (it's a setting when add the form widget to your sidebar) - click the "advanced options" and you will see the setting there. Screenshot:

    Just set the sidebar to some high number that is greater than the number of elements in your main form. I used 50 here. It could be 4 for this particular page, or you could make it 955. The index for the "enter email" field in the sidebar form would 955, and the "confirm email" would be 956.

    There are other ways to do it (when you embed the form in the page, or via functions.php) but the widget setting is probably easiest.

    Posted 9 years ago on Sunday August 19, 2012 | Permalink
  9. unodewaal

    Hi Chris - just to say that the solution worked perfectly. Everything seems to be running like a charm. I've setup goals in Analytics with the various form names I required so these should be pulling through from now on.
    I've updated the tabbing on the sidebar form as well - I didn't realize there was an error there.

    Thanks for your help!

    Posted 9 years ago on Wednesday August 22, 2012 | Permalink
  10. You're welcome. Thanks for updating this topic.

    Posted 9 years ago on Wednesday August 22, 2012 | Permalink

This topic has been resolved and has been closed to new replies.