Pass through query params
Unanswered
Western Kingbird posted this in #help-forum
Western KingbirdOP
I have a need to take any query params and then append them to the end of all outgoing URLs on a page, for tracking purposes... I'm using useRouter and grabbing the query off of that. I'm looking to just do a raw, straight passthrough. But somewhere along the line, HTML characters are encoded. So I start with something like this "utm_campaign=Advantage++10%25+Cap" and it ends up like this "utm_campaign=Advantage 10% Cap". Is there a way to stop that from happening so I just get the raw value?
3 Replies
@Western Kingbird I have a need to take any query params and then append them to the end of all outgoing URLs on a page, for tracking purposes... I'm using useRouter and grabbing the query off of that. I'm looking to just do a raw, straight passthrough. But somewhere along the line, HTML characters are encoded. So I start with something like this "utm_campaign=Advantage++10%25+Cap" and it ends up like this "utm_campaign=Advantage 10% Cap". Is there a way to stop that from happening so I just get the raw value?
you can encode it back to URLusing
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
haha
Western KingbirdOP
that was doing weird things. I actually was able to figure this out by switching from using router.query to using window.location.search