Is there a way to add JS to a Marketo form button? | Community
Skip to main content
Level 3
August 6, 2024
Question

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

  • August 6, 2024
  • 2 replies
  • 2925 views

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?

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
August 6, 2024

"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; }); });

 

Level 3
August 9, 2024

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
August 9, 2024

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

Jasbirka
Level 5
August 13, 2024

I am sharing a link, if it might be helpful.

 

https://support.google.com/tagmanager/answer/7679219?hl=en

SanfordWhiteman
Level 10
August 13, 2024
Problem with this is you'll log an event for people who forgot to fill in a field or in any other way failed to pass validation, in addition to people who successfully submit. Not a very useful event.
Level 3
August 19, 2024

Agreed. It is ultimately useful when comparing clicks on the button vs successful submissions which would clue us in as to whether or not we are doing a good job making sure that it is understood as to what fields are required. If users are clicking and the form is not submitting that could mean we failed. That or there is an error with the form submission. They fill all the fields but somehow we end up blocking a successful submission. Maybe a hidden field we marked as required that they can't fill out. Of course, we should probably catch an issue like this during QA but sometimes things slip by or additional code on the page breaks exiting JS.