Correct Parameter Name to Set a Hidden Form Field Value | Community
Skip to main content
Level 2
March 4, 2015
Question

Correct Parameter Name to Set a Hidden Form Field Value

  • March 4, 2015
  • 4 replies
  • 4768 views

Edit:

Hi All,

Our team is looking to capture javascript cookie information on our landing pages using hidden fields in forms 2.0. The fields we are looking to populate are the standard: Search Engine, Search String (when available), PayPerClick Keyword, UTM_Campaign, UTM_Medium, UTM_Source, UTM_term, AdGroup and Landing Page URL. I've reviewed the help article to "Set a Hidden Form Field Value" (https://community.marketo.com/MarketoArticle?id=kA050000000LH7uCAG) but am having issues finding/entering the correct Parameter Name. I am attempting to pull this information from "Cookie Value" from "Get Value From." I understand the Parameter Name has to map directly to the JS cookie but I don't know what values from the cookies to put them into the hidden fields. I have included bits of the JS cookie below. Thank you for your help.


            
              // The URL parameter that has your pay-per-click info.
              // Typically "kw" or "keyword" (depends on how you set up your PPC URLs)
              var payPerClickParameter = "keyword";
              var utmSourceParameter = "utm_source";
              var utmMediumParameter = "utm_medium";
              var utmCampaignParameter = "utm_campaign";
              var utmTermParameter = "utm_term";
              var adGroupParameter = "AdGroup";
              var landingPageUrlParameter = "LP_URL";
         
  
              // IDs for the fields to be updated. these are the form fields
              var searchStringField = "#SearchString";
              var searchEngineField = "#SearchEngine";
              var payPerClickKeywordField = "#PayPerClickKeyword";
              var utmSourceField = "#UTM_source";
              var utmMediumField = "#UTM_medium";
              var utmCampaignField = "#UTM_campaign";
              var utmTermField = "#UTM_term";
              var adGroupField = "#AdGroup";
              var landingPageUrlField = "#LandingPageURL";
    
  
                // Get the values from the cookies and put them into the hidden fields. this is where it reads the cookies.
            
            // we do this below, I don't think this is necessary
            //$jQ(searchStringField).attr("value", SearchString);
            //$jQ(searchEngineField).attr("value", searchEngine);
            //$jQ(payPerClickKeywordField).attr("value", payPerClickWord);
            //$jQ(utmSourceField).attr("value", utmSource);
            //$jQ(utmMediumField).attr("value", utmMedium);
            //$jQ(utmCampaignField).attr("value", utmCampaign);
            //$jQ(utmTermField).attr("value", utmTerm);
            //$jQ(adGroupField).attr("value", adGroup);
            //$jQ(landingPageUrlField).attr("value", landingPageUrl);
          
            // need to use Marketo forms 2.0 to get the form fields
            
            MktoForms2.whenReady(function(){
              // not sure what form to use, so we'll loop through all forms and set values
              
              var forms = MktoForms2.allForms();
              
              for(var i = 0; i < forms.length; i++) {
                var form = forms[i];
                setFormValuesFromCookie(form, {
                  'SearchString': 'SearchString',
                  'SearchEngine':'SearchEngine',
                  'PayPerClickKeyword': 'PPCKeyword',
                  'UTM_source': 'utm_source',
                  'UTM_medium': 'utm_medium',
                  'UTM_campaign': 'utm_campaign',
                  'UTM_term': 'utm_term',
                  'AdGroup': 'AdGroup',
                  'LandingPageURL': 'LandingPageURL'"
   

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

4 replies

SanfordWhiteman
Level 10
March 4, 2015
That's way too much code to post on this forum (which has no code handling to speak of).

Can you please narrow that down to just the part that is giving you trouble?

And try to rephrase your question.  "I don't know what in the cookie..." doesn't really make sense.  Each cookie is a <name>=<value> pair.  So you want to extract the <name> and map that to  a field on your form.  And you want to set the form field's value to <value>.
Level 2
March 5, 2015
Sorry... I went in and edited the original post based on your feedback...

But  I don't know what <values> from the cookies to put them into the "Parameter Name" in the hidden fields. Is the <name>=<value> equal to search "utmSourceField = '#UTM_source'" or is the <name>=<value> equal to 'UTM_source': 'utm_source'?
SanfordWhiteman
Level 10
March 5, 2015
The cookie "my_simple_cookie=12345" is expressed in a JS object as:
 
{ my_simple_cookie : '12345' }

Note the name is not in quotes.
Guy_Goldstein6
Level 4
May 31, 2015

I've actually run into a very similar challenge recently when trying to extract the data from the infamous utmz cookie (I figured I'd let google do the heavy lifting).

I've done it in PHP/JS before and it's easy enough, but when trying to identify the name of the cookie, there's really no clear guidance as to how to isolate the specific cookie I'm looking for.

So if I wanted the cookie utm_source and I know that it's in the __utmz cookie and that it's value is utmcsr=XXXX

How exactly would you go about instructing the hidden field to pull that specific value?

SanfordWhiteman
Level 10
May 31, 2015

Let's use precise terminology.

__utmz is the cookie name you are seeking.  The cookie value is something like (to give a real-work example from a site I just visited):

     69008525.1433101382.1.1.utmcsr=yahoo|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)

utmcsr, utmccn, etc. are not cookie names.  They are simply strings of characters within the __utmz cookie's value.  There no such thing as a cookie name & value inside a cookie value.  Ever.

However, you may choose to interpret the contents of a consistently structured cookie (like Google's __utmz and Marketo's _mkto_trk) as another series of name-value pairs.

For __utmz, you are understandably led to interpret the string as a pipe-delimited series of equal-sign-delimited names and values: name1=value1|name2=value2|name3=value3

For __mkto_trk, on the other hand, it appears to be an ampersand-delimited series of colon-delimited names and values: name1:value1&name2:value2&name3:value3

Regardless of the formatting rule you assume was used to assemble the cookie (and therefore how you'll parse it to get at individual name-value pairs) the name-values inside a cookie are not themselves cookies.  You can parse them out into a nicely-structured JavaScript object: { name1:"value1",name2:"value2" } that you can play with from the browser, but that's still not a cookie/set of cookies.

I hope now it's becoming clear why Marketo Forms' very cool ability to read data from a cookie into a hidden field does not apply to the arbitrary contents of a cookie. You can set a hidden field to the value of __utmz easily, but you can't set it to parse out a non-cookie value that appears to be embedded within __utmz.