SOLVED

Re: Munchkin is not associating anonymous activity with Leads on login

Go to solution
Anonymous
Not applicable

Munchkin is not associating anonymous activity with Leads on login

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

Accepted Solutions
Anonymous
Not applicable

Re: Munchkin is not associating anonymous activity with Leads on login

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
Kenny_Elkington
Marketo Employee

Re: Munchkin is not associating anonymous activity with Leads on login

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.
Anonymous
Not applicable

Re: Munchkin is not associating anonymous activity with Leads on login

Can (or should) I skip the Munchkin.init call then, if I'm going to call munchkinFunction?
Kenny_Elkington
Marketo Employee

Re: Munchkin is not associating anonymous activity with Leads on login

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

Re: Munchkin is not associating anonymous activity with Leads on login

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/
Anonymous
Not applicable

Re: Munchkin is not associating anonymous activity with Leads on login

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

Re: Munchkin is not associating anonymous activity with Leads on login

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

Re: Munchkin is not associating anonymous activity with Leads on login

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

Re: Munchkin is not associating anonymous activity with Leads on login

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

Re: Munchkin is not associating anonymous activity with Leads on login

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?