SOLVED

Caputuring _mtko_trk cookie and passing to hidden fieid

Go to solution
Highlighted
Anonymous
Not applicable

Caputuring _mtko_trk cookie and passing to hidden fieid

Hi,

I have a custom form builder function that renders a marketo form using json data from marketo.

To render out the correct form the i pass the 4 digit form if to the form builder plugin which calls the correct json data.

As part of this development I have been advised by marketo to add in the munchkin tracker js file and a hidden field to each form for the munchkin cookie value.

<input type="hidden" name="_mkt_trk" id="_mkt_trk">

In a standard form the munchkin tracker script passes the _mkto_trk cookie value to the hidden _mkt_trk form field.

My form builder function renders the form once the page has rendered and the munchkin track script triggered, meaning that the hidden form field will never be populated.

In order to solve this I have referenced this readCookie function, i then call the readCookie function inside my form builder function, which then sets the _mkt_trk hidden field value

http://developers.marketo.com/blog/get-a-visitors-cookie-id-and-then-query-associated-lead-data/

function readCookie(name) {

  var cookiename = name + "=";

  var ca = document.cookie.split(';');

  for (var i = 0; i < ca.length; i++) {

    var c = ca[i];

    while (c.charAt(0) === ' ') c = c.substring(1, c.length);

    if (c.indexOf(cookiename) === 0) return c.substring(cookiename.length, c.length);

  }

  return null;

}

readCookie('_mkto_trk')

A working demo can be found here:JSFiddle 

If _mkto_trk is in the cookie exists in document.cookie, the readCookie function will grab the value.

Based on my form implementation is this a suitable approach to grab the _mkto_trk cookie value and populate the form hidden field?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Marketo Employee

Re: Caputuring _mtko_trk cookie and passing to hidden fieid

Looks like it works fine, as I just tested it live in the console and it returns a valid cookie value.  What exactly are you trying to accomplish with the custom builder?

View solution in original post

2 REPLIES 2
Highlighted
Marketo Employee

Re: Caputuring _mtko_trk cookie and passing to hidden fieid

Looks like it works fine, as I just tested it live in the console and it returns a valid cookie value.  What exactly are you trying to accomplish with the custom builder?

View solution in original post

Highlighted
Anonymous
Not applicable

Re: Caputuring _mtko_trk cookie and passing to hidden fieid

HI Kenny,

Thanks for testing.

It's a long story, however the short version is a multi platform marketo form generator that seamlessly blends in with current systems on our portfolio of sites. Our sites are run on a variety of web platforms. One of the challenges we face is that some of our sites are build using aspx webforms. This caused issues when using the standard marketo embed.

The solution works well. We are able to make forms fit in with existing branding, we can apply layout and style customization for each instance and most importantly continue to serve the business requirements for custom and dynamic form thank you messages, google analytic event tracking and bespoke email auto responders.

Thanks