SOLVED

What are some examples for when a Cookie Value will be empty when a lead fills out a form?

Go to solution
Danielle_Wong
Level 8 - Community Advisor

We have leads that are not capturing the cookie value. Is this a normal thing? If so, what are some examples of situations when this would happen?

Thank you!

Tags (1)
1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator

I'd be looking for bugs in the code that writes the cookie in the first place.

For example, homegrown code may have a race condition so that on pages with Marketo forms, the cookie may be written either before or after the form is rendered, giving very different results. If your code doesn't understand the Forms 2.0 event model this can easily happen.

View solution in original post

17 REPLIES 17
SanfordWhiteman
Level 10 - Community Moderator

What do you mean by "the" cookie value exactly?

Do you mean a Hidden field that's set to AutoFill from a cookie? There's no case where the cookie provably exists where this is known to fail. Do you have more evidence/audit trail about what you're describing?

Danielle_Wong
Level 8 - Community Advisor

The issue that sparked this question is: we have a hidden field on some of our forms that is supposed to capture the cookie value from our lead tracking code. However, these are coming in as the hidden field's default value "Null".  I'm not sure how to find an audit trail.

SanfordWhiteman
Level 10 - Community Moderator

I'd be looking for bugs in the code that writes the cookie in the first place.

For example, homegrown code may have a race condition so that on pages with Marketo forms, the cookie may be written either before or after the form is rendered, giving very different results. If your code doesn't understand the Forms 2.0 event model this can easily happen.

Danielle_Wong
Level 8 - Community Advisor

I don't have much experience in setting up the code that writes the cookie. I've only ever managed the instances after that set up was completed. I'll have to see how to go about it. Thanks so much Sanford for the help with this.

SanfordWhiteman
Level 10 - Community Moderator

If you point to the page with the code I can give it a look to see if any bugs immediately jump out.

Danielle_Wong
Level 8 - Community Advisor

Awesome, thank you!

Here is the page where our form lives: http://innovate.ieee.org/innovate/contact-us

SanfordWhiteman
Level 10 - Community Moderator

Sure enough, the developer doesn't understand how Marketo Forms work.

This code cannot work predictably:

$(document).ready(function() {

  var a = "ieee.org";

  var c = document.referrer;

  var b = "LT";

  var d = getUrlParameter(b);

  if (typeof d != "undefined" && null != d && d != "") {

    $.cookie("LT", d, { expires: 730, path: "/", domain: a });

  }

});

When you wait for jQuery's ready (this is equivalent to the native event DOMContentLoaded) there's no guarantee that it will run before the Marketo form is finished drawing.

Marketo loads form descriptors (that's the technical name for the setup you manage in Form Editor) and injects HTML elements asynchronously. It doesn't wait for ready before beginning this process.

Therefore, depending on network conditions, caching, and other remote assets loaded by the page, the cookie code might run either before or after the form is ready for use. If it runs after, there are no cookies for the form to see.

This code should run synchronously, i.e. not wrapped in ready.

Danielle_Wong
Level 8 - Community Advisor

Hi Sanford,

Not sure if you have any insight on this.

I noticed this form is not pulling in the LT value from the url. I made sure to clear my cache and when I test it, it doesn't pull in the LT value: Testing1. Any idea why this is happening?

My field is set up like this:

lt.jpg

Thank you

Danielle

SanfordWhiteman
Level 10 - Community Moderator

The page still has the same problem I outlined above. You can't set cookies in jQuery.ready(), because that can fire after the Marketo form is loaded, hence Marketo will not see the cookie when it needs to.

Remember, the Forms 2.0 event model (whenReady, etc.) exists for a reason. You can't use the browser's generic event model to determine when the form is ready.

Danielle_Wong
Level 8 - Community Advisor

Hi Sanford,

Would you mind taking a look at the page again? The developer made an

update to the code. I’m not sure how to ensure it’s working as expected.

Any tips on testing it?

Thanks

Danielle

On Wed, Mar 14, 2018 at 2:20 PM Sanford Whiteman <

SanfordWhiteman
Level 10 - Community Moderator

Looks the same to me -- it still only sets the cookies inside jQuery.ready(), which won't work

Danielle_Wong
Level 8 - Community Advisor

Hmm, that's weird. I don't see the jQuery.ready() on the page. Are you able to clear your cache?

I think the new code has the jQuery.ready removed. But let me know if that's not the case. Thank you so much for the help!!

SanfordWhiteman
Level 10 - Community Moderator

pastedImage_0.png

Danielle_Wong
Level 8 - Community Advisor

Hi Sanford,

Thank you. I will have my web developer take a look at it!

Just so I understand the entire lead tracking process. We should be using "URL parameter" in our hidden lead tracking field? And the cookies code on the page should pull in any cookies if the lead happens to browse other pages before filling out a form?

Thanks

Danielle

Dan_Stevens_
Level 10 - Champion Alumni

Danielle - if you're looking to pull the LT value from the URL you shared, this is a "URL Parameter", not a "Cookie Value".  Have I overlooked the fact that you have also stored this as a cookie value?

Danielle_Wong
Level 8 - Community Advisor

Hi Dan,

Thanks for the reply. I believe we've used cookie value because we want to make sure that if someone browses our website, the lead tracking follows them. It's my understanding that if we use URL, that parameter doesn't follow the user.

We have code that captures the cookie as LT. It's in Sanford's reply above.

Thanks!

Danielle

Danielle_Wong
Level 8 - Community Advisor

I am super appreciative of the time and effort you put into this! This is super helpful and I will work to get this fixed ASAP.