Mouseflow Help & Support

Custom Variables/Tagging

Follow

With Mouseflow, you can associate additional information with a session by using custom variables or tags. This allows you to sort/filter various tools in Mouseflow based on your own data to isolate a specific segment of visitors.

A custom variable allows you to push a key/value pair into Mouseflow - two pieces of information like "user_id" = "1234" or "order_number" = "5678".

A tag allows you to push a single string into Mouseflow - one piece of information like "popup_fired" or "order_placed".

There are some tags that are already set up for you. To read more about them, please view this article: What do the preset tags in Mouseflow mean?

Use Cases

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

  • Customer ID
  • Name
  • Email Address
  • Zip Code
  • Order Amount/Number/Items
  • Campaign ID
  • Error Codes
  • Search Terms
  • Events (e.g. Modal Clicked, Abandoned Cart, Upsell/Crosssell)
  • Third-Party Data

Adding a Single Variable Using the Tracking Code

To push a single custom variable, add the following line (in bold) to your tracking code. 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.async = true;
mf.src = "//cdn.mouseflow.com/projects/your-website-id.js";
document.getElementsByTagName("head")[0].appendChild(mf);
})();
window._mfq.push(["setVariable", "KEY", "VALUE"]);
</script>

Adding Multiple Variables Using the Tracking Code

To push multiple custom variables, just add additional lines. Here's an example:

<script type="text/javascript"> 
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);
})();
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. Here's an example of how to do this:

<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.

Adding a Single Tag Using the Tracking Code

To push a tag, add the following line (in bold) to your tracking code.

<script type="text/javascript"> 
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);
})();
window._mfq.push(["tag","my-tag"]);
</script>

Adding Multiple Tags Using the Tracking Code

To push multiple tags, just add additional lines. Here's an example:

<script type="text/javascript"> 
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);
})();
window._mfq.push(["tag","my-tag"]);
window._mfq.push(["tag","my-other-tag"]);
</script>

Adding a Tag Separate from the Tracking Code

If you want to add a tag without changing your tracking code, you'll just need to enter a short snippet of code. This may come in handy if you are using Google Tag Manager or another extension. Here is an example:

<script type="text/javascript"> 
window._mfq = window._mfq || [];
window._mfq.push(["tag","my-tag"]);
</script>

Notes

  • The URL on the "mf.src" line must be customized to match the tracking code in your account. In particular, "your-website-id.js" should be replaced with the unique ID for your website.
  • 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: custom variables tags filter recording

Have more questions? Submit a request

Comments

  • Avatar
    freidahod

    Hello Stefanni,

    Thanks for replying to my question.
    Let me start by saying that I do not understand all the technical stuff .
    I need it for a landing page created. It is asking me to place a Mouse flow Tagging - Key and Tagging - Value, which I do not know where or how to find it.

    The articals are not helping me I do not understand them.
    Could you please point me directley to where I can find them or how to create them?

    Thanks,
    Freida

  • Avatar
    Stefanni Becker

    Hi Freida,

    I am happy to help you! I can walk you through how to do all of this. Please email me at sbecker@mouseflow.com, where I can talk you to more about this.

    Thank you for reaching out, and I look forward to hearing from you!

    Warmly,
    Stefanni

Powered by Zendesk