I'm looking to keep url querystring parameters in a url string when passed from my 3rd party https page to my https marketo page before munchkin loads so I can trigger off the "Visits Web Page" trigger. Thanks!
Solved! Go to Solution.
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:
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);
}
})();
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:
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);
}
})();
plug and play -- perfection! Thanks Sanford!!!