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 Google Event Tracking

  1. Hello,
    I've checked a number of the other forum topics on this but haven't been able to find an answer for my question. I'm trying to add onclick event tracking for Google analytics and when I edited the function.php of my site it threw a parse syntax error.
    Because my theme includes a specific html header/footer area, that is where the Google Analytics code lives, so I tried adding the event tracking code to the same area. That simply tracked everyone who saw the button, rather than just those who actually clicked the button.
    I've spent a number of hours trying to figure out how to add this code to the button on a Gravity form, is there something I'm missing? Where can I edit the code related to the submit button? The form I'm referring to lives in the footer of every page: http://www.conroymediagroup.com/.
    Thanks,
    Cate

    Posted 11 years ago on Wednesday April 3, 2013 | Permalink
  2. If you have a parse syntax error, you pasted the code in a bad place, or the code was invalid. Can you show us the code you were trying to paste, or post your complete functions.php and (separately) the code you want to add to pastebin.com or pastie.org? We can help you with the placement so you can try that solution.

    Posted 11 years ago on Monday April 8, 2013 | Permalink
  3. You bet, so here is the functions.php: http://pastebin.com/geF7putG
    and here is the code I was trying to add: http://pastebin.com/8ULkEpjL

    Keep in mind this is a child theme but the parent theme's php should not be edited.
    I also tried the onclick event tracking code in the footer, where my GA code lives. But that simply tracked everyone who viewed, rather than clicked.

    Posted 11 years ago on Thursday April 11, 2013 | Permalink
  4. amadex
    Member

    Did anybody found a solution for google analytics tracking with ajax forms?!... I don't understand why it works when pasting the script _gaq code in the confirmation message (ajax) but not injecting the same script trough gform_after_submission action!...

    Posted 11 years ago on Tuesday April 23, 2013 | Permalink
  5. I have to admit I'm pretty frustrated with this - I've seen multiple topics dedicate to this issue and the support always seems to involve editing the functions.php or other code-level work which isn't a reasonable thing to expect of your customers.
    Will Gravity Forms be adding this functionality to a release any time soon? Because right now this issue and the lack of support is making me question whether purchasing this was a good idea.

    Posted 11 years ago on Wednesday April 24, 2013 | Permalink
  6. amadex
    Member

    This Google Analytics tracking issue is something that I also agree should be an integrated functionality and not something that we should try to make work for ourselves... This is basic...

    The methods are also archaic. Pasting the tracking code in the confirmation message is something that shouldn't happen, because it makes code maintenance a nightmare.

    I could never make it work through functions.php also (ajax confirmation message), neither with gform_after_submission nor gform_confirmation...

    Posted 11 years ago on Wednesday April 24, 2013 | Permalink
  7. I wasn't able to inject my on click even in the submit button, but I was able to get my script to work in the confirmation message. Using this tracking method has helped me track when the form has been successfully submitted instead of just tracking the submit button clicks which track all clicks (even if the user made errors on the form and the form was not successfully submitted.

    <script>_gaq.push(['_trackEvent', 'Forms', 'Submit', 'NameOfForm']);</script>

    Sometimes the confirmation message removed my script tags, but checking the Disable auto-formatting option fixed that issue. I hope this helps.

    Posted 11 years ago on Tuesday May 7, 2013 | Permalink
  8. I am using the same approach as caconroy1 I am adding the following code to the function.php file.

    add_action("gform_after_submission", "gf_ga_tracking", 10, 2);
    function gf_ga_tracking($entry, $form) {
        ?>
        <script type="text/javascript">
    	jQuery(document).ready(function($) {
                _gaq.push(['_trackEvent', 'Forms', 'Submission', '<?php echo $form["title"]; ?>']);
    	});
        </script>
    
    <?php }

    but I am receiving a ReferenceError: jQuery is not defined @ http://domain.com/request-service/#gf_5:3

    I know I have to have jQuery added to the page. But I figured it was taken care of by another plugin. from this code on my page:

    <script type='text/javascript' src='http://culliganwaterdeals.com/wp-content/plugins/wp-lightbox/js/jquery.min.js?ver=1.7.1'></script>

    If now what is the best way to add jquery to my site?

    Thanks
    Greg

    Posted 11 years ago on Tuesday June 4, 2013 | Permalink
  9. @askena - thanks for the tip on disabling the auto format. I am going to give that a try.

    Posted 11 years ago on Wednesday June 5, 2013 | Permalink