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

Kenny_Elkington
Adobe Employee
Adobe Employee
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.
August 11, 2014
Can (or should) I skip the Munchkin.init call then, if I'm going to call munchkinFunction?
Kenny_Elkington
Adobe Employee
Adobe Employee
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
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/
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
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
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
Grant - You are right. DIsregard my promises suggestion. There is no callback / notification from Munchkin.init

The recommendation I got from the engineering team is to do Munchkin.init and munchkinFunction after the user's login.
August 12, 2014
I'm afraid I don't understand that recommendation.

I *am* doing them after the user's login.  Above you can see how I'm calling it in my post-logon page.  This is nearly the same as you have in your docs (which I've also repasted above).

Even with a 20 second delay separating the calls, it still doesn't work.

What does code that *does* work look like?
August 12, 2014
Hi Grant,

Munchkin Init and Munchkinfunction can be called sequentially. The init call is synchronous for all the things that munchkinFunction needs.

Most customers have one of the following problems when using associateLead.
  1. The generated hash is incorrect
    • EncryptKey is copied incorrectly
    • Email used is not the same as the lead being associated/updated
    • Hash Function used is not SHA1
    • There are trailing or leading spaces when passing the hash to munchkin.
  2. The browser is being re-directed to another page as soon as associatelead is called. (munchkin does not have enough time to perform the associate Lead which is a asynchronous call)
  3. The Munchkin ID being used and the Encrypt Key are from different subsciption.

I'll proceed with the presumption that you have checked all of the above conditions. 

Since we are receiving other successful associateLead calls to munchkin we have to presume that it is not a pervasive condition. Would it be possible to have either Murtza or me take a look at the actual page that you are trying to do this on?

regards,
Dj