Knowledge base | mouseflow

Hubspot Integration

To integrate with Hubspot, we can hook into the hubspotutk cookie to track users by the Hubspot ID in Mouseflow. This integration makes use of our Custom Variables feature and the js-cookie library. Here's how to set it up.

First, use the following line of code to install and run this additional library:

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.4/js.cookie.min.js"></script>

This code should be fired/called before your main Mouseflow code (below).

Next, add this line to the bottom of your Mouseflow code (before the </script> tag):

    _mfq.push(["setVariable", "hubspot_id", Cookies.get('hubspotutk')]);

Here's a finished example of how it should look:

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.4/js.cookie.min.js"></script>
<script type="text/javascript">

    // Mouseflow tracking code
    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);
    })();

    _mfq.push(["setVariable", "hubspot_id", Cookies.get('hubspotutk')]);
</script>

In the example code above, we use your-website-id as a placeholder for the Website ID found in your Mouseflow tracking code. You can obtain your Website ID in your account, under Settings -- you should replace your-website-id with this value (keep the .js ending).

Once this code is finalized, allow it to track some fresh sessions and you should now be able to filter the recording list by the hubspot_id variable. Under Recordings, click the filter (funnel) icon in the blue bar, and then under "Tags / Variables", click the dropdown to find the hubspot_id key. If it's not there, either you haven't tracked any visitors which have a Hubspot cookie yet or the modified code isn't installed/firing. Once you select thehubspot_id, enter a value for the ID you want to search for, accordingly.

It's important to note that the hubspot_id in the cookie for this integration is internal to Hubspot (not exposed by them anywhere in their UI). Instead, you need to take this information and query the Hubspot API with the hubspot_id to return information about the contact, if it exists in their system.