Knowledge base | mouseflow

Cross Domain Tracking

With Mouseflow, it's easy to track visitors that travel across several domains. The normal installation procedure tracks each of these domains separately. But, in some cases, it's better to have a combined recording for a cross domain visit. This is useful when hosting a landing page or checkout flow on a different domain from your main site.

The first step is to ensure both domains are added under "Domain" for the project in question. You can check this by picking the website you're interested, and clicking the "Settings" tab on the left hand side. Verify that both domains are listed in the "Domains" field. This will allow you to track both domains, and will generate two recordings - one for each domain. To combine these recordings, you'll need to alter the tracking code for each domain.

Change: You'll need to add this line to the start of the tracking code:


    var mouseflowCrossDomainSupport = true;

Example:


    <script type="text/javascript">
        var mouseflowCrossDomainSupport = true;
        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>

Once this is set up, visitors going from the first domain to the second should have one combined recording session.

Important notes

  • This will only work for navigation in the same window/tab. If the visitor opens the second page in a new tab or window, two separate recordings will be generated.
  • This will only work for direct navigation from one domain to the other. So the Mouseflow tracking code needs to be on the last page of domain 1 and the first page of domain 2.
  • In the code example, you should replace the your-website-id with your Website ID, which can be found under Settings.
  • If you're using a tag manager, you'll want to deploy Mouseflow and any modifications to the Mouseflow code, via a custom HTML snippet/tag.

If you got pages with the same name on both domains, and you would like to differentiate between the page names in the Mouseflow recordings, then you can apply this string to the tracking code:


    var mouseflowPath = window.location.hostname + window.location.pathname;

NB. It is important that the mouseflowPath is loaded before rest of the tracking code, e.g.:


    <script type="text/javascript">
        var mouseflowPath = window.location.hostname + window.location.pathname;
        var mouseflowCrossDomainSupport = true;
        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>