AnsweredAssumed Answered

Will our custom prefill code on non-Marketo pages stop working with Marketo's new changes to how prefill works?

Question asked by Gary S on Apr 11, 2019
Latest reply on Apr 29, 2019 by Ravindranathsarma Bollapinni

We had a company do a custom implementation to make Marketo forms embedded onto our website (i.e. not on marketo landing pages), have their fields prefill if the Marketo cookie info exists.  On my first read through of Marketo's announcement that they are changing how it will work , I'm pretty sure our custom work will stop working and prefill will no longer happen (which stinks), but I'm trying to confirm it one way or the other.

 

I'm hoping someone can read through the info below and confirm 100% either way whether our implementation will stop working.  It may not be enough information but hopefully it is...

 

The company who did the work said they would do it this way:

 

Suggested solution:

  • Include an endpoint that reroutes REST calls to the Marketo API, keeping the ClientId and ClientSecret hidden from the client-side
  • Finish the implementation from the client-side as per the documentation, but instead making the REST call to the local server instead of the Marketo one, e.g.: www.example.com/services/marketo_leads.ashx?filterType=cookie&filterValues=<cookie>&fields=email,firstName,lastName,company (the &access_token=<token> is appended on the server side)

 

And the "documentation" they referred to is this below:

 

ISSUE:  Marketo Form Fields on our site are not prefilling with users info.  When someone submits a Marketo form and later returns to another page with a Marketo form on it, the fields are NOT prefilled.  This makes it annoying for the user to have to re-enter their information if they want to download another gated asset.

 

SOLUTION:  Use REST API to get lead data from Marketo (via stored cookie) and use JS to populate the form fields.We contacted Marketo support and they pointed us to this page:http://developers.marketo.com/blog/external-page-prefill/

We technically could do everything via Javascript but as I’m sure you know, making the REST call via the browser is a no-no because it would expose our “client_id” and “client_secret” to the public.  So we need to make the REST calls via the server-sideIn addition to the link above that Marketo pointed us to, this other page explains how to get the cookie info via JS and then make the REST call to get the associated lead datahttp://developers.marketo.com/blog/get-a-visitors-cookie-id-and-then-query-associated-lead-data/

 

NOTE:  This git repo has some existing code for Marketo REST calls (including C#), which could be helpful:  https://github.com/Marketo/REST-Sample-Code

 

OVERALL STEPS:There will be two REST calls to Marketo:

  1. Get a new access token using “client_id” and “client_secret”.  Below is the complete URL structure for that (including our specific host URL, our client_id and our client_secret).  https://XXX-mtz-XXX.mktorest.com/identity/oauth/token?grant_type=client_credentials&client_id=XXX&client_secret=XXX
  2. Get lead data using the “_mkto_trk” cookie value and the access token.  Below is the URL structure for this call, but obviously need to fill in the corresponding <cookie> and <access_token> values.  https://XXX-mtz-XXX.mktorest.com/rest/v1/leads.json?filterType=cookie&filterValues=<cookie>&fields=email,firstName,lastName,company&access_token=<access_token>NOTE: The _mkto_trk cookie value includes an ampersand and needs to be URL encoded to ‘%26’ in order to be properly accepted by the Marketo endpoint.

 

 

Use Javascript to read the existing Marketo cookie.  This is obviously needed for the 2nd REST call above.

Once the 2nd REST call returns the lead data, it needs to be printed to the “mktoLead” variable:

Finally, map the lead data into the proper fields of the form

 

Sanford Whiteman

Outcomes