Mouseflow Asynchronous Script

I’ve noticed that, among all the tracking pixels things, that Mouseflow tends to slow pages down to a crawl quite often.

Recently encountering this on a client’s website, I took a look at the way Mouseflow suggested you embed their code, and therein lies the problem:

<script type="text/javascript">
document.write(unescape("%3Cscript src='" + (("https:" == document.location.protocol) ? "https" : "http") + "://cdn.mouseflow.com/projects/007ec61c-c4b4-48e2-855b-c222f6636be7.js' type='text/javascript'%3E%3C/script%3E"));
</script>

Rather ugly, right?

So, patterning after Google Analytics’s asynchronous script, voila — non-blocking, stripped down version of Mouseflow analytics script:

<script type="text/javascript">
(function(d) {
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//cdn.mouseflow.com/projects/YOURACCOUNTNUMBER.js';
var t = d.getElementsByTagName('script')[0]; 
t.parentNode.insertBefore(s, t);
})(document); </script>

2 thoughts on “Mouseflow Asynchronous Script

  1. Hi,

    Thanks a bunch for pointing this out. As a matter of fact we recently phased out the old tracking code and replaced it with an asynchronous one. We’ve also improved out backend service to provide faster data transfer.

    The new tracking code looks like this:

    (function() {
    var mf = document.createElement(“script”); mf.type = “text/javascript”; mf.async = true;
    mf.src = “//cdn.mouseflow.com/projects/{project-id}.js”;
    document.getElementsByTagName(“head”)[0].appendChild(mf);
    })();

Leave a Reply

Your email address will not be published. Required fields are marked *