Munchkin is not associating anonymous activity with Leads on login | Community
Skip to main content
August 11, 2014
Solved

Munchkin is not associating anonymous activity with Leads on login

  • August 11, 2014
  • 17 replies
  • 3702 views
As I understand it, I'm supposed to be able to make Munchkin associate anonymous lead activity with an existing Lead when they log in.  That's not working for me.

On my post-login page, I'm calling this:

<script type="text/javascript">
$.ajax({
  url: '//munchkin.marketo.net/munchkin.js',
  dataType: 'script',
  cache: true,
  success: function() {
    Munchkin.init('xxx-xxx-xxx', {"wsInfo":"xxxxxxxxxxxxx"});
    Munchkin.munchkinFunction('associateLead',
      { email: 'some@email' }, 'long_sha1_hex');
  }
});
</script>

The long_sha1_hex is computed in Ruby via:
  Digest::SHA1.hexdigest( encrypt_key + email_address )

I'm not getting any error mesages in my js console, and no feedback that anytying is wrong.  But that munchkinFunction appears to be having zero effect.

Can anyone help me out?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by
Ugh.  See this code?

Munchkin.munchkinFunction('associateLead', {email: 'grant@email.address'}, '<hex from above>');

The "e" in "email" needed to be capitalized.   That's it.

Ugh.

17 replies

August 11, 2014
Guys, this is proving to be really frustrating.

I put a 20 second delay between init() and munchkinFunction(), and my lead is still not associating.  Certainly 20 seconds is long enough to assume that init() has completed, right?  So why isn't my munckinFunction() call working?

This is my entire js block that calls munchkin:

<script type="text/javascript">
$.ajax({
  url: '//munchkin.marketo.net/munchkin.js',
  dataType: 'script',
  cache: true,
  success: function() {
    Munchkin.init('xxx-xxx-xxx', {"wsInfo":"xxxxx"});
    setTimeout(
      function(){
        Munchkin.munchkinFunction('associateLead', {email: 'grant@email.address'}, 'long_hex_string');
        console.log("called munchkinFunction");
      },
      20000
    );
  }
});
</script>

What kind of animal needs to be sacrificed in order to get Munchkin's associateLead feature to work?
August 11, 2014
Murtza, I ran your Promise suggestion by some of my more js-experienced colleages, and they're not really sure how you mean for a Promise to be applied.

The central difficulty here is that Munchkin.init() doesn't return anything, and there's no way to truly know when its operation is complete.  How is a Promise supposed to help get around this problem?

To use a promise with Munchkin.init(), we'd pretty much have to rewrite it, no?
August 11, 2014
Ok... *rubs forehead*.

So I have to call init() before munchkinFunction().

But I can't call them sequentually because init() needs time to operate.

BUT... In your documentation, this is exactly what you do:
  1. <script>
  2.   Munchkin.init("###-###-###");
  3.   Munchkin.munchkinFunction('function',
  4.                  { key: 'value', key2: 'value'},
  5.                        'hash');
  6. </script>

(See http://developers.marketo.com/documentation/websites/lead-tracking-munchkin-js/ )

Doesn't the above example snippet suffer the same problem I'm seeing?  The code is pretty much the same as mine.

I think your documentation could use some enhancement in this area.
August 11, 2014
To identify the source of the problem, I would try implementing a Promise in jQuery or vanilla JavaScript.

So before calling munchkinFunction, Munchkin.init would have to be executed. 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

http://api.jquery.com/promise/
Kenny_Elkington
New Participant
August 11, 2014
Well you need Munchkin to initialize and pass the MunchkinId and wsInfo arguments into the function in order for the munchkinFunction to call to the correct URL.
August 11, 2014
Can (or should) I skip the Munchkin.init call then, if I'm going to call munchkinFunction?
Kenny_Elkington
New Participant
August 11, 2014
Hey Grant,

Munchkin functions execute asynchronously, so what's occurring with your code example is that before Munchkin.init can execute fully, associateLead is attempting to fire, causing it to fail.  It's typically best to pass the associateLead function into your login followup page, or in via ajax onto the page if you're not doing navigation after the login.