If you use the plugin Contact Form 7 on your WordPress website, you may have noticed that recent changes have broken form submissions and event tracking, specifically with the removal of the ability to use “on_sent_ok” in additional settings. Thankfully, we’ve found a solution…
In the past, we leveraged Daniel Carlbom’s process of using “on_sent_ok” in Contact Form 7 to push a Data Layer event for use in Google Tag Manager on successful form submissions. This method worked fine, however the “on_sent_ok” setting has now been depreciated by the makers of Contact Form 7 (see screenshot below). This change means that in order to more accurately measure these goals, we will now needed to find an alternative.
While Contact Form 7 have presented a solution for pushing Google Analytics events by editing your WordPress functions.php file, we needed an easy solution that integrated with Google Tag Manager, and pushed a form submission event to the Data Layer.
The Solution…
If you’re looking for a fast solution that pushes a Data Layer event after a successful form submission, or require a simple way to get your Contact Form 7 event tracking working without editing WordPress files, simply download our CF7 GTM template.
Download the Bonfire Contact Form 7 GTM Template
(right click -> save link as…)
Our method uses a custom HTML script to listen for the wpcf7mailsent DOM event, and then fires an event to the Data Layer when this occurs. We then setup a trigger based on this Data Layer event which is used to track goal conversions in Google Analytics.
We recommend merging the template with your existing container and updating the {{UA Code}} variable to the Google Analytics UA tracking code on your website.
Advanced Tip: If you need the Google Analytics tag to only fire on selected Contact Form 7 forms, simply alter the Contact Form Submit Trigger to fire when the FormID variable equals your required FormID number.