Skip to content

Instantly share code, notes, and snippets.

@ahmadthedev
Created May 6, 2025 14:23
Show Gist options
  • Save ahmadthedev/8ded80267042e95f281fdd1e201d9bf2 to your computer and use it in GitHub Desktop.
Save ahmadthedev/8ded80267042e95f281fdd1e201d9bf2 to your computer and use it in GitHub Desktop.
Append param (utm, gclid etc) in internal URL
<script>
document.addEventListener('DOMContentLoaded', function () {
const queryString = window.location.search;
if (!queryString) return; // no UTM parameters, nothing to do
const links = document.querySelectorAll('a[href^="/"], a[href*="' + location.hostname + '"]');
links.forEach(link => {
const url = new URL(link.href);
if (!url.search) {
url.search = queryString;
link.href = url.toString();
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment