WordPress.org

Forums

[Plugin: Contact Form 7] Google Analytics goals using the using the _trackPageview function (26 posts)

  1. exodo
    Member
    Posted 5 years ago #

    I need to track how many inquiries comes from the website through the contact form.

    Searching through forums I could only find a hack how to disable the Ajax and send the user to a "thank you" page instead.

    Google Analytics, however, says Javascript events can be tracked even if the user is not sent to a "thank you" page:

    https://www.google.com/support/googleanalytics/bin/answer.py?answer=55521

    By using the _trackPageview function, you can assign a page filename to any Javascript event.

    To track an event, call _trackPageview() with an argument specifying a name for the event. For example:

    pageTracker._trackPageview("/homepage/link1");

    HTML Code Examples

    The following illustrates how to log an onClick event:

    Trouble is I have no clue where this code would be added and exactly how it would look. Any help appreciated!!

  2. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    Yes. Good point. You don't have to send to meaningless "Thank you page."

    And the recent version of Contact Form 7 has a feature just what you need.

    http://ideasilo.wordpress.com/2009/05/31/contact-form-7-1-10/

    You can use on_sent_ok action hook for that.

    Good luck.

  3. exodo
    Member
    Posted 5 years ago #

    Thank you! This is great!! Just what I need.

    I upgraded to Contact Form 7 1.10 and set up my goals in the form and in Google Analytics.

    The only issue now is that the confirmation box message on the page (Your message has been sent etc...) has disappeared (!)

    This is true for both Safari and Firefox on Mac OS X

  4. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    It should work well with the response message box. If not working, there might be errors of JavaScript or something blocking it to work.

  5. refinedinternet
    Member
    Posted 5 years ago #

    I had a similar problem, but discovered that it was down to Google Analytics for WordPress, I'd disabled Admin tracking, so when it finds an Admin session the Analytics code isn't included and then Contact Form 7 errors because the Javascript function doesn't exist. Logging out of the Admin session fixed it.

  6. djones101
    Member
    Posted 5 years ago #

    Takayukister,

    What if you weren't forwarding to a meaningless "Thank You Page", but an Important "information page" upon completion of the form. In my case, I have to have a customer fill out a waiver prior to being able to purchase workout time in my store.

    Is it possible to redirect the page upon completion?

    Thanks,

    Dan

  7. kidAlynch
    Member
    Posted 5 years ago #

    Just a few questions about how this works. I too am looking for a way to have my Google Analytics Conversion to work. I have read all the links posted here and I feel really close but I am still not able to see any results days later in my analytics.

    The form I would like to track:
    http://www.mercycollege.edu/contactemail-us

    What I have added to my Additional Settings:
    on_sent_ok: “pageTracker._trackPageview('/contactemail-us/thanks.php');”

    I am still not quite sure what this line does in terms of action and where I should check to see if its working? Does it put thanks.php in the url?

    If anyone sees a blatant mistake or has any advice or more details on how this command works please please let me know!

    Thanks!

  8. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    @kidAlynch Your on_sent_ok code seems correct. But it never works. Because on_sent_ok hook is called in the JavaScript (Ajax) function of Contact Form 7, and the JavaScript does not exist on your site.

    Check your footer.php in your theme. I guess you can't see <?php wp_footer(); ?> in it. Maybe you can get it to work by using wp_footer() correctly.

    http://codex.wordpress.org/Theme_Development#Plugin_API_Hooks

  9. kidAlynch
    Member
    Posted 5 years ago #

    takayukister, thanks for the tip.

    I went through and made sure that my api hooks were all in tact and where they needed to be. Especially <?php wp_footer(); ?> which now appears just before the </body> tag in my code.

    However, now I have lost the confirmation message box? I know you mentioned previously that this could be caused by a js error. I am using quite a few js files including protoype and I wanted to be sure that the jquery.js file that contact form 7 uses isn't the conflict. If it is I have to find another solution.

    Also, by using the setting mentioned above: on_sent_ok: “pageTracker._trackPageview('/contactemail-us/thanks.php');”

    should I be seeing thanks.php in my url after sending the form? Please let me know. I really really really appreciate the feedback.

    Thanks!

  10. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    Okay, seems all working correctly now. I think no problem remains. That's good.

    Check out Google Analytics documents carefully. You'll get that _trackPageview doesn't mean redirection.

    http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55521

    The thanks.php is just a dummy path. Doesn't mean jumping to thanks.php.

    You don't have to worry. You'll see '/contactemail-us/thanks.php' log in your Google Analytics a few days later.

  11. clickbasics
    Member
    Posted 5 years ago #

    pageTracker._trackPageview("/homepage/link1");

    and

    You can use on_sent_ok action hook for that.

    I have contact-form-7.2.0.zip

    I do not understand how to modify the following code as above.

    $on_sent_ok = $wpcf7_contact_form->additional_setting( 'on_sent_ok', false );
    				if ( ! empty( $on_sent_ok ) ) {
    					$on_sent_ok = array_map( 'wpcf7_strip_quote', $on_sent_ok );
    				} else {
    					$on_sent_ok = null;
    				}
    				$items['onSentOk'] = $on_sent_ok;

    If this is generic to any form on my site, how can a specific page file name be used effectively here?

  12. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    @clickbasics you can see an example on this article:

    http://ideasilo.wordpress.com/2009/05/31/contact-form-7-1-10/

  13. jsalcedo
    Member
    Posted 5 years ago #

    @takayukister "It should work well with the response message box. If not working, there might be errors of JavaScript or something blocking it to work."

    ==> It works fine in Firefox, however in Safari (Mac) it doesn't show the confirmation message.

  14. sitecreations
    Member
    Posted 5 years ago #

    I use Thesis 1.5 on a dozen or so sites. I was hoping to use Contact 7 on them for lead generation form (and of course conversion tracking.)

    So it seems that I cannot use Contact 7 if I wish to use the event tracking like this:

    on_sent_ok "javascript:pageTracker._trackPageview('/contactforms/main/lead');"

    Note: The on_sent_ok is firing, I have tested that with a simple alert.

    But conversions are never registered with the /contactforms/main/lead "virtual" page view. I am assuming that there is something related to the API calls to Google Javascript Tracking... Google says:

    if your pages include a call to _trackPageview, _setAllowLinker _trackTrans(), your Analytics tracking code must be placed in your HTML code above any of these calls. In these cases the tracking code can be placed anywhere between the opening <body> tag and the JavaScript call.

    Thesis is very popular.. anyone have thoughts about how to make this work?

    I'm going to try putting the Analytics code in the header instead of the footer, but this is a real long-shot.

  15. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    @sitecreations it's obviously a JavaScript issue though, I may be able to answer it if I can see your site's HTML source. So where is you site?

  16. sitecreations
    Member
    Posted 5 years ago #

    This one is at http://www.flowfunding.com/contact-us-apply
    ...and thanks

  17. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    There are two Analitics codes in your source. You should remove one of them.

    This should work.

    on_sent_ok "pageTracker._trackPageview('/contactforms/main/lead');"

  18. sitecreations
    Member
    Posted 5 years ago #

    I removed it, still nothing.

    Should I try to put the Google Analytics code at the top (only)?

  19. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    How did you test that? Google Analytics takes a few days to show.

  20. sitecreations
    Member
    Posted 5 years ago #

    giving it more time then.

  21. vinnyred
    Member
    Posted 5 years ago #

    Hi

    Is there anyway of testing the on_sent_ok hooks as I've set up the goals and funnels in analytics but cannot seem to get it to trigger.

    It's basically tracking an adwords campaign and i'm needing to track who submitted info via the contact from depending on which landing page they came from.

    The funnel is:
    1. Google landing page
    2. contact form
    3. the on sent ok hook from contact form 7

    Any advice would be much appreciated.
    thanks
    Vin

  22. jaimiescott
    Member
    Posted 5 years ago #

    Hello -- Like KidAlynch and exodo the confirmation box goes away (in Firefox and IE) when I add the following code to the additional settings on my contact form.

    on_sent_ok: pageTracker._trackPageview("/Contact/Send");

    Interestingly when I add this line -- on_sent_ok: "alert('TEST');" -- the confirmation box does not go away. I'm not using the Google Analytics for WordPress plugin as refinedinternet above says caused his problem. I would really like to be able to track contact form submissions so that I can run an Adwords campaign and I like the ContactForm7 plugin other than this issue and would rather not have to change. Can anyone help me figure out how to get the confirmation box back and run the GA _trackpageview code.

    This is the form in question -- http://www.blissfuldogowner.com/contact/

    Thanks.

  23. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    on_sent_ok: pageTracker._trackPageview("/Contact/Send");

    Look carefully. The correct input should be:

    on_sent_ok: "pageTracker._trackPageview('/Contact/Send')";

    See
    Tracking Form Submissions with Google Analytics

  24. brandoo
    Member
    Posted 5 years ago #

    same problem here: http://artgarden.es/en/contact/

  25. brandoo
    Member
    Posted 5 years ago #

    looking at the sourcecode of other pages with problems the only script everyone seems to have in common is jquery - unlikely to be the cause?

  26. joesken
    Member
    Posted 4 years ago #

    No answer I'm afraid but I do have some information.

    The issue I am having is similar to many people above. When I add the pageTracker code to the on_sent_ok code the verification box no longer appears.

    on_sent_ok: "pageTracker._trackPageview('/contact/sidebar-success.html');"

    This is indeed because of a Javascript error. The error is:

    Uncaught ReferenceError: pageTracker is not defined

    So basically it is trying to resolve the reference before the Google JS. However as the Google JS is already on the page and is being correctly called I'm a little lost as this variable is getting introduced via the AJAX call on correct form submission.

    In my case it is from a page called "articles" so the headers are:

    Request URL:http://www.mysite.com/articles/#wpcf7-f1-t1-o1
    Request Method:POST
    Status Code:200 OK

    And the content of that is:

    { "mailSent": 1, "into": "#wpcf7-f1-t1-o1", "captcha": { "captcha-163": "http://www.mysite.com/wp-content/uploads/wpcf7_captcha/896030197.png" }, "message": "Your message was sent successfully. Thanks.", "onSentOk": ["pageTracker._trackPageview(\'/contact/sidebar-success.html\');"] }

    Hope this is a clear enough explanation of the problem.

Topic Closed

This topic has been closed to new replies.

About this Topic