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.

Revisions

  1. brunogama created this gist May 1, 2025.
    15 changes: 15 additions & 0 deletions clean-utm.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // 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());