SOLVED

Does anyone know how to pull a User ID into a hidden field?

Go to solution
Anonymous
Not applicable

Does anyone know how to pull a User ID into a hidden field?

Hey Marketo Community! Does anyone know if or how I can pull this user ID into a hidden Marketo field? I've been trying to pull it in based on a cookie but no matter how I configure it it doesn't seem to work!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Does anyone know how to pull a User ID into a hidden field?

Not all of those field values can be fetched from the Tracker object... this kind of "introspection" is not actually supported, AFAIK, it just happens to work for some well-known fields.

The (theoretically) full set of fields available you can see by running:

MktoForms2.whenReady(function(form){

  ga(function(){

    console.log( ga.getByName('gtm1').b.data.keys );

  });

}); 

You can get a field's value using the same syntax as above:

ga.getByName('gtm1').get('flashVersion');

ga.getByName('gtm1').get('screenResolution');

// etc.

Note that adding hidden fields via the Forms 2.0 API + JavaScript is still using hidden fields. The result on the form, and on the Marketo side, is exactly the same as if you added them in Form Editor. The difference is that when adding fields in FE, you get to choose sources like Cookie, Current Query Param, or Referrer Query Param -- but only those sources.  While when you add the field programmatically, you don't get the automatic ability to draw from those common sources (you can simulate it yourself, though) but you do get the ability to draw from any source available in the browser.

View solution in original post

10 REPLIES 10

Re: Does anyone know how to pull a User ID into a hidden field?

I don't know what you're trying (you should add what isn't working for you) but the query param is uid.

Hence:

2017-02-14 14_30_11-Lab #388 - All Widgets - KL and PP.png

Anonymous
Not applicable

Re: Does anyone know how to pull a User ID into a hidden field?

Thanks so much for the response, Sanford! I apologize for being unclear.

Ideally I can start pulling those query parameters into hidden form fields so when a user submits a form I will be able to push that additional data into Marketo. I've tried setting my hidden fields similar to yours above, but unfortunately that doesn't seem to be pulling in the data. Has that worked for you?

Best,

Re: Does anyone know how to pull a User ID into a hidden field?

There's no known bug in this area.

If you post a link to a page with your form, I can tell you quickly if it's working and posting data.

Anonymous
Not applicable

Re: Does anyone know how to pull a User ID into a hidden field?

Wow - thank you very much! I have a test form at the following URL.

powerreviews.com/form-test/

Re: Does anyone know how to pull a User ID into a hidden field?

I went to this URL:

     http:​//www.powerreviews.com/form-test/?uid=fill_this_value

The hidden field is being filled correctly and sent to Marketo (check for the email address teknkl@powerreviews.com😞

2017-02-14 15_19_12-Form Test • PowerReviews - Slimjet.png

So I suspect something is up with your tests.

There are also two JS syntax errors on the page. These aren't causing the problem (they are contained within their own SCRIPT tags) but make troubleshooting more confusing.

Anonymous
Not applicable

Re: Does anyone know how to pull a User ID into a hidden field?

Thanks again for all the help, and sorry if this is an easy question, but what I am looking to do is pull in the UID from the Javascript console. Will that be the same as appending a URL to have the "?uid"? I'm not actually setting a URL to have that parameter, but instead banking off of Google Tag Manager assigning it.

2017-02-14_1322.png

Re: Does anyone know how to pull a User ID into a hidden field?

"From the JavaScript console" isn't what you mean -- you mean "from the GA tracker object."

Which you do like this:

MktoForms2.whenReady(function(form){

  ga(function(){

    form.addHiddenFields({

      GA_User_ID__c : ga.getByName('gtm1').get('userId')

    });

  });

});

Note you don't need the field added to the form (in Form Editor) at all since you're doing it this way.

Anonymous
Not applicable

Re: Does anyone know how to pull a User ID into a hidden field?

I can't thank you enough, Sanford! I have it pulling in the proper information. I had one last question if you have any insights on the matter.

I started pulling additional insights from the Google Cookie and I was wondering if you knew how to add that to my Marketo forms, whether that is through an automated process like the one you shared above, or through hidden fields.

2017-02-15_1602 - Michael_Patterson's library 

Thank you again, so much.

Re: Does anyone know how to pull a User ID into a hidden field?

Not all of those field values can be fetched from the Tracker object... this kind of "introspection" is not actually supported, AFAIK, it just happens to work for some well-known fields.

The (theoretically) full set of fields available you can see by running:

MktoForms2.whenReady(function(form){

  ga(function(){

    console.log( ga.getByName('gtm1').b.data.keys );

  });

}); 

You can get a field's value using the same syntax as above:

ga.getByName('gtm1').get('flashVersion');

ga.getByName('gtm1').get('screenResolution');

// etc.

Note that adding hidden fields via the Forms 2.0 API + JavaScript is still using hidden fields. The result on the form, and on the Marketo side, is exactly the same as if you added them in Form Editor. The difference is that when adding fields in FE, you get to choose sources like Cookie, Current Query Param, or Referrer Query Param -- but only those sources.  While when you add the field programmatically, you don't get the automatic ability to draw from those common sources (you can simulate it yourself, though) but you do get the ability to draw from any source available in the browser.

View solution in original post