Pushing Yext Form Data into Marketo

kenmckown
Level 4

We have a Yext form on an external site, and are trying to push that data into Marketo. We built out a JS file to push the data, but it doesn't seem to be working and wondering what we are missing.

Here is the code snippet:

<script src="//app-ab07.marketo.com/js/forms2/js/forms2.min.js"></script>
<script>
// Capture form submission
document.querySelector('#yext-form').addEventListener('submit', function(e) {
    e.preventDefault();
    // Get form data
    var formData = new FormData(this);
    // POST to Marketo first (using Marketo Forms 2.0 API)
    MktoForms2.loadForm("//app-ab43.marketo.com", "180-DGD-014", 4811);
    MktoForms2.whenReady(function(form) {
        form.setValues({
            'Email': formData.get('email'),
            'Company': formData.get('businessName'),
			'Address': formData.get('address'),
			'Country': formData.get('country'),
			'City': formData.get('city'),
			'State': formData.get('state'),
			'ZIP': formData.get('postalCode'),
			'Phone': formData.get('phone'),
            // map other fields
        });
        form.submit();
    });
    // Then POST to Yext (original destination)
    this.submit();
});
</script>
Tags (2)
6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

@kenmckown please return and check replies.

SanfordWhiteman
Level 10 - Community Moderator

This code

 

  1. makes the assumption a Yext form uses the standard DOM submit event to submit (that’s the only reason e.preventDefault() would do anything); is there evidence this would actually short-circuit the Yext form submit?
  2. also just proceeds to submit the form programmatically without waiting for anything (e.preventDefault() followed immediately by form.submit() is the same as just letting the form submit as usual)
  3. unnecessarily loads the Marketo form after the Yext form (it should be loaded and ready before the Yext form submits)
  4. repeats itself a lot (you should have a map of Yext field ⮕ Marketo field and iterate over that instead of inlining formData.get() over and over)

The main points are (1) and (2). Without any proof you’re stopping the submit, all will be for naught. 

kenmckown
Level 4

This is our first time doing this, so this was a code we generated. Is there an easier way to accomplish this through Yext? We just want to push the data from that form into Marketo so we can capture and store it into existing Marketo fields.

SanfordWhiteman
Level 10 - Community Moderator

OK, guess that explains why the code makes no sense! Please understand it’s like asking someone to proofread a block of random words and very frustrating. Without a real developer involved, such tools are just creating more work.

 

Impossible to help further without a link to your form.

kenmckown
Level 4

Sorry about that, as I said this is a first for us.

This is the page the form exists on the external site:

https://autoshopsolutions.com/listing-scanner/

The for I built in Marketo is set to accept the data, I tossed it on a test page here:

https://go.autoshopsolutions.com/test-VLO---2025_WebinarTemplate-Clone.html 

SanfordWhiteman
Level 10 - Community Moderator

OK. That’s not just a Yext form, it’s an entire Yext landing page on www.optimizelocation.com that’s been IFRAMEd into your site. 

 

Are you able to add custom JS to that IFRAMEd LP? (For obvious security reasons, you can’t simply detect behavior on a cross-origin IFRAME. You must also have control of the IFRAMEd page to send events to the parent document, e.g. to send a Marketo form with data from the Yext form.)