14 Replies Latest reply on Mar 17, 2016 6:42 PM by Ryan Baker

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

    Ryan Baker

      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!

        • Re: Mysterious behavior - form submissions not registering - what's happening?
          Grégoire Michel

          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

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

            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.

            1 of 1 people found this helpful
            • Re: Mysterious behavior - form submissions not registering - what's happening?
              Ryan Baker

              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.

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

                  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.

                  1 of 1 people found this helpful
                    • Re: Mysterious behavior - form submissions not registering - what's happening?
                      Ryan Baker

                      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.

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

                          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.

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

                              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.

                              1 of 1 people found this helpful
                                • Re: Mysterious behavior - form submissions not registering - what's happening?
                                  Ryan Baker

                                  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

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

                            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?