Mouseflow Help & Support

Block Recordings From Certain Countries

Follow

With Mouseflow, it's easy to control which visitors are recorded. For example, you can record visitors based on their country.

The examples below rely on the use of jQuery - you’ll need to download and install it if you don’t already have it. You can find another version hosted by Google Libraries here.

Record US visitors only

<!-- MouseflowExcludeStart -->
<script type="text/javascript">
function loadMouseflow() {
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);
 })();
}

jQuery.ajax({
   url: '//freegeoip.io/json/',
   type: 'POST',
   dataType: 'jsonp',
   success: function(location) {
   // Country you only want to record
   if (location.country_code === "US") {
      loadMouseflow();
      }
   },
   timeout: 2000, // Wait 2 secs to get the success
   error: function(jqXHR, textStatus, errorThrown) {
      if(textStatus === "timeout") {
         console.log("GeoIP error, loading MouseFlow anyway");
         loadMouseflow();
      }
   }
});
</script>

<!-- MouseflowExcludeEnd -->

In this case, the recording would only start for visitors from the United States.

Record Non-US Visitors

<!-- MouseflowExcludeStart -->
<script type="text/javascript">
function loadMouseflow() {
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);
 })();
}

jQuery.ajax({
   url: '//freegeoip.io/json/',
   type: 'POST',
   dataType: 'jsonp',
   success: function(location) {
      //Country you don't want to record
      if (location.country_code != "US") { 
         loadMouseflow();
      }
   },
   timeout: 2000, // Wait 2 secs to get the success
   error: function(jqXHR, textStatus, errorThrown) {      if(textStatus === "timeout") {
        console.log("GeoIP error, loading MouseFlow anyway");
        loadMouseflow();
     }
  }
});
</script>
<!-- MouseflowExcludeEnd -->

In this case, the recording will start for all visitors except the ones from the United States.

Important notes:

  • The code above uses the ISO 3166 Country Codes to define countries, in the line 'location.country_code'. Simply replace 'US' in this example with any country code you might need. Examples include US = United States, GB = United Kingdom, DE = Germany. For a full list of available country codes, we refer you to the ISO Online Browsing Platform
  • The MouseflowExclude-comments starting and ending the code examples are necessary to avoid the IP check from running in our playback window, which could slow down your playback of recordings.
  • Disclaimer: the code snippet above uses freegeoip.io, a public REST API for searching geolocation of IP addresses and host names. Usage is limited to 10,000 queries per hour. Mouseflow takes no responsibility for any downtime or performance issues with freegeoip.io.
  • In both code snippets we've added an error catch. So if the Freegeoip-API fails or has downtime, the code will still be loaded. In that case, you'd still get recordings from all countries, regardless of the filters you've entered. If you're not interested in this, you should remove the line 'error: function(location) { loadMouseflow();}'. That would mean that no recordings are made in case of an error with Freegeoip.io.

 

Tags: record specific visitors record specific country record non-us exclude country

 

Have more questions? Submit a request

Comments

  • Avatar
    mihailo.dhoric

    this feature should be available in website settings

Powered by Zendesk