Categories
WordPress

WordPress Contact Form 7 – Tracking Form Submissions in Universal Analytics

Are your Contact Form 7 submissions not working fine? Is the ‘Thank You’ success message flashing for a second and disappearing? The problem might be in the on_sent_ok hook.

The standard recommendation on the Contact Form 7 website is to use the following code.
[js]
on_sent_ok: "_gaq.push([‘_trackEvent’, ‘Contact Form’, ‘Submit’]);"
[/js]
The above code will work fine with Google’s Classic Analytics. For the new Universal Analytics code you need to change the JavaScript call to the following:
[js]
on_sent_ok: "ga(‘send’, ‘event’, ‘Contact Form’, ‘Submit’);"
[/js]
Now, if you are using Yoast’s WordPress Google Analytics plugin, you will have to change the trigger to the following:
[js]
on_sent_ok: "__gaTracker(‘send’, ‘event’, ‘Contact Form’, ‘Submit’);"
[/js]
I do not know why, but Yoast has decided to use ‘__gaTracker’ instead of ‘ga’.

9 replies on “WordPress Contact Form 7 – Tracking Form Submissions in Universal Analytics”

Thanks Kathir for the clear explanation and mention about Yoast GA plugin. I found about this on another website, but you made it very clear here. (Using ga instead of __gaTracker shows “not defined” error in the console).

Hi, and thanks for the post.

I have an issue with this tracking code.
1.Is yoast seo plugin the same as yoast GA?

2.I have seen this code on other pages as well, but they use ‘sent’ instead of ‘Submit’

Whats the diffrence?

Yoast SEO and GA are from the same people, but this code is specifically for the GA plugin. Where in Yoast SEO do you see tracking codes? Maybe I haven’t tried their advanced functionality yet.

I’ve been working on this all afternoon. We have a WP site with Yoast and Contact Form 7. Other posts had “send” instead of “Submit” for the last part of the code. Your code for Yoast+Contact Form 7 worked great. Thanks Kathir!

It seems Yoast plugin has been replaced with Google Analytics by MonsterInsights. I can’t find any code working for it… which one should?

Comments are closed.