Forms 2.0 onSuccess callback appears to fire twice on a form submission | Community
Skip to main content
New Participant
March 20, 2019
Solved

Forms 2.0 onSuccess callback appears to fire twice on a form submission

  • March 20, 2019
  • 1 reply
  • 5745 views

Hi there, I have been adding Google analytics events tracking to our Marketo Forms 2.0 forms. I have noticed the onSuccess callback is triggering two events in analytics with each form submission instead just one. Is there a reason why this function would be executed twice and is there a way to prevent this? Any suggestions or insight....maybe from @Sanford Whiteman would be greatly appreciated. Thanks!

-John

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Maybe I have the wrong idea of MktoForms2.whenReady(function(form) { }); does, it is looking like it might not be needed. I kinda thought it was like jquery's document.ready function.


MktoForms2.whenReady listens for the initial readiness of every form on the page (firing once for every form). It is indeed like DOMContentLoaded for the Marketo forms DOM, and no non-Marketo-emitted event can substitute.

So it's actually critical that you use MktoForms2.whenReady whenever adding events outside the 4th argument to loadForm.

However, in your case, you're inside loadForm, which means with 2 forms on the page, you're duplicating all your whenReady listeners. So because of your current setup, yes, you should remove the extra whenReady wrapper.

1 reply

SanfordWhiteman
New Participant
March 20, 2019

Need your URL.

New Participant
March 20, 2019

Hey Sanford, the url is Packet Pushers | Network Performance Monitoring Built For the Cloud

it appears everything wrapped in the MktoForms2.whenReady(function(form) { }); fires twice but inside the block to call to load the form, MktoForms2.loadForm only fires once.

New Participant
March 20, 2019

Maybe I have the wrong idea of MktoForms2.whenReady(function(form) { }); does, it is looking like it might not be needed. I kinda thought it was like jquery's document.ready function.