Can’t get custom DOM events to work?
-
I feel like I’ve tried everything!
I’m using the tutorials outlined here:
https://contactform7.com/dom-events/
https://contactform7.com/tracking-form-submissions-with-google-analytics/
https://contactform7.com/redirecting-to-another-url-after-submissions/I’ve tried hooking into wp-head and using the header code integration that comes with my theme. There are no errors in the console and I’m seeing that the code is, in fact, in the head of the page.
Here’s the code I’m trying to insert:
<script> var formStandard = document.querySelector( '#cf7-custom-container' ); formStandard.addEventListener( 'wpcf7submit', function( event ) { ga('send', 'event', 'Contact Form', 'submit', 'Standard Form Submit'); location = '/thank-you'; }, false ); </script>
Where #cf7-custom-container is a div surrounding my form.
I’ve even tried using just the very basic implementation of the page redirect, which is basically just copy and pasted from the docs:
<script> document.addEventListener( 'wpcf7mailsent', function( event ) { location = '/thank-you'; }, false ); </script>
I’m not getting any errors or anything, it’s simply not working. Any ideas?
- The topic ‘Can’t get custom DOM events to work?’ is closed to new replies.