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.

Google Analytics and conversion tracking with ajax

  1. I have researched this problem thoroughly on the forum and am still confused. (Note: I am talking here about ajax forms, where confirmation is on the same page and no redirect to a confirmation page.)

    I am been able to successfully track GA conversion goals (not talking events here but goals) by placing something like this in the confirmation:

    <script type="text/javascript">_gaq.push(['_trackPageview','/tla-thankyou']);</script>

    In the latest site I did this with, I am now getting a "_gaq is undefined" type of error when I submit the form and look at my console. Okay, I understand that the form is loading in an iframe and that possibly my code in the confirmation does not "see" the variable defined in the header of my page (via the GA code normally pasted just before the closing <head> tag. So I entered the full GA code (where the variable is defined) into the confirmation.
    And that seemed to solve the problem.

    My questions are this:
    1. Should I be worried about executing the full GA tracking code a second time? Once in the <head> of my page and once in the iframe
    2. Why do I need to add the full GA tracking code when I didn't before? Did something change with the latest version of Gravity Forms?

    It would be nice to have a simple answer once and for all the best method for those of us who wish to track virtual pages (and take advantage of the ajax form) - with some clear understanding for those of us who are not super technical EXACTLY what we should or should not be doing. So many of us choose Gravity forms because of the ease of creating lead gen pages (meaning we are marketers first, coders second) and need a reliable way of tracking form submissions in Google Analytics - one we can use over and over again.

    Any help will be appreciated.

    thanks,
    Lisa

    Posted 12 years ago on Thursday August 16, 2012 | Permalink
  2. Same here! Looking for a workable way for tracking conversions either by event tracking or virtual URL. Whatever works best!

    As a non-techie I just don't like the need for adding PHP code to functions.php as a "solution" here: http://www.gravityhelp.com/forums/topic/onclick-tracking#post-7734

    Thx,

    Stan

    Posted 12 years ago on Friday August 17, 2012 | Permalink
  3. David Peralty

    Juicy - iframes only see the code within the iframe, that's why you had to add more to it to get things to work. It shouldn't have worked before, so I am not sure why it did. You shouldn't be worried about having it in there "twice" because again, the iframe is seen as independent of the page it is being pulled into.

    The link that stan linked is the best way to do things.

    Stan- I am not sure why you don't like the functions.php solution, but it is effective, and uses our built-in hooks system. If you could give me more information on how you would like to see it work, I'd be happy to pass it on to the developers.

    Posted 12 years ago on Friday August 17, 2012 | Permalink
  4. David,

    A belated thanks for the reply. I am not afraid of adding stuff to functions.php but the solution in the link that Stan posted assumes you only have one form (and are doing event tracking but I assume you could swap out trackEvent for trackPageview)...I'd have to get someone to code it to work with my many forms without pasting the code in there for each form. But definitely something to look into.

    Posted 12 years ago on Thursday September 6, 2012 | Permalink
  5. I added the code snippet here (http://www.gravityhelp.com/forums/topic/onclick-tracking#post-7734) to functions.php and changed the form ID. JQuery is available, and the GA tracking code is in the site header.

    The form submitted properly but the Ajax response I saw was the one I set up in the plugin instead of "Nice! Your successful form submission was recorded by Google Analytics".

    I did get the email from the form, but I don't see it reported as an event in GA. Can you please point me in the right direction?

    Posted 12 years ago on Wednesday November 28, 2012 | Permalink