Issues Reading cookies on First Page Load? | Community
Skip to main content
November 17, 2017
Solved

Issues Reading cookies on First Page Load?

  • November 17, 2017
  • 2 replies
  • 7148 views

I have a script that parses my URL and writes parameters to cookies. I can see this functioning with proper cookies being set.

However, when I submit my form the cookies don't appear to be read. All applicable fields are blank or at defaults.

If I go back and resubmit the form, the cookies are read and submit through.

Ideas?

Thanks,

Ben Brooks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

That needs to be fixed, as the form can render before or after the DOM is ready (DOMContentLoaded).  Very important to listen for Forms API events, not built-in DOM events.  If simply using GTM tags independent of each other, you'll always have a race condition (since the script-injected scripts are all asynchronous). You have to interlink these somehow, either by running MktoForms2.loadForm after setting cookies or by re-reading the values at form.whenReady() and running addHiddenFields.

2 replies

SanfordWhiteman
New Participant
November 17, 2017

Thanks Josh -- yes, Ben, you need to provide a URL.

Setting cookies is a synchronous operation, but if for some reason you kick off your code after the Marketo form is rendered, the form can't pick up the cookie values.

November 21, 2017

Interesting. My cookie setting code in GTM fires on dom.ready and it usually takes longer for the form to load, but that could be an issue.

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
November 21, 2017

That needs to be fixed, as the form can render before or after the DOM is ready (DOMContentLoaded).  Very important to listen for Forms API events, not built-in DOM events.  If simply using GTM tags independent of each other, you'll always have a race condition (since the script-injected scripts are all asynchronous). You have to interlink these somehow, either by running MktoForms2.loadForm after setting cookies or by re-reading the values at form.whenReady() and running addHiddenFields.

Josh_Hill13
New Participant
November 17, 2017

Need code or url.

@Sanford Whiteman​

November 21, 2017

Good call:

info.nintex.com/cnt_corp_buyers_guide_0717_lp_o365_bdm.html

info.nintex.com/cnt_corp_demystifying_workflow_ebook_0717_lp_o365_bdm.html