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 tracking

  1. brianc
    Member

    I simply want to add an onclick event to the submit button for google analytics tracking. that way I can see if people submit forms when i have the ajax functionality on (which keeps the user on the page)

    whats the best way to do this?

    Do I have to modfy core code? If I do what line of the file mods that.

    Thanks!

    Posted 14 years ago on Wednesday February 17, 2010 | Permalink
  2. You should be able to add on onclick event to the button with some simple jQuery.. something similar to this.

    <script type="text/javascript">
      $(document).ready(function() {
    
        $('#gform_1 input[type=submit]').click(function () {
          // do something here
        });
    
      });
     </script>

    where the "gform_1" above is your form ID.

    http://api.jquery.com/click/

    Posted 14 years ago on Wednesday February 17, 2010 | Permalink
  3. brianc
    Member

    This is the code I am trying.

    <script type="text/javascript">
      $(document).ready(function() {
    
        $('#gform_1 input[type=submit]').click(function () {
          pageTracker._trackPageview('/submit/')
        });
    
      });
     </script>

    I will let you know if it works. Thanks.

    Posted 14 years ago on Thursday February 18, 2010 | Permalink
  4. brianc
    Member

    Just an update here. The solution I used above does not appear to be working.

    Posted 14 years ago on Friday February 26, 2010 | Permalink
  5. I'm in the same boat. I tried a slightly different approach though. In the confirmation message area. I added:

    <script type="text/javascript">pageTracker._trackPageview('/contact/contact-form.html');</script>

    I then set up a two step Google Analytics goal that started at the contact forms address of "/contact/" and ends at the fake success page of "/contact/contact-form-success/"

    This doesn't log in Analytics as a goal.

    I then tried the other two options on the confirmation tab (page and redirect) and inserted the above javascript on those pages. Neither of those options logged the Analytics goal either.

    My Google Analtyics javascript include is in the header section of my website so I know that isn't the case.

    I absolutely love Gravity forms and native support for Google Analtyics goal tracking would be icing on the cake.

    Posted 14 years ago on Friday February 26, 2010 | Permalink
  6. orone
    Member

    Where do you apply Kevin's onclick event? Is it the notification.php? If it is in there notification.php how do you differentiate between forms? Maybe I am over analyzing this and its right in front of my eyes.

    Can I add the tracking into the text box for confirmation?

    help please.

    Posted 14 years ago on Wednesday April 21, 2010 | Permalink
  7. My suggestion was some jQuery that you put in the page template the form uses. You wouldn't need to edit any of the core plugin files.

    Posted 14 years ago on Wednesday April 21, 2010 | Permalink
  8. Yeah - a simple way of tracking successful form submissions would be great. Whithout having to redirect to a new page that is. But I've no idea how to get that to work onClick won't do it accurately - as it may get caught up in multiple validation "loops".

    Does anyone clever out there know how to trick GA into this when the form generates a text confirmation message in the page?

    Posted 14 years ago on Friday May 14, 2010 | Permalink
  9. I'd love to have this post revisited. Is anyone using goal tracking with Google Analytics + Gravity? Care to share how you have it set up?

    Posted 14 years ago on Wednesday July 14, 2010 | Permalink
  10. Me too, Kinda looks like it's not possible for mere mortals!

    Posted 14 years ago on Wednesday July 21, 2010 | Permalink
  11. Here's an easy way to set up Google Analytics event tracking for a successful Gravity Forms form submission: http://pastie.org/1057774

    General Usage:

    Paste this code into your theme's function file. This code assumes that you have already included jQuery and the Google Analytics embed code for your site.

    Quick break down:

    edited December 19, 2013 to change from gform_post_submission to gform_after_submission.

    add_action("gform_after_submission", "gf_ga_tracking", 10, 2);

    We make use of the gform_after_submission action to trigger a function after the form has been submitted. The entry is validated before this action is called, so we know that the form has been submitted successfully.

    if($form['id'] != 4) return;

    We check to make sure that we only continue processing this function if we are on the correct form. Replace '4' with your form id.

    <script type="text/javascript">
            jQuery(document).ready(function($) {
                _gaq.push(['_trackEvent', 'Forms', 'Submission', 'GA Testing Form FINAL']);
            });
        </script>

    This next bit assumes that you already have the Google Analytics embed code on your site and jQuery included. All we're doing is "pushing" an event to GA. For more information on this line, check out the GA documentation.

    And that, my friends... is all there is to it. I'll do a more thorough write up as time allows. Hope this helps! :)

    Posted 14 years ago on Friday July 23, 2010 | Permalink
  12. Just getting back to this. David, thanks for your help here - I'll try out your suggestions tonight!

    Cheers.

    Posted 14 years ago on Wednesday September 8, 2010 | Permalink
  13. Just a quick update to this... it worked like a charm.

    Posted 14 years ago on Wednesday September 15, 2010 | Permalink
  14. MellyVille
    Member

    Wow, this does seem like a nice contrib.

    But i can't get it to work!

    I've pasted the code in my functions.php file and then ran form id 9 (so i changed the 4 to 9). Didn't get any errors, but also, the day after doesn't show an event in my google analytics.

    Would you care to look a bit closer with me, David Smith?

    Posted 14 years ago on Tuesday November 16, 2010 | Permalink
  15. MellyVille
    Member

    David?

    Posted 14 years ago on Wednesday November 17, 2010 | Permalink
  16. Sure Melly. :)

    Send me an email with your FTP and WP login credentials to david@rocketgenius.com.

    Posted 14 years ago on Wednesday November 17, 2010 | Permalink
  17. MellyVille
    Member

    Thanks David,

    I've sent you an email...

    Posted 14 years ago on Friday November 19, 2010 | Permalink
  18. fhdigital
    Member

    Can you provide guidance on how one might implement a similar tracking code with AJAX enabled?

    Posted 14 years ago on Wednesday November 24, 2010 | Permalink
  19. This should really be in the core. Seems like a much required feature!

    Posted 13 years ago on Thursday March 10, 2011 | Permalink
  20. I completely agree with @clickrmedia.
    It's not a best practice to be making more than the necessary changes to a functions.php file, especially for people who are not developers.
    Contact Form 7, for instance, has an additional settings area where this code can easily be added.
    Can Gravity Forms do this as well?

    Posted 13 years ago on Friday April 15, 2011 | Permalink
  21. Has this been improved any? I need to track submissions with 3 different scripts: One with the Google analytics' _trackPageview function, the second with the Google AdWords conversion script, and the third with the Microsoft AdCenter conversion script. I do NOT want to forward to a different page for this.

    Posted 13 years ago on Thursday May 19, 2011 | Permalink
  22. Bump, I am trying to do this as well, and have not found any real answers in the forums. Is it updated and I am missing a setting?

    Posted 12 years ago on Saturday December 17, 2011 | Permalink
  23. @tasty, please start a new topic and ask your question specifically. Please include a link to your site so we can give you personalized support. Thank you.

    Posted 12 years ago on Tuesday December 20, 2011 | Permalink

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