The old mechanism of submitting form events to Google Analytics involved using the “Additional Settings” tab of a specific contact form using code similar to:

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

In WordPress, it will look like this:

Note the “Deprecated settings are used” message.

Contact Form 7 has deprecated the on_sent_ok hook and now requires an addEventListener for ‘wpcf7mailsent’, as mentioned at the bottom of this page:

Unfortunately, this article does not clearly indicate a convenient way to add the addEventListener.  It is NOT done through the Additional Settings tab, but must have a javascript snippet added with some other mechanism.

We recommend using a custom javascript plugin such as “Simple Custom CSS and JS”.  Once Installed and Activated, add a new JS Code entry.

With the following code:

	document.addEventListener( 'wpcf7mailsent', function( event ) { ga('send', 'event', 'Contact Form', 'submit'); }, false );

In WordPress, it will look like this:


Also note, if you are using Autoptimize – which we highly recommend – you may need to check your JavaScript Options if you do not see the addEventListener in your page source code. (Right-click the page and select View Source.)


0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *