SOLVED

Munchkin is not associating anonymous activity with Leads on login

Go to solution
Anonymous
Not applicable
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?
Tags (1)
1 ACCEPTED SOLUTION
Anonymous
Not applicable
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.

View solution in original post

17 REPLIES 17
Anonymous
Not applicable
Great catch, Grant! Thanks for sharing that with everyone. 
Anonymous
Not applicable
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.
Anonymous
Not applicable
Hi Grant, 

I've taken a look in your instance, and reviewed the currently defined API Private Key.

The currently defined API Private Key does not have full words in it. I've included that key in the case I have open with you. Please check your case notes to find the value of your API Private Key. 

Please use this key and see if this resolves your issue. As stated by DJ, you need to use the key listed in your Marketo Admin section. 

Best regards,
Chris
Anonymous
Not applicable
My admin has given me a key which is 18 alphanumeric (not hex) characters.  He created this key himself (e.g. contains real words).

Does this sound like a correct key?  I tried it, and it did not work.
Anonymous
Not applicable
Aaaaaaargh.

I've asked my admin to set up a key for me.

Thanks.
Anonymous
Not applicable
Hi Grant,

I think we may have found your problem :-). The Key for munchkin is set from Marketo Munchkin Admin.
  • Log into Marketo 
  • Go to Admin 
  • Under Integration  click on  Munchkin
  • Enable Munchkin API and set a API key there
You should use this key for Munchkin API functions. 

We are planning to introduce callback functions to Munchkin calls, https://community.marketo.com/MarketoIdeaDetail?id=08750000000HzjkAAC with the next Beta. Stay Tuned. Callbacks would  allow you to ensure delivery of your API call before moving on. This would still not give you a success/Failed satus because that  could allow anybody on the internet to brute force guess your api key/lead details.

Regards,
DJ
Anonymous
Not applicable
Thanks DJ, that's a very helpful comment.
 
It very well could be that I am encrypting it wrong.  (I really wish Munchkin could give some kind of status code feedback if this was the case.)
 
This is how I am encrypting it (using Ruby, though I'm not assuming you know this particular function):
 
    Digest::SHA1.hexdigest( encrypt_key + email_address )
 
And the actual function call in Javascript is:
 
    Munchkin.munchkinFunction('associateLead', {email: 'grant@email.address'}, '<hex from above>');
 
The email address I'm using does correspond with an existing lead.  Do those calls look basically correct?
 
If yes, then it's possible I'm not using the right key.  It's a length-44 hexidecimal string, right?    I'm using the same key that I use for my Marketo SOAP API calls.  Am I perhaps mistaken in assuming that I can/should use the same key for SOAP and Munchkin?
 
Anonymous
Not applicable
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

Anonymous
Not applicable
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?
Anonymous
Not applicable
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.
Anonymous
Not applicable
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?
Anonymous
Not applicable
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?
Anonymous
Not applicable
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.
Anonymous
Not applicable
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
Marketo Employee
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.
Anonymous
Not applicable
Can (or should) I skip the Munchkin.init call then, if I'm going to call munchkinFunction?
Kenny_Elkington
Marketo Employee
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.