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’.