Created
May 6, 2025 14:23
-
-
Save ahmadthedev/8ded80267042e95f281fdd1e201d9bf2 to your computer and use it in GitHub Desktop.
Append param (utm, gclid etc) in internal URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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