Last active
May 4, 2017 17:40
-
-
Save james2doyle/4f7ffcc0945e621accbe7c6d082bc978 to your computer and use it in GitHub Desktop.
Setup Google Tag manager for Contact Form 7. Focus fields when an error occurs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't the DOM Events be wpcfmailsent and wpcf7invalid?
https://contactform7.com/dom-events/