Skip to content

Instantly share code, notes, and snippets.

@bensoutendijk
Last active December 10, 2020 16:02
Show Gist options
  • Save bensoutendijk/aa08c3bcfd41119d69c52f842f5b5186 to your computer and use it in GitHub Desktop.
Save bensoutendijk/aa08c3bcfd41119d69c52f842f5b5186 to your computer and use it in GitHub Desktop.
Capture URL Parameters as Tags in Mouseflow
// This snippet of code will tag the pageview with the
// QueryString Variables found in the mfQueryVariables array
var mfQueryVariables = ["ref"];
function mfGetQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
return "";
}
window._mfq = window._mfq || [];
for (var i = 0; i < mfQueryVariables.length; i++) {
if (mfGetQueryVariable(mfQueryVariables[i])) {
window._mfq.push([
"tag",
mfQueryVariables[i] + "=>" + mfGetQueryVariable(mfQueryVariables[i])
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment