API Reference

Munchkin provides several functions which can be called manually through Javascript. These can allow for customized tracking of browser events, such as video plays, or clicks on non-links. In order to use the Munchkin API, it must be enabled and a secret key set, via the Admin > Integration > Munchkin Menu.

Munchkin-Config

Munchkin.init()

Munchkin.init() must be called before any other functions. It will set Munchkin on the current page to send activities to a specific instance and will generate a “Visits Web Page” activity for the current page.

Parameter Name Optional/Required Type Description
Munchkin ID Required String Munchkin Account ID found under Admin > Integration > Munchkin menu.

Sets the target instance to send activities to.

Configuration Settings Optional Object Enables alternate behavior settings for Munckin.

Munchkin.createTrackingCookie()

When called, this will check to see if there already exists an “_mkto_trk” cookie in the browser, and will create one if it does not. This is useful for enabling tracking for users during specific actions, such as registration or downloading an asset, if cookieAnon is set to false.

Parameter Name Optional/Required Type Description
forceCreate Required Boolean Create cookie even if cookieAnon is set to false.

Munchkin.munchkinFunction()

Used for generating custom tracking behaviors, such as video player plays and pauses, or page visits for non-standard navigation, such as hashcodes.

Parameter Optional/Required Type Description
Function Type Required String Determines the activity to record.

Permissible values:

Data Required Object Contains data for the activity to be recorded.
Hash Required if Function Type is associateLead String The SHA1 hash of Munchkin API Private Key + Email Address.

visitWebPage

Calling munchkinFunction() with visitWebPage will send a visit activity for the current user to Marketo. You can customize the URL and querystring which are sent with the data object in the second argument.

Data Property Name Optional/Required Type Description
url Required String The URL file path used to record a page visit.  This value is appended to current domain name to create full page name.

For example, if url is ‘/index.html’ and domain name is ‘www.example.com’, then the visited page is recorded as ‘www.example.com/index.html’.

params Optional String A querystring of the desired parameters to be recorded.

For example, ‘foo=bar&biz=baz’.


clickLink

Calling munchkinFunction() with clickLink will send a click activity for the current user to Marketo. You can customize the click URL with the “href” property in the data object.

Data Property Name Optional/Required Type Description
href Required String The URL file path used to record a link click.  This value is appended to current domain name to create full link.

For example, if href is ‘/index.html’ and domain name is ‘www.example.com’, then the link click is recorded as ‘www.example.com/index.html’.


associateLead

Calling munchkinFunction() with associateLead allows you to send field data to the lead record which corresponds to the browser’s current Marketo cookie value. The lead will receive updates for each of the fields included in the data object. The data object for associateLead can include any number of properties, as long as the property name is a lead field, and one of those properties is “Email”.

The third parameter when using associateLead is a SHA1 hash of two concatenated items:

  1. API Private Key from Admin > Integration > Munchkin menu
  2. Email address passed in the “Email” property of the data object

For example, given the API Private Key of “secret_key”, and the email address of “email@example.com”, the hash would be “764ff23fd5cbf8ff7b08c8017b5645710a9e6f77”.

The hash should never be calculated in client-side code, as this risks exposing your API Private Key for unauthorized use.

You should not attempt to call associateLead if there is a risk that the page will quickly navigate away, as this can result in the request failing. If used as a method to submit form data to Marketo, this method should always be called on the followup page so that the data can be safely submitted.

For Smart Campaign triggering purposes, use “Munchkin API” as your “Source Type”. For example, you can use a “Lead Is Created” trigger with “Source Type” is “Munchkin API” to trigger on associateLead calls that create leads.

Data Property Name Optional/Required Type Description
Email Required String The Email address of the lead to be updated and/or associated to the Marketo cookie in the current browser session.
Other Fields Optional Field-dependent Any other fields may be included via their SOAP API names, which can be obtained through Export Field Names.