NAV
javascript

Introduction

You can interact with Mouseflow on your website when Mouseflow is installed and is tracking. This website describes how you can identify end users, add tags, custom variables, manage virtual pageviews and a lot more.

In case you're looking for a server-side API, please visit our REST API documentation

The _mfq object

window._mfq = window._mfq || [];

The _mfq object is the entry point for all communication with the Mouseflow tracking script. Since the tracking script is loaded asynchronously you need to make sure the _mfq object is present before calling it. That's done my declaring it as an empty array if it's not declared already (see code to the right).

The array object is used as a queue, and you use it by pushing commands onto the array. Once Mouseflow is fully loaded, the queue is processed, and any new commands pushed only it will be processed immediately.

_mfq.push([commandName, argument1, argument2, ...]);

_mfq.push( function(_mouseflow) { console.log("Mouseflow loaded. Session ID: " + _mouseflow.getSessionId()); } );

Adding custom data

Identifying a user

_mfq.push(["identify", _userName]);

If you have a user name or email of the current user, you can add this information to Mouseflow which makes it much easier to find your users in the dashboard.

Tagging a recording

_mfq.push(["tag", _tag]);

Sometimes it's useful to add a custom tag to a recording. A tag is a string value that you choose yourself. Examples include "product-added", ...

Setting a custom variable

_mfq.push(["setVariable", _key, _value]);

If a tag isn't enough, and it's more useful for you to add a key and a value, you can use custom variables. Values are always treated as strings, ...

Star recording

_mfq.push(["star"]);

Virtual paths and pageviews

Setting a virtual path

_mfq.push(["config", "path", _virtualPath]);

Adding a virtual pageview

_mfq.push(["newPageView", _virtualPath]);

Starting and stopping recording

Disabling auto-start

_mfq.push(["config", "autoStart", false]);

If you for some reason don't want Mouseflow to start recording immediately when a user enters a page, you can set the "autoStart" configuration to false. When at some point you would like the recording to start, use the mouseflow.start() call which is explained below.

Start recording

mouseflow.start();

If you have set "autoStart" to false (see previous section), this call starts recording a page.

Please note that this is the only call where you don't use the _mfq variable, but call a method directly on the "mouseflow" global object. You should check if the object is available prior to calling it, to avoid throwing a javascript exception.

Stop recording

_mfq.push(["stop"]);

Getting Mouseflow recording data

Get session ID

_mfq.push(function(mf) {
    console.log(mf.getSessionId());
});

Get pageview ID

_mfq.push(function(mf) {
    console.log(mf.getPageviewId());
});

Check if Mouseflow recording is currently recording

_mfq.push(function(mf) {
    console.log("Mouseflow is recording: " + mf.isRecording());
});

Get website ID

_mfq.push(function(mf) {
    mf.websiteId;
});

Get recording rate

_mfq.push(function(mf) {
    mf.recordingRate;
});

Custom form events

Add form submit event

_mfq.push(["formSubmitAttempt", formId]);

Add form submit success event

_mfq.push(["formSubmitSuccess", formId]);

Form ID is optional and defaults to form with latest registered form submit attempt.

Add form submit failure event

_mfq.push(["formSubmitFailure", formId]);

Form ID is optional and defaults to form with latest registered form submit attempt.

Advanced configuration

Excluding all keystrokes

_mfq.push(["config", "keyLogging", false]);

Default: true

Controlling the timing of the HTML snapshot

_mfq.push(["config", "htmlDelay", _delayInMilliseconds]);

Default: 1000

Disabling auto-tagging

_mfq.push(["config", "autoTagging", false]);

Default: true