Re: Mysterious behavior - form submissions not registering - what's happening?

Anonymous
Not applicable

Mysterious behavior - form submissions not registering - what's happening?

Ok folks, I am really stumped on this one, as is Marketo Support. I recently tried implementing Gregoire's excellent solution​ to capture UTM values and store them in cookies, awaiting a lead's next form submission, at which time the data will be transferred to the form via hidden fields, and fed into UTM processing campaigns.

I built everything in a way that I thought to be exactly correct. However, something in the code is hijacking the Marketo form submission process. When a person submits a form on one of our pages (which are not hosted on Marketo), occasionally it works perfectly fine - it submits the captured UTM values along with the standard form fields. However, most of the time, Marketo does not register the form submission. From the lead's perspective, they filled out the form, got the subsequent success message, etc. However, in the lead's activity log, there is no record of the form submission. They were using standard browser mode, not incognito. Initially it appeared to be a caching issue - after clearing cache it would work more reliably - but that has ceased to work. Even with a clear cache, no form submission is recorded.

Here is the code that I think must be throwing off Marketo's system:

MktoForms2.whenReady(function(form){

  setTimeout(function(){

  getCookies(); // successfully retrieves all the cookies set with the values utm_campaign_log, original_utm_campaign, etc...

  form.addHiddenFields({

  "latestReferrer": latest_session_referrer,

  "utmCampaignHistoryCapture": utm_campaign_log,

  "utmContentHistoryCapture": utm_content_log,

  "utmMediumHistoryCapture": utm_medium_log,

  "utmSourceHistoryCapture": utm_source_log,

  "originalUTMCampaign": original_utm_campaign,

  "originalUTMContent": original_utm_content,

  "originalUTMMedium": original_utm_medium,

  "originalUTMSource": original_utm_source,

  "originalSessionDatetime": original_session_datetime,

  "originalSessionReferrer": original_session_referrer,

  "utmCampaignCapture": session_utm_campaign,

  "utmContentCapture": session_utm_content,

  "utmMediumCapture": session_utm_medium,

  "utmSourceCapture": session_utm_source

  });

  }, 2000);

  form.onSuccess(function(vals){

  Cookies.remove('utm_campaign_log', { domain: 'tubemogul.com' });

  Cookies.remove('utm_source_log', { domain: 'tubemogul.com' });

  Cookies.remove('utm_medium_log', { domain: 'tubemogul.com' });

  Cookies.remove('utm_content_log', { domain: 'tubemogul.com' });

  console.log("Form submitted. Removed UTM log cookies.");

  });

});

This code first has a setTimeout function so that it makes sure any new cookies have been set before updating the form. Then it retrieves cookies (successfully) and sets hidden form values (successfully) within any form contained on the page. 

Screen Shot 2016-03-15 at 4.24.46 PM.png

When that form is submitted, frequently, Marketo has no memory of it.

mkto_issue.jpg

Do any of you geniuses know what could be causing this frustrating behavior? Am I missing something critical from my MktoForm2.whenReady function? We would be so grateful for any help!

14 REPLIES 14
Grégoire_Miche2
Level 10

Re: Mysterious behavior - form submissions not registering - what's happening?

Hi Ryan,

I am not a Forms 2.0 API specialist, but is there a reason why you would load the cookies at form readiness and not when the form is submitted (in the form.onsubmit)? Furthermore, you would not need any timeout, which, IMHO, does not necessarily guarantee you that you will with the time race...

-Greg

Sanford Whiteman

Anonymous
Not applicable

Re: Mysterious behavior - form submissions not registering - what's happening?

Greg - I can certainly try that - I was attempting to avoid having to manually add the fields to all of our forms that we use. It's a good idea.

However, i can confirm that the form fields were being properly set before submission, at least every time I checked the code, as seen in that screenshot.

Anonymous
Not applicable

Re: Mysterious behavior - form submissions not registering - what's happening?

And I totally misread your comment 😕 I thought you were saying something that I've considered, which is to add the fields through the Design Studio form editor.

Adding it at form submission rather than form load could work, I have not tried it. It seemed like that would run a higher risk of failing to capture some of the fields, though, as there are so many being populated.

SanfordWhiteman
Level 10 - Community Moderator

Re: Mysterious behavior - form submissions not registering - what's happening?

Adding it at form submission rather than form load could work, I have not tried it. It seemed like that would run a higher risk of failing to capture some of the fields, though, as there are so many being populated.

Not at all.  The onSubmit function is guaranteed to complete before the form is submitted.

SanfordWhiteman
Level 10 - Community Moderator

Re: Mysterious behavior - form submissions not registering - what's happening?

This code first has a setTimeout function so that it makes sure any new cookies have been set before updating the form

Set by what process?  Setting cookies is synchronous in the main thread.  Are you expecting cookies to be set by some external asynchronous scripts?  I have to assume there's no actual reason for this setTimeout.  In fact it could break the whole cookie-to-field concept in a corner case.

Anonymous
Not applicable

Re: Mysterious behavior - form submissions not registering - what's happening?

The setTimeout definitely could be unnecessary - I added it in when I was seeing that some of the values were not being retrieved from cookies. The cookies are being set previously in the function via js-cookie, and I was thinking that they were not being set in time for the form to retrieve the values and populate the form. Here is the full javascript file that is being called (Greg deserves most of the credit for this code): https://www.tubemogul.com/wp-content/themes/tubemogul/js/utmcookies.js

I will give both of your suggestions a try - I will remove the setTimeout and apply the behavior to onSubmit rather than on form ready.

Thanks again fellas.

Anonymous
Not applicable

Re: Mysterious behavior - form submissions not registering - what's happening?

By the way, Marketo Support has said that they think this is because we have more than one form embedded on the page, which, as they say "causes shenanigans". I guess that could be the issue, but would be pretty disappointing.

SanfordWhiteman
Level 10 - Community Moderator

Re: Mysterious behavior - form submissions not registering - what's happening?

Don't accept that explanation unless it's proven. Multiple forms can cause validation problems (unless worked around), but if a form's onSuccess is called, that means Marketo responded to a form post.

It's simple to see whether a form ended up going on the wire to Marketo. In your browser's network tab, do you see a POST to the url .../save2?  You may have to click Preserve Log (Chrome) or Persistent Logs (FF) to see it.

Anonymous
Not applicable

Re: Mysterious behavior - form submissions not registering - what's happening?

Ok, as my latest test, I've applied all the recommended Javascript changes, and I've removed the second form from the page. Submitted the form on this page. Got a 200 OK from /save2, and confirmed that all the correct form fields were submitted. The result? No lead record was created for this email address, no campaign activity at all. It's like the form submission never happened.

Screen-Shot-2016-03-17-at-11.58.03-AM.jpg

Screen-Shot-2016-03-17-at-11.58.11-AM.jpg

My next test is to try eliminating the addHiddenFields altogether (so much for my time-saver) and do it in Marketo Design Studio.