Get a Visitor’s Cookie ID and then Query Associated Lead Data

October 30, 2014 | by

Using the Get Multiple Leads by Filter Type REST endpoint, you can query lead data based on a user’s cookie id. For example, you can use this approach to prefill a form on a non-Marketo landing page. This post will show you how to capture the user’s cookie value during a webpage visit, query Get Multiple Leads REST API with that cookie id, and then return the user’s lead data.

First, we will need the value of the user’s Munchkin cookie, ‘_mkto_trk’. Here is an example JavaScript function that you can use to get the cookie value. Please see this StackOverflow page for more information about this approach. I recommend setting a delay of 500ms after page load event before calling this function. This will give Munchkin time to load, and cookie the user.

Next, pass the value of the ‘_mkto_trk’ cookie to your server. To retrieve lead data, from your server you will make a call to the Get Multiple Leads REST API with this cookie value. You’ll need your Authentication and REST endpoints from your instance. Your call should be structured as follows:

The example above will return the email and all cookies associated with the user. You can then use this data to personalize the subsequent page the user visits.