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.

on_sent_ok: "_gaq.push(['_trackEvent', 'Contact Form', 'Submit']);"

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:

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

Now, if you are using Yoast’s WordPress Google Analytics plugin, you will have to change the trigger to the following:

on_sent_ok: "__gaTracker('send', 'event', 'Contact Form', 'Submit');"

I do not know why, but Yoast has decided to use ‘__gaTracker’ instead of ‘ga’.