@creativekindle
So add this script as a custom HTML tag in GTM:
<script>
var wpcf7Elm = document.querySelector( '.wpcf7' );
wpcf7Elm.addEventListener( 'wpcf7mailsent', function( event ) {
dataLayer.push({'event' : 'formSubmitted'});
}, false );
</script>
Then create a tag (whichever type you’re after) that is triggered by the custom event ‘formSubmitted’.
If you have multiple forms then you can use a custom JS variable that identifies the form and then use it as a rule in the trigger too.
function() {
var nav = jQuery({{Click Element}}).closest('form').attr('action');
if (nav.includes("#wpcf7-INSERT FORM ACTION-o") == true) {
return 'Contact Form';
}
else if (nav.includes("#wpcf7-INSERT FORM ACTION-o") == true) {
return 'Newsletter Sign Up';
}
else{
return 'unknown form';
}
}
You can find the form ID by inspecting element on the form and finding the form action value. You just need to include the part that’s between ‘#wpcf7-‘ and ‘-o’. Note, if multiple forms are on the page, the action value will end with o1, o2, o3 etc. In the code above I’ve omitted the number at the end in case it changes depending on the page that the user is on.
I found that the latest version of the CF7 plugin (4.7) has to be in place, it won’t on older versions.
Hope this helps.
-
This reply was modified 8 years ago by
gravy834.