Created
May 1, 2025 14:47
-
-
Save brunogama/8d1c687e95f72399e6bf1bbd1ef21c13 to your computer and use it in GitHub Desktop.
clean-utm.js using OpenIn Browser
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
// 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