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.

GA Event Tracking

  1. I saw the pastie that had this

    <?php
    
    add_action("gform_post_submission", "gf_ga_tracking", 10, 2);
    function gf_ga_tracking($entry, $form) { 
    
        if($form['id'] != 4) return; ?>
    
        <script type="text/javascript">
            jQuery(document).ready(function($) {
                _gaq.push(['_trackEvent', 'Forms', 'Submission', 'GA Testing Form FINAL']);
            });
        </script>
    
        <div class="ga-confirmation">Nice! Your <strong>successful</strong> form submission was recorded by Google Analytics.</div>
    
    <?php } ?>

    We have multiple forms on our site. I want to track each individually (our form numbers are 1,2,6,7,8,9) with separate categories (same Action).

    The reason for this is for segmenting within Google Analytics. Is there a way to alter the code above to account for 6 separate forms?

    I'm comfortable putting things into the functions.php, but to someone's earlier point, it would be nice if, right under the field to change the Submit button text, we had the option to paste in the GA Event code.

    Posted 6 years ago on Tuesday August 21, 2012 | Permalink
  2. You should be able to place the JS you'd like into each of the form's confirmation text areas as well in the form settings - just make sure it's wrapped in script tags. Would that work for you?

    Posted 6 years ago on Tuesday August 21, 2012 | Permalink
  3. go4
    Member

    Hi, I have used the code example on this page using gform_post_submission as provided by Actsoft and it works fine when a confirmation message is displayed after submission but it won't work if I choose to redirect to a thank you page.

    The post submission only triggers event tracking once the form is validated and sent successfully which is the ideal outcome. My form is used for several location pages and adds the page title to the value in GA event tracking similar to this code http://pastie.org/4551792 . But I also need it to go to a thank you page.

    What can I do to trigger the event tracking post submission and display a redirect page?

    Posted 6 years ago on Wednesday October 3, 2012 | Permalink