With Mouseflow, you can associate additional information with a session by using custom variables or tags.

A Custom Variable allows you to push a single string into Mouseflow - one piece of information like popup_fired or order_placed. In addition, there are some tags that are already set up for you.

Use

Variables allow you to sort/filter various tools in Mouseflow based on your own data to isolate a broad segment of visitors.

Use cases

Here is a list of some of items you might want to track:

  • Order Amount/Value
  • Campaign ID
  • Error Codes
  • Search Terms
  • Events (e.g. Modal Clicked, Abandoned Cart, Up-sell/Cross-sell)

Setup

Setting up Custom Variables on your site is relatively easy but it does require a small amount of coding.

Adding a Single Variable in the Tracking Code

To push a single custom variable, add the following line to your tracking code.

window._mfq.push(["setVariable", "KEY", "VALUE"]);

Set the "key" and "value" to match your requirements, accordingly.

Here's an example:

<script type="text/javascript"> 
window._mfq = window._mfq || [];
(function() {
var mf = document.createElement("script"); mf.type = "text/javascript"; mf.defer = true;
mf.src = "//cdn.mouseflow.com/projects/your-website-id.js";
document.getElementsByTagName("head")[0].appendChild(mf);
})();
window._mfq.push(["setVariable", "KEY1", "VALUE"]);
</script>JavaScript


Adding Multiple Variables in the Tracking Code

To push multiple custom variables, just add additional lines. Set the "key" and "value" to match your requirements, accordingly.

Here's an example:

<script type="text/javascript"> 
window._mfq = window._mfq || [];
(function() {
var mf = document.createElement("script"); mf.type = "text/javascript"; mf.defer = true;
mf.src = "//cdn.mouseflow.com/projects/your-website-id.js";
document.getElementsByTagName("head")[0].appendChild(mf);
})();
window._mfq.push(["setVariable", "KEY1", "VALUE1"]);
window._mfq.push(["setVariable", "KEY2", "VALUE2"]);
</script>


Adding a Variable Separate from the Tracking Code

You can add a variable by itself, without implementing it in your tracking code. This may be useful if you are using Google Tag Manager or another integration. Set the "key" and "value" to match your requirements, accordingly.


Here's an example:

<script type="text/javascript"> 
window._mfq = window._mfq || [];
window._mfq.push(["setVariable", "KEY1", "VALUE1"]);
</script>


Scope

A custom variable can be set many time per session. Each time the variable is set, it will overwrite any previous values. So if a user is assigned KEY1 / VALUE1 at the start of the session, and is later assigned KEY1 / VALUE2, the latter variable will overwrite the first. So the session will only be tagged with KEY1 / VALUE2.


However, if you want to set a variable and make sure it's never overwritten, you can do so using an extra argument in the call:

window._mfq.push(["setVariable", "KEY1", "VALUE1", "session", false]);

In the example above, the variable "KEY1", will get a value of "VALUE1", and that value will never be overwritten, even if another call is made later in the session.

Did this answer your question?