Mouseflow Help & Support

Store Cookies as Custom Variables

Follow

With Mouseflow, you can use Custom Variables to push all cookies and their values into our platform. This is useful if you want to see which cookies are associated with a session or sort/filter for specific sessions based on cookie data.

To use this feature, simply add the following JavaScript to any page(s) you wish to cookies from.

<script type="text/javascript">
for (var i = 0; i < document.cookie.split(';').length; i++) {
	var _mfq = _mfq || [];
	var cookie = document.cookie.split(';')[i].trim();
	var cookieName = cookie.split('=')[0];
	var cookieValue = cookie.split('=')[1];
	_mfq.push(["setVariable", cookieName, cookieValue]);
}
</script>


Note: By default, custom variables are session-scoped so a cookie which has an initial value that is later changed (updated) will be stored only with the latest/most recent value. To change this behavior (preserving the initial value and ensuring that it doesn't get overwritten), use this code snippet instead:

<script type="text/javascript">
for (var i = 0; i < document.cookie.split(';').length; i++) {
	var _mfq = _mfq || [];
	var cookie = document.cookie.split(';')[i].trim();
	var cookieName = cookie.split('=')[0];
	var cookieValue = cookie.split('=')[1];
	_mfq.push(["setVariable", cookieName, cookieValue, "session", false]);
}
</script>
Have more questions? Submit a request

Comments

Powered by Zendesk