Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active May 4, 2017 17:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/4f7ffcc0945e621accbe7c6d082bc978 to your computer and use it in GitHub Desktop.
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.
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;
});
});
@hsquareweb
Copy link

Shouldn't the DOM Events be wpcfmailsent and wpcf7invalid?
https://contactform7.com/dom-events/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment