How To Use Contact Form 7 DOM Events With Google Analytics Goals
I have been using Contact Form 7 for years and it really is a great plugin, I wrote a contact form 7 getting started guide if you are new to it. When I logged into WordPress to change some text on the form fields I noticed a configuration error in the Additional Fields column in CF7.
Using DOM Events For Google Analytics Events and Goals
Download the Header and Footer Scripts plugin if you do not already have a scripts inserter or install one through the WordPress dashboard.
When sending events to google analytics you need to use the same variables you used in the Additional Settings tab in CF7 which looked something like this:
on_sent_ok: "ga('send', 'event', 'eventCategory', 'eventAction', 'eventLabel');"
You need the line of code inside the quotation marks without the deprecated on_sent_ok.
Insert New DOM Event Code
Insert this code before the closing </body> tag.
You should change the eventCategory, eventAction and eventLabel to values that work for you.
Content Writing Service
Discover the exclusive service from Nicebrains. Order written content for your website, e-books, product pages, reviews, educational content and more.Learn More
Please Note: you can use any of the other DOM Events in place of wpcf7submit. Here is a list of what you can use and their meanings:
wpcf7invalid— Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because there are fields with invalid input.
wpcf7spam— Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because a possible spam activity has been detected.
wpcf7mailsent— Fires when an Ajax form submission has completed successfully, and mail has been sent.
wpcf7mailfailed— Fires when an Ajax form submission has completed successfully, but it has failed in sending mail.
wpcf7submit— Fires when an Ajax form submission has completed successfully, regardless of other incidents.
Setup Your Goal In Google Analytics – I have written a quick guide on how to do this here.
Tracking contact form submissions in Google Analytics is one of the best ways of identifying which sources of traffic are netting you the most enquiries or leads. Along with tracking conversions you should be tracking email link clicks on your pages and monitoring how your pages are performing in terms of speed to increase website conversions.
The solution outlined above will keep Contact Form 7 working smoothly and firing events to Google Analytics.