Mouseflow Help & Support

How do I only track visits referred by Facebook?

Follow

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 makes use of some extra JavaScript. Just replace your tracking code with the snippet below.

Example

<script type="text/javascript">
var Cookie = { set: function(name, value, days) { var domain, domainParts, date, expires, host; if (days) { date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); expires = "; expires="+date.toGMTString(); } else { expires = ""; } host = location.host; if (host.split('.').length === 1) { document.cookie = name+"="+value+expires+"; path=/"; } else { domainParts = host.split('.'); domainParts.shift(); domain = '.'+domainParts.join('.'); document.cookie = name+"="+value+expires+"; path=/; domain="+domain;
if (Cookie.get(name) == null || Cookie.get(name) != value) { domain = '.'+host; document.cookie = name+"="+value+expires+"; path=/; domain="+domain; } } }, get: function(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i=0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') { c = c.substring(1,c.length); } if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; }, erase: function(name) { Cookie.set(name, '', -1); } };

if (document.referrer.indexOf('facebook') > -1) { Cookie.set('mf_record_user', 1, 10); }

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

// mouseflow tracking code

 var _mfq = _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.

 

Tags: track record referral facebook

Have more questions? Submit a request

Comments

Powered by Zendesk