Pass URL parameter to next page upon pressing a CTA button

Hi,

Would like to ask for help on a situation. I have got the following url parameter appended: https://www.couponly.io/?fans=85223456189

I have a CTA button, which will lead to a form block, where I would like to have a hidden field to capture the phone number above. How a custom code can make it happen?

I tried with the following consulting the Notion AI, but it is not working, anyone has an idea of it? I think this should be quite an interesting topic a lot of users would like to know.

<script>
document.addEventListener('DOMContentLoaded', () => {
  const contactUsButton = document.querySelector('.MuiButton-containedPrimary');
  contactUsButton.addEventListener('click', () => {
    const currentUrl = window.location.href;
    console.log('Current URL:', currentUrl);
    const fans = new URLSearchParams(window.location.search).get('fans');
    console.log('Fans parameter:', fans);
    const redirectUrl = `https://www.couponly.io/potcustomer?fans=${fans}`;
    console.log('Redirect URL:', redirectUrl);
    setTimeout(() => {
      window.location.href = redirectUrl;
    }, 2000);
  });
});
</script>

Appreciate kind assistance!

Tks & Bgds

Eric