Knowledge base | mouseflow

Start Recordings Based on User Actions

With Mouseflow, you can choose to only record visitors who perform a specific action - like logging in, adding an item to the cart, or simply clicking a button.

This requires the use of cookies and JavaScript to conditionally include the tracking code. The examples below rely on the js-cookie library. Add this line to use it on your site:

<script src=""></script>

In the example below, we are starting recordings when the HTML element with the ID example is clicked. This condition can of course be changed to whatever suits you.


<script type="text/javascript">
    window._mfq = window._mfq || [];
    var activateMouseflow = function() { 
        var mf = document.createElement("script"); mf.type = "text/javascript"; mf.async = true; 
        mf.src = "//";

    // Action to trigger Mouseflow here:
    $("#example").click(function() {
        Cookies.set('mf_start', '1');

    if (Cookies.get('mf_start') === '1') {


  • The URL on the "mf.src" line must be customized to match the tracking code in your account.
  • You should always test these examples to make sure they have the desired functionality.