SOLVED

Foms duplicating / not submitting on Marketo landing page

Go to solution
dakotaratcliffe
Level 1

Foms duplicating / not submitting on Marketo landing page

We just launched a new site, but didn't change anything in Marketo. Now forms are duplicating and not submitting on our landing pages. Any insight as to why would be appreciated.

 

Landing page: https://go.glia.com/02-2025-AMS-Webinar_Q2_Product_Update_Marketing-Activities---Test.html

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Foms duplicating / not submitting on Marketo landing page

The situation is much worse than you think.

 

In fact, your forms don’t load at all whenever GTM loads before the forms library (which will randomly happen depending on network conditions).

 

This is because you have some — I must say — atrociously buggy custom JS being injected via GTM:

<script>
window.dataLayer = window.dataLayer || [];
var origin_open = XMLHttpRequest.prototype.open
  , origin_send = XMLHttpRequest.prototype.send
  , form_data = "";
XMLHttpRequest.prototype.send = function(a) {
    form_data = Object.fromEntries(a);
    origin_send.apply(this, arguments)
}
;
XMLHttpRequest.prototype.open = function(a, b) {
    b.includes("admin-ajax.php") && (this.addEventListener("loadend", function(c) {
        var d = ["form_id", "form_fields"];
        if (JSON.parse(c.currentTarget.response).success) {
            for (key in form_data)
                d.some(function(e) {
                    return key.startsWith(e)
                }) || delete form_data[key],
                form_data[key] || delete form_data[key];
            dataLayer.push({
                event: "generate_lead",
                form_data: form_data
            })
        }
    }),
    origin_open.apply(this, arguments))
};
</script>

 

Remove that JS immediately. It has a giant bug in assuming an XHR payload will be an iterable. How would that ever work with a GET?

 

Yes, sometimes you need to override XMLHttpRequest.prototype for instrumentation & analytics, but you simply cannot embark on this without experience.

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Foms duplicating / not submitting on Marketo landing page

The situation is much worse than you think.

 

In fact, your forms don’t load at all whenever GTM loads before the forms library (which will randomly happen depending on network conditions).

 

This is because you have some — I must say — atrociously buggy custom JS being injected via GTM:

<script>
window.dataLayer = window.dataLayer || [];
var origin_open = XMLHttpRequest.prototype.open
  , origin_send = XMLHttpRequest.prototype.send
  , form_data = "";
XMLHttpRequest.prototype.send = function(a) {
    form_data = Object.fromEntries(a);
    origin_send.apply(this, arguments)
}
;
XMLHttpRequest.prototype.open = function(a, b) {
    b.includes("admin-ajax.php") && (this.addEventListener("loadend", function(c) {
        var d = ["form_id", "form_fields"];
        if (JSON.parse(c.currentTarget.response).success) {
            for (key in form_data)
                d.some(function(e) {
                    return key.startsWith(e)
                }) || delete form_data[key],
                form_data[key] || delete form_data[key];
            dataLayer.push({
                event: "generate_lead",
                form_data: form_data
            })
        }
    }),
    origin_open.apply(this, arguments))
};
</script>

 

Remove that JS immediately. It has a giant bug in assuming an XHR payload will be an iterable. How would that ever work with a GET?

 

Yes, sometimes you need to override XMLHttpRequest.prototype for instrumentation & analytics, but you simply cannot embark on this without experience.

dakotaratcliffe
Level 1

Re: Foms duplicating / not submitting on Marketo landing page

Appreciate it. We just inherited this project and don't know what all was going on in there previously. Will take a look at your recommended fix! 

SanfordWhiteman
Level 10 - Community Moderator

Re: Foms duplicating / not submitting on Marketo landing page

I notice the bad code is still there. Are you having trouble finding it in GTM? Because it's kinda bad to have your forms not show up for some people when the fix is that easy!

dakotaratcliffe
Level 1

Re: Foms duplicating / not submitting on Marketo landing page

Wanted to confirm this did end up being the fix. Appreciate the assistance!