Skip to main content
Level 2
November 12, 2019
Question

Run code on start and submit with Marketo forms

  • November 12, 2019
  • 2 replies
  • 2559 views

@Sanford Whiteman‌

Hello.  Once a user starts a form and submits I need to run the below code.  How can I do it?

When a user starts the form, run this code:

_satellite.track('form_start', {

      form_type:'[ type of the form ]',

      form_title:'[ document's title (if applicable) ]'

   }

);

When a user successfully submits the form, run this code:

_satellite.track('form_submit', {

      form_type:'[ type of the form ]',

      form_title:'[ document's title (if applicable) ]'

   }

);

Would this work for after successfully submitting the form?

MktoForms2.whenReady(function(form) {  
form.onSuccess(function(values, followUpUrl) {


_satellite.track('form_submit', {
form_type:'gated content',
form_title: '[documents title]'
}
);



return false;
});
}) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I'm not sure how to go about the start piece though.  Any assistance would be appreciated.

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

2 replies

SanfordWhiteman
Level 10
November 12, 2019

Can you highlight all your code using the Syntax Highlighter? Thanks. Then we'll continue.

rocky06Author
Level 2
November 12, 2019

Updated

SanfordWhiteman
Level 10
November 12, 2019

Thanks for fixing that up.

"Start" is a little vague, but interpreting that as the first time anything in the form is focused, capture (literally) that event like this:

MktoForms2.whenReady(function(form){
var formEl = form.getFormElem()[0];

formEl.addEventListener("focus", logFirstFocus, true);

function logFirstFocus(e){
formEl.removeEventListener("focus", logFirstFocus, true);
// your _satellite.track() stuff goes here
}
});‍‍‍‍‍‍‍‍‍‍

For after successful submission, yes, you'd use the built-in onSuccess event.

rocky06Author
Level 2
November 12, 2019

Thanks Sanford.