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?
"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;
});
});
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.
Another discussion on custom form buttons, could be helpful Solved: Custom Form Buttons - Marketing Nation (marketo.com)
Wouldn't really apply, though (that thread is about custom styling, this is about JS code).