DEV Community

Viacheslav Borodulin
Viacheslav Borodulin

Posted on • Updated on

Tilda: transfer UTM params to another page

This code you should past in block:
Other ⟶ T123 ⟶ HTML-code.

<script>
(() => {
  const addSearchParams = () => {
    const links = document.getElementsByTagName('a');
    Array.from(links).forEach((link) => {
      if (link.href.indexOf({{your_domain}}) > 0) {
        const url = new URL(link.href);
        url.search = window.location.search;
        link.href = url.toString();
      }
    });
  };

  document.addEventListener(
    'DOMContentLoaded',
    addSearchParams
  );
})();
</script>
Enter fullscreen mode Exit fullscreen mode

Discussion (0)