Re: Is there a way to add JS to a Marketo form button?

future_vision
Level 1

Is there a way to add JS to a Marketo form button?

I am looking for a way to add a datalayer push to a Marketo form button. I thought I had seen a way to add code awhile back in design studio but I must have been mistaken. Is there a way to push a datalayer event with the click of the form button?

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Is there a way to add JS to a Marketo form button?

"Adding to the button" isn't the way to think about it. You're adding code that fires upon form success.

 

You can do anything you want in onSuccess:

 

MktoForms2.whenReady(function(readyForm){
  readyForm.onSuccess(function(submittedValues,originalThankYouHref){
    // do whatever you want here, then set
    // document.location.href = originalThankYouHref 
    // when other tasks are done
    return false;
  });
});

 

future_vision
Level 1

Re: Is there a way to add JS to a Marketo form button?

I already have code in place for a datalayer push for the onsuccess event. I guess what I was looking at were clicks regardless of whether the form was submitted successfully or not but I can see just tracking successful clicks the way you described.

Ishita_Chawra
Level 2

Re: Is there a way to add JS to a Marketo form button?

Another discussion on custom form buttons, could be helpful Solved: Custom Form Buttons - Marketing Nation (marketo.com)