NAV
javascript

Mouseflow JS API documentation

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

Introduction

You authenticate to the Mouseflow API by providing your API key in the request. You can manage your API keys from your account. Your API keys have the same privileges as your user account, so be sure to keep them safe.

Authentication to the API occurs via HTTP Basic Auth. Provide your email address as the basic auth username, and provide your API key as the password.

All API requests must be made oer HTTPS. Calls made over plain HTTP will fail. You must authenticate for all requests.

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", _myUserName]);

If you want to add a username to the recording, …

Tagging a recording

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

Setting a custom variable

_mfq.push(["setVariable", _myKey, _myValue]);

Virtual paths and pageviews

Setting a virtual path

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

Adding a virtual pageview

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

Advanced

Start recording

_mfq.push(["start"]);

Stop recording

_mfq.push(["stop"]);

Stop session

_mfq.push(["stopSession"]);

Rebind event handlers

_mfq.push(["rebindEventHandlers"]);

Get session ID

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

Get pageview ID

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

Star recording

_mfq.push(["star"]);

Check if recording is enabled

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

Get website ID

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

Get recording rate

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

Get recording script version

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

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.

Excluding all keystrokes

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

Default: true

Excluding recording on subdomains

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

Default: true

Adding cross-domain support

_mfq.push(["config", "crossDomainSupport", true]);

Default: false

Controlling the timing of the HTML snapshot

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

Default: 1000

Disabling auto-tagging

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

Default: true

Disabling auto-start

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

Default: true

Force recording to start

_mfq.push(["config", "forceStart", true]);

This ignores the recording rate and always starts recording.

Default: false

Disable recording of touch events

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

Default: true

Disable compression

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

Default: true

Set a custom href

_mfq.push(["config", "href", _customHref]);

Default: window.location.href

Set HTML fetch mode

_mfq.push(["config", "htmlFetchMode", _mode]);

This can be set to either “post” or “get”

Default: “post”

Override session ID

_mfq.push(["config", "sessionId", _sessionId]);

Enable honoring of browser “Do not track” setting

_mfq.push(["config", "honorDoNotTrack", true]);

Default: false

Enable tracking mouse by relative position

_mfq.push(["config", "relativeMouseMove", true]);

Default: false

Disable data compression

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

Default: true

Disable DOM re-use optimization

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

Default: true

Disable DOM deduplication optimization

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

Default: true

Set custom timout for submit events

_mfq.push(["config", "registerSubmitTimeout", _timeout]);

Default: 2000

Use “unload” event instead of “beforeunload” event

_mfq.push(["config", "useUnload", true]);

Default: false