Pass query param to every page

How can I pass a query param from one page to another. I have tried inserting the following code into the header in a script tag but it doesn’t seem to do anything.

https://stackoverflow.com/questions/55414111/how-to-pass-url-parameters-across-all-pages-internal-links-in-a-site-with-javasc/55414202

1 Like

This should work also, but the tag isn’t executing and I have no idea why

<!-- URL Param pass -->
<script>
document.querySelectorAll('a')
        .forEach(el => el.attributes.href.value += window.location.search);
</script>
<!-- End URL Param pass --!>

Did you find an answer? I’m trying to figure this out myself as well.

Hey sorry, just saw your response. No I was never able to figure it out and received no support from webflow. Seems like they don’t answer any questions

Hey, I’ve just been dealing with this topic too. If anyone else is looking for a solution, here is my solution in which I simply append all query parameters directly to the existing links on the page. Hope it helps!

<script>
// Append query parameters to all links
document.addEventListener('DOMContentLoaded', function () {
  const queryParams = new URLSearchParams(window.location.search);
  const links = document.querySelectorAll('a');

  links.forEach(link => {
    const currentUrl = new URL(link.href, window.location.origin);
    queryParams.forEach((value, key) => {
      currentUrl.searchParams.set(key, value);
    });
    link.href = currentUrl.toString();
  });
});
</script>