Re: Callback for visitWebPage?

Anonymous
Not applicable

Callback for visitWebPage?

I want to execute some JavaScript after Marketo makes its call to visitWebPage. Is there a callback for this function or an event I can detect? Can this be done on a Marketo-hosted landing page?
Tags (1)
6 REPLIES 6
Anonymous
Not applicable

Re: Callback for visitWebPage?

I have the same question.

SanfordWhiteman
Level 10 - Community Moderator

Re: Callback for visitWebPage?

There's no builtin hitCallback as there is with GA.  My "Munchkin Enhanced" adapter adds this capability into Munchkin.  But can I ask what you're using it for?  There may be another way.

Anonymous
Not applicable

Re: Callback for visitWebPage?

Thanks for your reply Sanford. I was hoping for a callback after the Munchkin cookie is set, so I may send the cookie to another domain.  I assumed Munchkin wouldn't call visitWebPage until that cookie had been finalized, so I was first probing for one there.  Then I later discovered a function called Munchkin.createTrackingCookie but couldn't find any documentation on this, certainly none with any mention of a callback, so then attempted to bind a callback of my own to that but ran out of time figuring out the art of doing that in JS.  So I ended up setting an interval to check for the cookie after the munchkin script is requested.  That seems to work fine, just not as elegant.

SanfordWhiteman
Level 10 - Community Moderator

Re: Callback for visitWebPage?

No need for an interval.  Cookies are always set synchronously, immediately after the Munchkin library (not the bootstrapper) loads.

So:

  Munchkin.init('AAA-BBB-CCC');

  document.addEventListener('load', function(e) {

    if (/\/munchkin.js$/.test(e.target.src)) {

      setTimeout(function() {

        // cookie must exist here on this turn of the event loop

      });

      document.removeEventListener('load',arguments.callee,true);

    }

  }, true);

Anonymous
Not applicable

Re: Callback for visitWebPage?

Very creative and elegant approach!

Thank you so much, I'm going to try this.

SanfordWhiteman
Level 10 - Community Moderator

Re: Callback for visitWebPage?

Yeah, I am quite proud of it.