Skip to main content
Solved

'klayvioForms' event not being fired on form submission

  • February 19, 2025
  • 2 replies
  • 15 views

Forum|alt.badge.img

Hello. I’m attempting to submit an event to our mixpanel dashboard when a user submits their email address to a signup form. I have this code snippet before the closing </body>

<script>
  window.addEventListener("klaviyoForms", function(e) {
        if (e.detail.type == 'submit') {
          let formLocation = 'Popup';
          if (e.detail.formId === '<FORM_ID>' || e.detail.formId === '<OTHER_FORM_ID>') {
            formLocation = 'Footer;
          };
          mixpanel.track('Email List Signup', {
            'Form location': formLocation,
            'User email': e.detail.metaData.$email 
          });
        };
    });
</script>

I added a console log statement in there as well but was not seeing it get hit when I submit either of the forms. It’s like the listener for `klaviyoForms` is failing. Any help here would be great, 

 

Thank you

Best answer by retention

Hi ​@GraysonNull, welcome to the community.

So fi you’re catching Klaviyo Form Submit events, I assume you’ve seen the documentation about it here:

The code you have looks OK to me, but you may want to simplify it to match the example in the guide and work backwards from there.  Maybe the additional code has errors or syntax issues.

Additionally, make sure the code is loaded after the Klaviyo.js is loaded so that there isn’t some kind of order of operation or race conditioning that’s keeping the listener from registering properly.   

View original

2 replies

retention
Partner - Platinum
Forum|alt.badge.img+62
  • 2025 Champion
  • 944 replies
  • Answer
  • February 19, 2025

Hi ​@GraysonNull, welcome to the community.

So fi you’re catching Klaviyo Form Submit events, I assume you’ve seen the documentation about it here:

The code you have looks OK to me, but you may want to simplify it to match the example in the guide and work backwards from there.  Maybe the additional code has errors or syntax issues.

Additionally, make sure the code is loaded after the Klaviyo.js is loaded so that there isn’t some kind of order of operation or race conditioning that’s keeping the listener from registering properly.   


Forum|alt.badge.img
  • Author
  • Contributor I
  • 1 reply
  • February 19, 2025

Thank you for the quick reply. Turns out there was a missing quote in my code. It was written directly in a textarea in my Webflow site settings which does no validation. All is working as expected now. 

 

Thanks!