With Mouseflow, it's easy to control which visitors get recorded. For example, you can record visitors who find your website through Facebook.


To only track visits from Facebook, we can check whether the referrer URL contains Facebook.


This integration example uses the js-cookie library. Add it to your site by adding this line:

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.4/js.cookie.min.js"></script>

Example

<script type="text/javascript">
    if (document.referrer.indexOf('facebook') > -1) { 
        Cookies.set('mf_record_user', 1, 10); 
    }

    if (Cookies.get('mf_record_user')) {

        // mouseflow tracking code
        window._mfq = window._mfq || [];
        (function() {
            var mf = document.createElement("script"); mf.type = "text/javascript"; mf.async = true;
            mf.src = "//cdn.mouseflow.com/projects/your-website-id.js";
            document.getElementsByTagName("head")[0].appendChild(mf);
        })();
    }
</script>

Each new visit will only be captured if it originates from Facebook.