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

Anonymous
Not applicable

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

After narrowing down the various factors, the only explanation I have is that calling the getCookies() function before addHiddenFields is breaking something (line 25 below). If I remove that function call, the form submits to Marketo, but does not pick up most of the values for the cookies. I had that function call onSubmit because when the form first loads, the tracking cookies likely haven't been set yet.

var session_utm_campaign, session_utm_source, session_utm_medium, session_utm_content, original_utm_campaign, original_utm_campaign, original_utm_source, original_utm_medium, original_session_datetime, original_session_referrer, utm_campaign_log, utm_source_log, utm_medium_log, utm_content_log;

function getCookies() {

  session_utm_campaign = Cookies.get('session_utm_campaign');

  session_utm_source = Cookies.get('session_utm_source');

  session_utm_medium = Cookies.get('session_utm_medium');

  session_utm_content = Cookies.get('session_utm_content');

  original_utm_campaign = Cookies.get('original_utm_campaign');

  original_utm_source = Cookies.get('original_utm_source');

  original_utm_medium = Cookies.get('original_utm_medium');

  original_utm_content = Cookies.get('original_utm_content');

  original_session_datetime = Cookies.get('original_session_datetime');

  original_session_referrer = Cookies.get('original_session_referrer');

  utm_campaign_log = Cookies.get('utm_campaign_log');

  utm_source_log = Cookies.get('utm_source_log');

  utm_medium_log = Cookies.get('utm_medium_log');

  utm_content_log = Cookies.get('utm_content_log');

}

// then comes the code to set the cookies, not pasted here.

MktoForms2.whenReady(function(form){

  form.onSubmit(function(form) {

  getCookies(); // If I remove this, the form submits to Marketo, but without most of the cookie values set.

  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

  });

  })

});

After another several hours of testing this, I am nearly resigned to the fact that I am just going to have to add these hidden fields in manually in the Form Editor. It worked correctly when I did that, and never in cases when i did not. However, I have not tested thoroughly. Hopefully, hidden fields populated from cookie values in Marketo Forms pull in the values at submission time, not load time, as in my case the cookie will likely not have been set at the time the form loads.

SanfordWhiteman
Level 10 - Community Moderator

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

I had that function call onSubmit because when the form first loads, the tracking cookies likely haven't been set yet.

There's no room for "likely" in JavaScript.  Either [a] the cookies were set synchronously (calls to document.cookie are always synchronous) before the form started to load and thus must exist, or [b] they were set asynchronously (by being wrapped, for some misguided reason, in some async routine) and they must be assumed to not exist until a specific callback is fired. (The fact that they may exist in the second case under some circumstances is irrelevant, as if they can ever not exist, you must code as if they will not exist).

But this is really not the main question.  If you're putting the same data on the wire to the same endpoint, Marketo has no idea what you did beforehand to craft the values. So if that record in the Network tab is the same one you see with a regular post, it must result in the same activity in Marketo. Please post a screenshot of the same post when it does work.

Anonymous
Not applicable

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

That's correct regarding the cookie stuff - I was assuming that they were NOT set by the time the form was constructed. This was because of some previous testing where it seemed like some were not being set in time. Who knows what the actual problem was. This whole situation has been difficult to test.

Anyway, here is the comparison of the two logs - the first one failed, the second one worked. Upon inspection, the differences that i can see (besides the different server I tested on) is the Cache-Control line in the Response Header of the successful one:

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0

And then some cookie values. Any ideas?

example1_failure.jpg

example2_success.jpg

SanfordWhiteman
Level 10 - Community Moderator

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

Also, are you reloading the entire page http://tubemogulnew.staging.wpengine.com/thanks/contact-us/ (and its who-knows-how-many linked assets) in a zero-height IFRAME just to get a Munchkin/GA hit on a /thanks/ page?  Do you know you can log those hits in one line of JS each and save all the crazy overhead?

Anonymous
Not applicable

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

Hah yes, that is a remnant of when another developer hacked together that solution, and from when we were back on HubSpot. I also didn't know how to use GA triggers until recently. It's on my list to make that work the right way.