Last active
December 10, 2020 16:02
-
-
Save bensoutendijk/aa08c3bcfd41119d69c52f842f5b5186 to your computer and use it in GitHub Desktop.
Capture URL Parameters as Tags in Mouseflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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