How to Track WPForms Form Submissions with Google Analytics

0
107
How to Track WPForms Form Submissions with Google Analytics
How to Track WPForms Form Submissions with Google Analytics?

WPForms is my favourite form builder plugin for WordPress. I like its user interface and functionality. You can use WPForms and collect data from your website visitors with great ease.

To measure the effectiveness of your digital marketing campaigns, you would also want to track these form submissions with an analytics tool. The most commonly used tool is Google Analytics. In this article, I’ll show you how to track WPForms form submissions with Google Analytics if you redirect the user to a “Thank You Page” after the form has been submitted successfully.

The internet is full of tutorials that teach you form submission tracking with Google Analytics. To track a form, we normally use Google Tag Manager these days using which we send an event to Google Analytics when either the “Submit” button of the form is clicked or when the user is navigated to a “Thank You Page” after successfully submitting the form.

This can be accomplished even without Google Tag Manager. You simply create a Goal inside Google Analytics based on a destination page (the Thank You Page).

However, I am not a fan of both of the above implementations.

Problem With Tracking “Submit” Button Clicks

Clicking the Submit button does not necessarily mean that the form was successfully submitted. What if the user did not enter anything in a mandatory field, or if the user entered an invalid email address in the email field of the form? Clicking the Submit button would display the validation error(s), the user would correct the errors and then click the Submit button again. If you track Submit button clicks to track conversions in Google Analytics, your conversion data would be inaccurate. In our example scenario, Google Analytics would show two conversions while the form was successfully submitted only once.

Problem With Tracking “Thank You Page” Views

If you track “Thank You Page” views to track form submissions using Google Analytics, data might be inaccurate again. There is nothing stopping anybody to copy the URL of the thank you page in the address bar of the browser and open that page. I know, there is a very less chance of somebody actually doing it, but, you never know. The approach that you undertake to track WPForms form submissions with Google Analytics must be foolproof.

How to Track WPForms Form Submissions With Google Analytics The Right Way?

In order to track WPForms form submissions with Google Analytics, we’ll make use of wpforms_process_complete action which fires at the end of a successful form entry processing. You can read more about it here:

https://developers.wpforms.com/docs/action-wpforms_process_complete/

In our theme’s functions.php file, we’ll create a function and hook that on to the wpforms_process_complete action. Effectively, this function would execute each time your form is successfully submitted.

Inside this function, we’ll make use of the Google Analytics Measurement Protocol to send an event directly to Google Analytics servers. Don’t worry if you are not a programmer. You do not need to write the code yourself. I’ve given the code snippet below. If you encounter any problem while implementing this, get in touch with me. I’ll help you do it.

function ga_track_event_form_submission_function_name( $fields, $entry, $form_data, $entry_id ) {
  $endpoint = 'https://ssl.google-analytics.com/collect?';
  $payload_data = array(
    'v' => 1,
    'tid' => 'UA-XXXXXX-1',
    'cid' => 123,
    't' => 'event',
    'ec' => 'Forms',
    'ea' => 'Successful Submission',
    'el' => 'Contact Us'
    );
    $parameters = http_build_query( $payload_data );
    wp_remote_post( $endpoint . $parameters );
}
add_action( 'wpforms_process_complete_1634', 'ga_track_event_form_submission_function_name', 10, 4 );

Please note that you need to replace UA-XXXXXX-1 with your Google Analytics Tracking ID. In the above code snippet, 123 is a random User ID. For a detailed explanation of all the parameters that Measurement Protocol uses, please refer to the Measurement Protocol Parameter Reference.

Also note that I have used an alternate version of the wpforms_process_complete action. The number 1634 in wpforms_process_complete_1634 specified in the code snippet above is the Form ID. Therefore, if you have multiple forms in your website, it would be easy to implement different code snippets for different forms.

This way, we have removed dependence on the “Submit” button as well as the “Thank You Page”. The conversion data recorded in Google Analytics would be absolutely accurate. What do you think of this approach? Please let me know in the comments section below.

How to Track WPForms Form Submissions with Google Analytics
5 (100%) 3 vote[s]

LEAVE A REPLY

Please enter your comment
Please enter your name