Cookie hidden fields don't work if custom html is used for known visitors | Community
Skip to main content
Nick_Deboo1
Level 2
March 14, 2018
Question

Cookie hidden fields don't work if custom html is used for known visitors

  • March 14, 2018
  • 3 replies
  • 6753 views

Hi

I have lot of embedded forms on non-Marketo pages and I would like to make it easier for the visitor to e.g. fill in a webinar forms or ebook download forms.

Idea 1: pre-fill known fields

This doesn't work as the pre-fill unfortunately doesn't work with embedded forms on non-Marketo pages.

Idea 2: "If Known Visitor, Show:" custom html

This does work with embedded forms but the problem is that hidden fields don't take my cookie values.

Anyone other ideas? Transferring the content to Marketo landing pages is a no

3 replies

Grégoire_Miche2
Level 10
March 14, 2018

Hi Nick,

Log ideas rather than questions . People can vote and they are reviewed by Product Management.

Idea 1: pre-fill known fields

There are a lot of discussions and ideas already in the community on this. To make it short, there are good data security reasons for not doing this as someone could use your JS code to steal your data.

Idea 2: "If Known Visitor, Show:" custom html

Worth and idea so that we can vote for. Can be worked around with javascript, though.

-Greg

SanfordWhiteman
Level 10
March 14, 2018

Nick, you can reenable cookie (and query param) support via the code here: MktoForms2 :: KL HTML w/Auto-Fill

Note the dependency on the FormsPlus::Util (the <script> in the HTML pane).

Once you have that set, the only part you need to change is this little JSON block:

   var hiddenFieldMap = {

      Last_Result__c: {

         channel: "query",

         selector: "utm_results"

      },

      Field_From_Cookie: {

         channel: "cookie",

         selector: "ahoy_visitor"

      },

      Another_Field_From_Constant: {

         channel: "constant",

         selector: "Always use this value."

      }

   };

Hopefully, this is nearly self-explanatory...

  • the top-level properties (Last_Result__c, etc.) are the Marketo form field names
  • you set the channel (this is the term used by the Forms 2.0 API, so I reused it here) to either "query", "cookie", or "constant"
  • set the selector to the specific place to pluck the value from (the name of the cookie or query param to look for, or a static string in the case of "constant")
Boone_White1
Level 2
March 29, 2018

I am actually having this cookie issue with my non-embedded forms. Basically not getting query parameter support when the "If Known Visitor, Show:" custom html is in use.

Will the JSON script above also reenable this data for me? If so where should I place that script?

Thank you so much for your help!

Boone White

SanfordWhiteman
Level 10
March 29, 2018

Sure, Boone, you can use the same JS with any Marketo form, whether on a Marketo LP or on another site.

On a Marketo LP, you would include the formsplus-util.js <script>, then the custom JS in another <script>, right before the closing </body> tag.

Craig_Boren
Level 2
June 27, 2019

Sanford Whiteman‌ - This is awesome! Thank you for this script. It worked perfectly!

One question - is there a way to set default utm_params with this script? For example, in the event that a return visitor comes to a page with Custom HTML set, and there are no utm parameters defined in the URL, we still want to attribute their visit with some type default utm params.

SanfordWhiteman
Level 10
June 27, 2019

Sure, will update later when I'm by my machine.