We have many embedded Marketo forms that capture leads across a few sites. Many of these forms are of high importance and we need to have them up at all times if possible.
A week or two ago there was an outage on Marketo's side that caused these forms to not load. I'd like to be able to detect when there are issues like this consistently to load a backup local form in those cases.
I can detect if the MktoForms2 object doesn't exist and respond to that. My concern are all the possible cases where MarketoForms2 is available but the form fails to load for any number of reasons. I looked through the documentation and I'm not seeing any convenient ways to catch form load errors.
Does MktoForms2 give any indication that a form was not able to be successfully loaded and embedded? Aside from setting a timer on page load and checking for the existence of the form I'm coming up blank.
Thank you for the help!
If you’re referring to the request to get the form descriptor failing, yes, you can detect that easily with a capturing error event listener:
document.addEventListener("error",function(e){
if( e.target.tagName == "SCRIPT" ) {
let srcLoc = document.createElement("a");
srcLoc.href = e.target.src;
if( /^\/index\.php\/form\/getForm/.test(srcLoc.pathname) ) {
console.log("Marketo getForm failed");
// take further action
}
}
}, true);
More broadly, you have a Dead Man’s Switch situation, and it’s impossible for code to fully police itself when it might have a bug. For example — not saying this has ever happened to my knowledge w/Marketo, but it for sure happened last week with another forms-related product — if a new JS library isn’t properly tested, it might fetch bad results from its own endpoint, still with an HTTP 200 and valid JSON,and throw an internal error. You can’t know externally that something went wrong, it could even just make the form not submittable but still visible, etc.