SOLVED

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

Go to solution
John_Wallace
Level 4

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

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

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

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

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.

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

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

Need your URL.

John_Wallace
Level 4

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

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.

John_Wallace
Level 4

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

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.

SanfordWhiteman
Level 10 - Community Moderator

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

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.

John_Wallace
Level 4

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

Great thank you for your help and clarifying MktoForms2.whenReady ​!

I seem to have a hard time finding all the documentation pertaining to forms 2.0