hsquareweb
10/31/2016 - 9:53 PM

Setup Google Tag manager for Contact Form 7. Focus fields when an error occurs.

Setup Google Tag manager for Contact Form 7. Focus fields when an error occurs.

jQuery(document).ready(function($) {
    $(".wpcf7").on('wpcf7:mailsent', function() {
        window.dataLayer = window.dataLayer || [];
        window.dataLayer.push({
            'event': 'formSubmitSuccess',
            'formId': 'contactForm'
        });
    }).on('wpcf7:invalid', function() {
        // focus errors on contact form
        window.location.hash = $('.wpcf7-not-valid').get(0).id;
    });
});