WordPress.org

Forums

Contact Form 7
Contact form 7 and google analytics problem (31 posts)

  1. sallemannen
    Member
    Posted 1 year ago #

    Hi

    I've spent couple of hours trying to solve this without any results.
    My problem is how i track for example submitted contact forms on my google analytics. I've tried different codes in contact form, these are:

    on_sent_ok: "ga('send', 'event', 'Contact Form', 'sent');"
    on_sent_ok: "_gaq.push(['_trackEvent', 'Intresseanmälan1', 'Submit']);"
    on_sent_ok: "ga('send', 'event', 'Intresseanmälan2', 'sent');"
    on_sent_ok: "ga('Submit', 'event', 'Intresseanmälan3', 'sent');"
    onClick="_gaq.push(['_trackEvent', 'Intresseanmälan4', 'Skickat', 'Kontaktformulär',, false]);"
    on_sent_ok: "ga(['_trackEvent', 'Intresseanmälan5', 'Skickat', 'Kontaktformulär',, false]);"

    and no one works. When i add the code in additional settings and then submitt a form name, email and so on doesnt reset (the form goes through). This can be fixed by removing the code in additional settings.

    So i appreciate some help here..

    https://wordpress.org/plugins/contact-form-7/

  2. pcreytens
    Member
    Posted 1 year ago #

    Same problem here:
    on_sent_ok: "ga('send', 'event', 'Contact Form Content Page', 'Verzenden');"

    Followed instructions from here:
    https://www.impression.co.uk/blog/825/event-tracking-wpcf7-universal-analytics/

    And (re-) started plugin several times...

  3. mpek
    Member
    Posted 1 year ago #

    Did you enter the code in "additional settings" below your form and email form(s)?
    Check here:
    http://contactform7.com/tracking-form-submissions-with-google-analytics/

    I'm trying this feature as well. No additional help from me at this point...sorry

  4. RayBoyd1455
    Member
    Posted 1 year ago #

    Also have a issue with the Analytics code. With the code in the Additional Setting box the code works but the form is not displaying the "Thank You" message so we are getting multiple submissions from the same user.
    I was using this code;
    on_sent_ok: "_gaq.push(['_trackEvent', 'Contact Form', 'Submit']);"
    We have multiple forms so I was changing the 'Contact Form' string for each form, this would create a unique Category in Google Analytics for each form.
    Here is one of the forms;
    http://www.atlplastic.com/DrFernandoBursteinblog/

  5. Roundcape
    Member
    Posted 1 year ago #

    Hi All,

    I was struggling with this, and other posts didn't seem to resolve.

    Additionally, errors were very random, some of my sites work, some don't. I was getting a "Uncaught ReferenceError: _gaq is not defined" when submitting (you can see this by opening the developer tools, console on google chrome)

    At the end I resolved by introducing the following code (Ref 1) on the Header, at the beginning, of the page where your contact form is, replacing the UA-XXXXXX-1 with your analytics code.

    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
      _gaq.push(['_trackPageview']);
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    
    </script>

    Then you can add the tracking code in the "Additional Settings" of the form, where you replace the /goals/enquiry-sent with whatever goal page you have defined (Ref 2):

    on_sent_ok: "_gaq.push(['_trackPageview', '/goals/enquiry-sent']);"

    This now works consistently across all my websites. Hope this helps!

    KR
    Siro

    References to above procedure:
    Ref 1) https://developers.google.com/analytics/devguides/collection/gajs/
    Ref 2) http://www.creare.co.uk/goal-tracking-contact-form-7

  6. Aaron Dicks
    Member
    Posted 12 months ago #

    Hi everyone,
    Firstly, thanks for referencing the article I wrote (here on Impression).

    I wanted to drop by for future visitors to help clarify any issues on this topic - I've subscribed to posts via email. Alternatively there's a comment section under the article.

    @Roundcape. I am always weary with pushing additional page views on your website in the way you have identified above - this will double those page views in your Audience Overview in Google Analytics and may be misleading. Events (as per my article) are a much better solution as the double page views are avoided, plus you can also store additional data - such as category, action, label, value).

    To sum up, if you're using Universal Analytics, the correct text to paste into Additional Settings will look something like this;

    on_sent_ok: "ga('send', 'event', 'category', 'action);"

    Thanks
    Aaron

  7. platypidesigns
    Member
    Posted 12 months ago #

    Hi,

    I too have setup my Contact Form 7 the way it has been outlined in the article: https://www.impression.co.uk/blog/825/event-tracking-wpcf7-universal-analytics/

    I have all the settings in place but it will not track. I know I'm using Universal GA so that's fine. I have the right code in the Additional settings of the wordpress Contact Form 7 plugin, the goal setup in GA and it's not tracking.

    Any ideas, thoughts?

    Is there something we should be looking for in the code that might tell us if we have things right?

    Thanks.

  8. Aaron Dicks
    Member
    Posted 12 months ago #

    Hi platypideigns
    Are these events tracking in Google Analytics under Behaviour > Events?
    Have you set up your goals exactly matching your events?

    You might also need to check out whether there are any JavaScript issues on the page when you click submit, too. If you use a browser with a console (FF, Chrome, etc), are there any errors there?

    Aaron

  9. Aaron Dicks
    Member
    Posted 12 months ago #

    Also, I have noticed I missed a single quote off the end of that code snippet - could you confirm whether you spotted that?
    It should be:

    on_sent_ok: "ga('send', 'event', 'category', 'action');"

    So for an enquiry form submission, copy this exactly

    on_sent_ok: "ga('send', 'event', 'Enquiry', 'Submit');"

    Aaron

  10. pitterz
    Member
    Posted 9 months ago #

    Hi,

    We used to have the old google analytics code in the additional settings box and it tracked form submissions fake page views with the below code:

    on_sent_ok: "_gaq.push(['_trackPageview', '/thanks']);"

    Then we updated to universal analytics and replaced the above code that was in the additional settings box with the below and set up an event goal to match it:

    on_sent_ok: "ga('send', 'event', 'category', 'action', 'label');"

    .... but now it doesn't track form submissions.

    I also tried send pageview /thanks with the new universal code and set the page destination as a goal and still no joy.

    Please can someone help with this? Do we need to implement Roundcape's procedure first before this will work??

    Any help would be much appreciated.
    Thanks

    Hi All,

    I was struggling with this, and other posts didn't seem to resolve.

    Additionally, errors were very random, some of my sites work, some don't. I was getting a "Uncaught ReferenceError: _gaq is not defined" when submitting (you can see this by opening the developer tools, console on google chrome)

    At the end I resolved by introducing the following code (Ref 1) on the Header, at the beginning, of the page where your contact form is, replacing the UA-XXXXXX-1 with your analytics code.

    <script type="text/javascript">

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
    _gaq.push(['_trackPageview']);

    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();

    </script>

    Then you can add the tracking code in the "Additional Settings" of the form, where you replace the /goals/enquiry-sent with whatever goal page you have defined (Ref 2):

    on_sent_ok: "_gaq.push(['_trackPageview', '/goals/enquiry-sent']);"

    This now works consistently across all my websites. Hope this helps!

    KR
    Siro

    References to above procedure:
    Ref 1) https://developers.google.com/analytics/devguides/collection/gajs/
    Ref 2) http://www.creare.co.uk/goal-tracking-contact-form-7

  11. RayBoyd1455
    Member
    Posted 9 months ago #

    I ended up setting a Goal and using the setting here, using the UA code;
    http://www.creare.co.uk/goal-tracking-contact-form-7

    I think one of my problems was I was using the old _gaq.push code but using the new UA anilytics code.

  12. pitterz
    Member
    Posted 9 months ago #

    Thanks for your reply - I've set this up as a destination goal using the Creare instructions and still no joy.

    If anyone has any other ideas that would be great!

    Thanks,

  13. RayBoyd1455
    Member
    Posted 9 months ago #

    @pitterz
    Results on Google Anilytics Goals take 24 to 48 hrs. to show up. Has it been that long since you set it up and did a test form submission?

  14. pitterz
    Member
    Posted 9 months ago #

    Yea it's been that long and still no joy.

    Any help much appreciated before I remove the form and get a dev guy to code one up?

  15. RayBoyd1455
    Member
    Posted 9 months ago #

    Can you post the exact line you added to your Additional Settings in your Contact form, and if you have more then one form make sure it is the one you want to track.
    Can you also post the exact line you put in the Destination field for your Google Goal( you have your Goal type set to destination right)?

  16. bmcgoff
    Member
    Posted 9 months ago #

    Hey all,

    Very useful thread, so thanks. If you're still struggling, this may be your problem:

    I was working on a site that had Google Analytics for WordPress installed (by Joost). The developer used this plugin to add Analytics.

    Using the method outlined above (adding the UA event tracking code to CF7 additional settings), the form would not reset or show the "thank you" message.

    I deleted the Joost plugin and added the UA tracking code to the footer manually. After that, everything works just fine.

    So if you're using any third party plugin to add Analytics code to your site, that could be the problem.

    Hope that helps!

    -Brock

  17. John-Pierre Cornelissen
    Member
    Posted 8 months ago #

    I just followed the explanation from 'impression.co.uk' and submitted my contact forms myself. Now I need to wait 24~48 hours to see if the submissions got tracked.

    @bmcgoff / Brock: with Google Analytics for WordPress installed (by Joost) you likely mean Yoast. Just add this in here so this threat can also get found by that keyword.

    Unfortunately you did not indicate which version of that plugin was used. I use "Google Analytics by Yoast" version 5.0.5 and I have Universal tracking enabled. When I submit the contact form it does show the "thank you" message.

    On the flip side, I don't see my the CF7 additional settings code being added to the page source. So I'll wait and see if there is any goal being tracked over the next few days.

    JP

  18. John-Pierre Cornelissen
    Member
    Posted 8 months ago #

    @bmcgoff / Brock: an additional note. I just wrote I did see the "thank you" message after submitting the form. I have been able to reproduce the issue that you don't see that message though. Here is the reason:

    The plugin "Google Analytics by Yoast" has a setting to "Ignore users" (by role) to prevent your page views being tracked while you work on the website. It does this by stripping out the Google Analytics tracking code for ignored users that are logged in to WordPress.

    This means that if you submit the contact form while you are logged in as an 'ignored user', there is no 'ga' tracking code but CF7 still submits the form and still triggers the 'ga' event. This results in an error and you don't see the "thank you" message. If you then look in your browsers console (F12) on the error tab you see an error:

    ReferenceError: ga is not defined
    ga('send', 'event', 'Contactformulier', 'Verzonden');

    Hope this explains the problem you described.

    Now I still need to wait 24~48 hours to see if my form submissions are being tracked.

    Regards
    JP

  19. pitterz
    Member
    Posted 8 months ago #

    This is sorted now thanks everyone!

  20. John-Pierre Cornelissen
    Member
    Posted 7 months ago #

    It took me a while to get back on my previous post but my CF7 submissions are correctly tracked as goals. I used the CF7 guide from impression.co.uk and I also use the "Google Analytics by Yoast" plugin version 5x with Universal tracking enabled and

    Pitfalls when it doesn't track
    - The ignore user setting in the "Google Analytics by Yoast" plugin
    - A Google Analytics filter that excludes your own IP address
    - ...

  21. John-Pierre Cornelissen
    Member
    Posted 5 months ago #

    Weird

    This original code stopped working, it produced the error "ga is not defined" again. Ihad to replace the first part to get it working again.

    Original (stopped working)
    on_sent_ok: "ga('send', 'event', 'category', 'action');"

    New one
    on_sent_ok: "__gaTracker('send', 'event', 'category', 'action');"

    Not sure when this happened, maybe after an update of the yoast analytics plugin.

  22. uomopalese
    Member
    Posted 5 months ago #

    @John-Pierre Cornelissen: With the last version of Yoast Google Analytics and CF7 your code works fine. Thanks

    The code:
    on_sent_ok: "__gaTracker('send', 'event', 'category', 'action');"

  23. John-Pierre Cornelissen
    Member
    Posted 5 months ago #

    @uomopalese

    Thank you, I know that is the code I use now.
    But it used to be ga(.. rather then __gaTracker(...

    Do you know if this is caused by a change from Analytics or from the Yoast plugin?

    thx
    JP

  24. uomopalese
    Member
    Posted 5 months ago #

    @John-Pierre Cornelissen

    Hi, for what i see, there is no trace of your code in the google analytics guide https://developers.google.com/analytics/devguides/collection/analyticsjs/events;
    I contacted support on the Yoast Analytics site, I guess they will answer in one business day, i will let you know their answer.

  25. John-Pierre Cornelissen
    Member
    Posted 5 months ago #

    Thanks again @uomopalese,

    After some creative Googeling I found it
    https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#renaming

    Then I did some further searching and found this thread
    https://wordpress.org/support/topic/note-change-of-global-function-ga-_gatracker

    So yes the function is changed by an update of the Yoast Analytics plugin. I am glad it works again but am slightly annoyed that this wasn't in the plugin release notes and I only noticed it after testing my contact form after an update of that plugin.

    thanks
    JP

  26. uomopalese
    Member
    Posted 5 months ago #

    Thanks @John-Pierre Cornelissen

    Yoast support has kindly answered that they "can't give personal support for our free plugins" (and i understand this).
    Just as additional information, i dug by myself in the plugin folder, and i found out that these two files:

    • frontend/class-universal.php (line 165 and subsequent)
    • frontend/vews/tracking-universal.php

    are both written with the new "__gaTracks" code, in accordance with the google guideline, as you properly reported.

  27. Aaron Dicks
    Member
    Posted 5 months ago #

    I think Yoast would have renamed the JS object to keep it compartmentalised from other JS Google Analytics plugins. I'll make a note to update my blog post to reflect this, thanks!

  28. adeb
    Member
    Posted 5 months ago #

    Hi
    I tried the new "__gaTracks" code but that broke the confirmation message for some reason. When I use the new code I don't get a confirmation message when I press the button to send my message. When I go back and change to the "ga" code everything works fine! Expect that it doesn't show up in Analytics of course.....

    It would be fantastic if Contact Form 7 would create a solution that "just worked" As it is right now the web is full of solutions but not one of them is working!

    Please help!
    //Per

    http://www.pocketogram.se

  29. John-Pierre Cornelissen
    Member
    Posted 5 months ago #

    @adeb,

    I looked at the page source of pocketogram.se and I don't think it uses the Analytics by Yoast plugin.

    The Analytics code that is in that page uses the 'ga' function (as per the line that contains: //www.google-analytics.com/analytics.js','ga')

    That means you need to use the 'ga' code and not the '__gaTracks' code.

    For it to show up in Analytics you may have to wait a day or so. You did create a goal in Analytics as explained here, right?

    Regards
    JP

  30. bmcgoff
    Member
    Posted 5 months ago #

    Ignore (I'm just unsubscribing).

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic