After searching for about 20 minutes, i could not find any hooks to explain how to track events in analytics for a wordpress site we are using (contact form 7). All you have to do is: 1. Make sure you have the latest google universal analytics code google-analytics-new-code 2. Go to Contact Tab in wordpress Admin contact-tab-form-7 3. Edit your form and scroll to bottom to “Additional Settings” additional-settings Enter the following: on_sent_ok: "ga('send', 'event', 'Contact Form', 'sent');"

Comments

  1. says

    Thank you for this post!

    I’ve been struggling for months about Contact Form 7 tracking in Analytics without success.

    Next step is to configure Analytics to report this results. Could you tell me how? Through goals?

    • says

      you can view the event tracking in analytics on the left hand side through “content” -> “event”.

      also, you can setup a “goal” and select “event” to show it in “goals”.

      let me know if you need additional detail on this.

  2. says

    I used this code in additional settings as suggested but on my site it knocks out the submission validation and the form does not reset after submit? Any suggestions?

  3. Pepe says

    Hi Ori!

    Just a tip: how should I set up Google Analytics to track the Goals, as you say in your post? I’m using this code: on_sent_ok: “ga(‘send’, ‘event’, ‘”.$campaign.”‘, ‘sent’); ($campaign is a PHP variable, is that ok?).

    Then I go to Analytics, Goals, and I follow the steps of the “wizard” till I arrive to the step 3 (Event conditions). It asks me for 4 parameters: category, action, label and value. What should I put on these to link your code and the goals? maybe the four parameters of your code correspond exactly to them? as in:

    category = send
    action = event
    label = $campaign
    value = sent

    Is that ok?

    Thank you very much for your post!

  4. Pepe says

    Well that was not the issue at all. Imagine that $campaign it’s not a variable, but a fixed value, like in your original code. The set up of Google Analytics it’s ok?

    I don’t know how to assure this, because it’s hard to debug :

  5. says

    Hi everyone

    tracking the fired event is a very good first step. But don’t you think the road is the true goal. Hence, knowing how the form is filled out by firing events to track the goal funnel would be awesome. I checked the controller.php but the “on_sent_ok” functions can’t be utilized.

    Does anyone have an idea how to implement more additional settings in the form configuration so a GA onClick event is inserted in the fields? Firing validation error events might also be a necessary.

    Thanks
    Mike

  6. says

    Hi Ori, great to hear you’re up to this too. I did a little brainstorm and Google search on this. Would be awesome to get others involved. What are your ideas and thoughts about this?

    1st – There’re certain user cases where multiple forms on a single page might mess up the conversion tracking. Hence, events which were fired should have added the contact form title to the category.

    2nd – To track the conversion funnel a start event have to be fired upon focus of any field … user might start filling out forms non-linear.

    3rd – After focusing a new field (onblur) an event has to be fired for the previous field.

    4th – To track the actual goal flow a timestamp might be added to the event label. This will provide intel on the necessary duration to fill out forms and possible problems.

    5th – Do you agree that real time validation is necessary? It would be a great usability boost. Validating fields and firing “error” events to track fields which cause conversion drop outs at the end goes the wrong way.

    6th – Tracking validation errors where the input value is provided as the event value will boost conversion optimization a lot too.

    7th – Unless there’re no validation errors the submit button should not be able to trigger.

    Here i found some good input:
    jQuery real time validation: http://www.1stwebdesigner.com/tutorials/building-real-time-form-validation-using-jquery/

    Showcase for Google Analytics Events: http://www.seerinteractive.com/blog/event-tracking-explained

    Kind regards
    Mike

    • says

      Hi Mike,

      We create a blog post and video to try to answer your question about the detailed submission of form fields.

      Please see the article at https://www.astralwebinc.com/event-tracking-detailed-forms-analytics/

      This article does not show exact detail for wordpress & contact form 7 but the same idea should apply. It should work if you place both 2 scripts in the html of your contact page form (edit contact page under WordPress -> Pages -> Edit page and rename the contact form name in script.

      Let me know your thoughts on this.

  7. Jetel says

    Dear WP Contact form 7 professionals, hopefully you can help me. Want to track CF7 submissions in GA via event tracking. I don’t know how to use the Additional Settings field while there is already a text. How can I add more to make it work. Perhaps it is a basic use of ” or ; Don’t know.

    There is already and I need to use:

    on_submit: window.cf7multiclick.reactivate('.wpcf7-submit');

    And I want to add event “objednavka” (means “purchase order” in czech):

    on_sent_ok: "ga('send', 'event', 'objednavka', 'sent');"

    How should the Additional Settins field look like? Thx for help.

    • says

      Hi Jetel.

      Have you tried to use them one after the other? (please make sure your quotes and semi colon are correct and a new line between them two)
      what happens then?

      on_submit: “window.cf7multiclick.reactivate(‘.wpcf7-submit’);”
      on_sent_ok: “ga(‘send’, ‘event’, ‘objednavka’, ‘sent’);”

  8. says

    Hi Ori & everyone,

    Thanks for the post. I’m using using Contact Form 7, the Contact Form DB plug-in, and universal analytics on a new website for Hands On Science (handsonscience.com.au). This is running on WooTheme’s Function template. So far, I’ve just tried event tracking on the e-newsletter sign up box using the code:

    on_sent_ok: "ga('send', 'event', 'E-newsletter sign-up', 'sent');"

    However, the form no longer validates and clears after it’s sent – though it does send the email and record the entry in the database. I can’t see any events from my test emails in Google Analytics, but this may be because it’s less than 24 hours since I set it up. Would be grateful for any ideas on how to get this working.

    Many thanks!

  9. says

    Not sure how, but by deactivating the Contact DB plug-in, deleting the code, adding the code again and reactivating the plug-in, I seem to have got it working. Wish I could explain why, but at least it does 😉

  10. Jetel says

    Dear Ori,

    thx for trying to help. I am aware of quotes and semicolons. Trying your code unfortunately doesn’t help. Have tried all possible combinations of using/not using quotes, putting on_sent_ok before on_submit etc. Now even the “successfuly send” message doesn’t show up even when I left the Additional settings field blank. What a mess…

    I wonder why so basic functionality hasn’t been implemented yet 🙂

  11. says

    I have tried adding your code but it’s not picking up in my GA account.
    Can you please confirm exactly how I am to set up not just this code (as i’ve just pasted it verbatim into the fields stated), but also exactly what I need to do inside my GA account? I am on universal analytics.

    Thanks
    Catherine

  12. says

    Dear Ori,

    When you say ‘you can setup a “goal” and select “event” to show it in “goals”.’ above – I have a question:

    What do I set as the Goal Details (step 3) when setting this up in Analytics? There are 4 “Event Conditions” – Category, Action, Label & Value – and at least 1 must be set to complete this et-up.

    many thanks!

    Rob

  13. says

    Thank you a lot. I did not know how to do it and I did not undertand the explanation on Contact Form7 help site.
    It seems to work. I’ll just wait few days that everything is ok.

  14. says

    what is your website? also, please confirm that you have the universal analytics and not regular analytics installed. in addition, can you please copy and paste the line that you are inputting into “additional settings” box?

  15. James Bull says

    For the next person that stumbles upon this thread looking for a solution to get Universal Analytics sending events when deployed via Google Tag Manager (GTM):

    on_sent_ok: ga('create', 'UA-XXXXXX-1'); ga('send', 'event', 'web lead', 'right rail');

    … It seems that you have to recreate the GA tag, which is promptly ignored based on the comments returned via GA debugger, in order to send the event.

    Otherwise, an error is thrown due to an “unknown target.”

  16. Mark says

    Robert asked the question:

    What do I set as the Goal Details (step 3) when setting this up in Analytics?

    There are 4 “Event Conditions” – Category, Action, Label & Value

    Based on the on_sent_ok code you have provided, is the following correct:

    Category – send
    Action – event
    Label – Contact Form

    Will this properly capture a submitted form as a conversion in Google Analytics?

    I have tried numerous methods to get this to work, including the ping a dummy page, but so far my goal completion in Google Analytics is way higher then the number of actual emails I have received from form submissions.

    Thanks,
    Mark

  17. says

    Hi Ori,

    Thanks for the solution. I followed your instructions and, as I’m a noob, I’m stuck at defining a goal in analytics.

    I just want to track the form submissions as goals as I want to see the source (adwords, banners, direct traffic). Is there somewhere an example? (I tried the above but none seem to work).

    Hope I explained correctly what I’m looking for. Thanks again.

Leave a Comment