Hi folks
we redirect users from an external site to a hs landing page and add different parameters to the url string:
https://url-of-hs-landingpage.com/contentslug**?userId=12345&other=params **
When i try to get the userId from the query string:
var source = window.location;
var userId = source.searchParams.get("userId");
console.log("uderId:" + userId);
I always receive an console error log:
How can I get dedicated Params from the URL string to work with these on the hs landing page?
Hello @jakobtiebel , I would like to add some top experts to this matter @Pixl_Labs @rohansdeeson @Teun what would you recommend to @jakobtiebel matter?
Thank you!
Pam
Problem is solved:
<script>
var params = JSON.parse(
'{"' +
decodeURI(location.search.substring(1))
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"') +
'"}'
);
var userId = params['userId'];
</script>
Teun
August 31, 2021, 5:19pm
4
Cool! If you need a more simple approach in the future, check my comment.
Teun
August 31, 2021, 4:49pm
5
Hi!
I got a solution that works for us on HubSpot landing pages:
const urlParams = new URLSearchParams(window.location.search)
const userId = urlParams.get(‘userId’)
Thanks Teun, simple and straight forward! I like, thank you!