Munchkin API Help | Community
Skip to main content
June 24, 2016
Question

Munchkin API Help

  • June 24, 2016
  • 1 reply
  • 814 views

Our web pages our built using client-side AJAX and the URL doesn't change, thus the standard analytics-type libraries which send events automatically based on URL changes etc., those are going to miss the majority of what's going on with the user. 

  I assume the Javascript for doing direct, realtime event submission is fairly straightforward, I was wondering someone wouldn't mind posting  a simple example of it how they use it on their website that is also using client-side AJAX

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
Level 10
June 25, 2016

Given a link like:

<a id="loadAjaxContent" href="#getSome">Get it</a>

Listen for clicks like:

     document.querySelector('#loadAjaxContent').addEventListener('click',function(e){

          Munchkin.munchkinFunction('clickLink',{href: this.href});

     });

Obviously you will want to use classes or some other kind of grouping for simplicity.

Or you could listen for any hashchange:

     window.addEventListener('hashchange',function(e){

          Munchkin.munchkinFunction('clickLink',{href: document.location.hash});

     });

Take note that if you use standard <a> tags and your hrefs ​do not ​start with hashes, then Munchkin will already be attached to them, so you definitely do not want to attach again.

Your question is actually overbroad because you have not specified how your single-page site actually works.  There's no one way to use Ajax for content replacement.