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!
Solved! Go to Solution.
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.
I don't know what you're trying (you should add what isn't working for you) but the query param is uid.
Hence:
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,
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.
Wow - thank you very much! I have a test form at the following URL.
powerreviews.com/form-test/
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😞
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.
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.
"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.
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.
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.