CMS Development

Jools619
Participant

Form validation message to trigger a GTM event?

Hi

 

We have a Hubspot powered Request form on our site that requires the user to input a work email addres and not a personal one. 

 

If a personal email address is entered an error validation message occurs via the forbiddenEmilDomain translation.

 

So my question is how can I trigger a GTM event when this validation erorr message is shown?

 

I dont have much knowledge with GTM so any information much appreciated.

 

Thanks

Jools

0 Upvotes
3 Replies 3
Anonymous
Not applicable

Form validation message to trigger a GTM event?

You should be able to have it fire only on successful submission ~ something along these lines should do the trick:

 

<script type="text/javascript">
  window.addEventListener("message", function(event) {
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted' && event.data.id === "FORM-ID-NUMBER-GOES-HERE") {
      window.dataLayer.push({
        'event': 'hubspot-form-success',
        'hs-form-guid': event.data.id
      });
    }
  });
</script>
Jools619
Participant

Form validation message to trigger a GTM event?

Thanks for the this.

 

But we really need it to fire when that validation message appears as we want to see how many users are dropping out of the journey because of having to enter a work email instead of a personal email address.

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Form validation message to trigger a GTM event?

@Bryantworks , do you have a solution for this?

0 Upvotes