You're in luck with this particular need because you don't actually need to parse the referrer's querystring (that is, parse its inner key=value pairs) at all, just chop out the querystring properly and plop it onto the end of the current URL.
For that we use a by-now typical pattern:
- create a couple of built-in Location objects
- use the the search property on any Location — that's the querystring, including the question mark
- concatenate the search-es
- replace the current URL without refreshing
Just make sure you run this code before loading Munchkin. On a Marketo LP, putting it in the head will suffice, since Munchkin loads at the end of the body.
(function () {
var referrerLoc = document.createElement("a"),
docLoc = document.createElement("a");
referrerLoc.href = document.referrer;
// if referrer has a non-empty qs, transplant it to current doc
if (referrerLoc.search.length > 1) {
docLoc.href = document.location.href;
docLoc.search += (docLoc.search ? "&" : "") + referrerLoc.search.substring(1);
history.replaceState({}, undefined, docLoc.href);
}
})();