Knowledge Base/Integrations and advanced use

Record Visitors Based On Entry Page

Mouseflow Support
posted this on June 28, 2013, 21:18

With Mouseflow, you can determine whether to record visitors based on a specific entry page. This requires the use of cookies and JavaScript to conditionally include the tracking code.

First, download and install the jQuery Cookie Plugin.

Then, replace your existing tracking code with something that follows this format:

<script type="text/javascript"> 
var entryPageToRecord = "/entry-page"; (function($) { var activateMouseflow = 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); }; var mfEntryPageCookie = $.cookie('mf_entrypage'); if (mfEntryPageCookie === null) { $.cookie('mf_entrypage', document.location.pathname); mfEntryPageCookie = document.location.pathname; } if (mfEntryPageCookie == entryPageToRecord) { activateMouseflow(); } })(jQuery);
</script>


Notes

  • You need to customize the path to the entry page (in this case "/entry-page" above).
  • The URL on the "mf.src" line must be customized to match the tracking code in your account.
  • You should always test this to make sure it has the desired functionality.

Questions?

If you have questions or need help, feel free to open a ticket or call us at +1 (855) 668-7335.

Tags: cookies javascript jquery

 

Comments

User photo
Rosinvest Realstate

Please help me with the below queries..

1. Do i need to add the page url directly or any code that relates to the entry page ? How i need to add entry page like "/http://www.website.com/page1=sample&rent" or "/www.website.com/page1=sample&rent" ?

2. Tracking code means which code? Is it my analytics code or mouse flow code which i received at the beginning of my account creation?

 

 

February 19, 2015, 07:37
User photo
Morten Hornbaek
Mouseflow

1: You should enter URL of thee entry page to in the first line of the example:

var entryPageToRecord = "/entry-page";

You should note that we don't use the full URL, but only the pathname. So with your example ('http://www.website.com/page1=sample&rent') you should enter:

var entryPageToRecord = "/page1=sample&rent"

Also, if the entrypage in question uses querystrings - such as www.example.com/?query=string - you will need to change some lines in the example:

This first line should be:
var entryPageToRecord = "/?query=string"

And these two lines:
$.cookie('mf_entrypage', document.location.pathname);
mfEntryPageCookie = document.location.pathname;

Should be changed to:
$.cookie('mf_entrypage', document.location.pathname + window.location.search);
mfEntryPageCookie = document.location.pathname + window.location.search;


2: The tracking code we mention is the Mouseflow tracking code you received when you created your project. Is should be replaced by the this example, once it has been personalized (you need to add your own website-ID to replace the '123.js' in the example.

February 20, 2015, 14:26