Skip to content

Instantly share code, notes, and snippets.

@brunogama
Created May 1, 2025 14:47
Show Gist options
  • Save brunogama/8d1c687e95f72399e6bf1bbd1ef21c13 to your computer and use it in GitHub Desktop.
Save brunogama/8d1c687e95f72399e6bf1bbd1ef21c13 to your computer and use it in GitHub Desktop.
clean-utm.js using OpenIn Browser
// Remove tracking utm query
// Convert the iterator to an array to avoid modification issues
let keys = Array.from(ctx.url.searchParams.keys());
// Loop through all parameters
keys.forEach(function(key) {
// Check for both utm with and without underscore, same for uta
if (key === "utm" || key.startsWith("utm_") ||
key === "uta" || key.startsWith("uta_")) {
ctx.url.searchParams.delete(key);
}
});
// If needed: Apply the changes to the current URL
// window.history.replaceState(null, '', ctx.url.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment