Auto populate form from Marketo cookie and auto submitting the form

Highlighted
Anonymous
Not applicable

Auto populate form from Marketo cookie and auto submitting the form

Hi,

we want a way to track a lead who clicks on a PDF link from a mail that is not sent out via Marketo. We also do not wish to Gate the PDF file (Require our clients to fill in a form) to access the file. After talking to support and scouring the Marketo fourms and support sites, I understood (I think) the only way to achieve this is to make a REST API call and try and get the lead information from the cookie file on their PC (People who will access our PDF's are known clients and not the general public) I am no expert coder, so I patched up this code from my research, suffice to say it is not working and any help will be appreciated.

<script src="//xxx.marketo.com/js/forms2/js/forms2.min.js"></script>

<form id="mktoForm_2244" style="display:none"></form>

<script>MktoForms2.loadForm("//xxx.marketo.com", "xxx-xxx-xxx", 2244);</script>

<script>

MktoForms2.whenReady(function(form) {

  //OnSuccess is optional - only if you need to make client-side decisions about Thank You URL

  form.onSuccess(function(vals, tyURL) {

    location.href = 'http://www.1234.com/rs/xxx-xxx-123/images/somepdffile.pdf'; 

    return false;

  });

     //Get LEAD info from cookie

     var mktoGet = new XMLHttpRequest();

     mktoGet.open("GET", "https://xxx-xxx-xxx.mktorest.com/rest/v1/leads.json?filterType=cookie&filterValues=<cookie>&fields=email,firstName,lastName&access_token=<token>", false);

     mktoGet.send();

    //set the first result as local variable

    var mktoLeadFields = mktoLead.result[0];

    //map your results from REST call to the corresponding field name on the form

    var prefillFields = {

            "Email" : mktoLeadFields.email,

            "FirstName" : mktoLeadFields.firstName,

            "LastName" : mktoLeadFields.lastName

            };

    //pass our prefillFields objects into the form.vals method to fill our fields

    form.vals(prefillFields);

    });

  //Submit the form

  form.submit();

});

</script>

p.s. I replaced the <cookie> and <token> values and once I paste the link in the browser I get a sucess result.

13 REPLIES 13
Highlighted
Level 10 - Community Moderator

Re: Auto populate form from Marketo cookie and auto submitting the form

Don't do this, period.

For the love of all that is secure, never call the REST API from the browser. Do you really want the whole world to able to read your entire database?

But also: don't use the REST API in response to individual end-user actions, even if you gateway the REST API call via your own server. This is a Denial of Service vulnerability for the record books.

Highlighted
Anonymous
Not applicable

Re: Auto populate form from Marketo cookie and auto submitting the form

So bottom line, theres simply no way to achieve this?

Highlighted
Level 10 - Community Moderator

Re: Auto populate form from Marketo cookie and auto submitting the form

So bottom line, theres simply no way to achieve this?

I didn't say that.

But it's critical that no one looks at your first take and tries to do it that way.

There's something not entirely clear from your description: if these people already have an associated cookie, then why not use the Known Lead HTML feature ("If Known Lead, show Custom HTML")?  That's specifically designed to let already-associated sessions bypass the form and get to the download link. When they click the download link, a Filled Out Form activity is logged. There's no reason to populate a form with data that's already known on the server.

Highlighted
Anonymous
Not applicable

Re: Auto populate form from Marketo cookie and auto submitting the form

The clients are getting a link via personal Email and not through a Marketo email, to a PDF file hosted on Marketo servers, I have attemped to select the Known Lead HTML feature, but the Leads are not being 'Known' and I cannot track via SmartList e.g. Visits website (with or without QueryString), Also not being detected by smart campaign via trigger 'Filled out form' or any trigger for the matter, Leads are not even appearing in the activity log...

Highlighted
Anonymous
Not applicable

Re: Auto populate form from Marketo cookie and auto submitting the form

TO Clarify Further, I am only using a form as a means to capture the Lead information by auto submitting it, ideally people receiving the link should click the link and get the PDF file directly without filling in any forms....

Highlighted
Level 10 - Community Moderator

Re: Auto populate form from Marketo cookie and auto submitting the form

I am only using a form as a means to capture the Lead information by auto submitting it, ideally people receiving the link should click the link and get the PDF file directly without filling in any forms....

Right, a redirector page sends them to the asset automatically after the necessary tracking + association steps are done.

Highlighted
Level 10 - Community Moderator

Re: Auto populate form from Marketo cookie and auto submitting the form

If they're not known, then looking them up by the cookie wouldn't get you anything, either! The prerequisite for looking up by cookie is that the cookie is associated with a known lead. In other words, Known Lead HTML and the don't-use-it API method serve the same purpose here, and neither of them are usable.

"[G]et the lead information from the cookie file on their PC" only makes sense if they've already been identified on that machine, either via

  • a previous, Marketo-originated email link; or
  • a previous form fillout; or
  • a deliberate call to one of the associateLead APIs (client or server)

If you want to use the latter method with a non-Marketo send, this blog post is a must-read in preparation.

Highlighted
Anonymous
Not applicable

Re: Auto populate form from Marketo cookie and auto submitting the form

The clients are known to Marketo as in they are existing Leads in the database. But for this specific purpose they will be getting the link from a private email via the sales person and not via Marketo. So the people getting the link will have the cookie on their computer for sure and definetly would have been identified on that machine previously via the methods you mentioned.

I will Read the post you suggested and wish to thank you for taking the time to review my problem and giving feedback.

Highlighted
Level 10 - Community Moderator

Re: Auto populate form from Marketo cookie and auto submitting the form

So the people getting the link will have the cookie on their computer for sure and definetly would have been identified on that machine previously via the methods you mentioned.

If that's so, then Known Lead HTML will work.

Whether the person is simply known within Marketo doesn't matter for the purposes of Known Lead HTML, or any cookie-based logic.  What matters is whether their current web session is associated with that lead.

Perhaps you're overconfident about the frequency of people using the same device + browser on which they were already associated? Because if they're associated in that browser, that's all you need to let them skip the form. (I personally wouldn't make that assumption, since we're in a multi-device world.)