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 2. Go to Contact Tab in wordpress Admin 3. Edit your form and scroll to bottom to “Additional Settings” Enter the following: on_sent_ok: "ga('send', 'event', 'Contact Form', 'sent');"
Comments
Leave a Comment
You must be logged in to post a comment.
Petr says
Thank you very much!
Searching for this for a long time.
Updated also http://wordpress.org/support/topic/not-shown-message-was-sent-ok-if-tracking-form-submission
Ori Tzvielli says
your welcome. glad to help
ABonaplata 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?
Ori Tzvielli 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.
James 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?
Ori Tzvielli says
can you specify which template/theme you are using and write a short description about the customization you are using?
Kartikaye says
A) The code displayed in step 1 ie latest google universal analytics code is to be pasted somewhere ?
B) “Contact Form” in step 3 has to be the name of a Goal ?
Ori Tzvielli says
Step 1 – Make sure you have google analytics universal code in all of your pages on your website.
Step 2 – Yes, should be a unique description name of form
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!
Ori Tzvielli says
i don’t think you’ll be able to use the variable $campaign as this setting is in the contact form 7 settings and you won’t get any value for $campaign.
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 :
Ori Tzvielli says
if it’s a fixed value, then it will work.
let me know how it goes
Mike 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
Ori Tzvielli says
Hi Mike, Personally haven’t done any specific field validation but this is a great point. Will try to research this and maybe others have input on this.
Mike 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
Ori Tzvielli 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.
Andrea Michelotti says
Hi everyone,
after lots of searches, the solution above really fixed everything.
Thanks
Ori Tzvielli says
Glad we could help!
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.
Ori Tzvielli 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’);”
Natasha 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!
Natasha 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 😉
Ori Tzvielli says
happy you got it to work!
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 🙂
Catherine 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
Ori Tzvielli says
can you send me your url?
Robert 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
Ori Tzvielli says
would recommend in analytics “goal details” to setup “category”, “action” and “label” but it really depends on your specific even and/or goal. can you explain further?
Robert says
What I was asking (and it seems Mark is also asking here), is how does one get the correct settings for these 4 “Goal Detail” boxes to set up a Google Analytics Goal of Contact Form 7 submissions?
Please see screenshot:
https://www.dropbox.com/s/qcirwvwu8qrjxac/ga_CF7_tracking-settings.png?dl=0
thanks again!
Drew Hammond says
Is there a full list of hooks that we can use somewhere?
Julien 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.
Leon says
Hi Ori,
I found a little difference between your trackevent code and contactform7.com
and it seems like your code can not work on my site
Ori Tzvielli says
what did you try?
Leon says
i tried both,
but no one worked, i can not see any date in the goal-reports of GA.
this problem has trouble me weeks
Ori Tzvielli 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?
Leon says
oh, i sent a wrong url, sorry.
here is my website “www. dl-drilling.com”
here you can see the “additional settings” and the Goal details.
Leon says
the “additional settings” and the Goal details.
http://zhongyuheavyindustry.tumblr.com/post/80954749436
Ori Tzvielli says
off hand dont see why it does not work:
1. can you specify exact contact form 7 version?
2. does form submit and send correctly? is it on http://www.dl-drilling.com/contact-us/ ?
3. do you see the events in behavior->events->top events?
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.”
Leon says
1.Version 3.7.2
2.yeah, the form work correctly.
3.and there’s no data
Ori Tzvielli says
can you try to create a simple html file/page without wordpress and see if clicking on event triggers
something like this:
1 (888) 555-1212
INSERT YOUR GOOGLE ANALYTICS UNIVERSAL TRACKING CODE HERE
Leon says
ok, thank you very much Ori.
i am trying to use the goodgle tag manager right now,
and test the event tracking in one or two days.
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
adrian 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.