How To Redirect Contact Form 7 to a Thank You Page

How To Redirect Contact Form 7 to a Thank You Page

Sometimes it’s useful to redirect a Contact Form 7 submission to a Thank You page. Let’s be honest…nothing can provide you with the level of accuracy in tracking as a visited Thank You page as far as Google Analytics and Google Tag Manager is concerned.

After implementing contact forms and publishing a Thank You page you can:

Redirect all forms

This should suffice for most use cases:

  document.addEventListener( 'wpcf7mailsent', function( event ) {
            location = 'https://www.yourdomain.com/thank-you/';
});     

Redirect select form with conditions

This is useful if you have different conversion actions, such as an e-book download and a regular enquiry form.

document.addEventListener( 'wpcf7mailsent', function( event ) {
  if ( '1234' == event.detail.contactFormId ) {
    location = 'https://www.yourdomain.com/thank-you-1/';
  			}
}, false );
  document.addEventListener( 'wpcf7mailsent', function( event ) {
  if ( '1235' == event.detail.contactFormId ) {
    location = 'https://www.yourdomain.com/thank-you-2/';
  			}
}, false );

Change the names with your actual domain and actual contact form ID’s.

Include this into your Theme and add JS script tags.

Leave a Comment