Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tracker URL Overwrite #3190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

lucca180
Copy link

Allows you to create a custom function to overwrite a URL before is sent to Unami.
Kinda solves #2979

Works this way:

Define your overwrite function at the window scope:

<script>
function myPathOverwriter(path) {
    if (path.startsWith("/pt")) path = path.replace("/pt", "");
    return path;
 }
</script>

and when loading unami, pass your function name using the data-url-overwrite param

<script
  defer
  src="http://mywebsite.com/umami.js"
  data-website-id="94db1cb1-74f4-4a40-ad6c-962362670409"
  data-url-overwrite="myPathOverwriter"
></script>

If your function returns empty or undefined, the original path will be used.

Copy link

vercel bot commented Jan 25, 2025

@lucca180 is attempting to deploy a commit to the umami-software Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR adds URL overwriting functionality to the Umami tracker, allowing users to modify or redact sensitive data from URLs before they are sent to the analytics server.

  • Added urlOverwrite attribute in src/tracker/index.js to specify a custom URL transformation function
  • Modified parseURL() to check for and execute the custom overwrite function before returning the final URL
  • Maintains original URL if overwrite function returns empty/undefined or isn't defined
  • Implementation integrates cleanly with existing URL parsing logic without breaking changes
  • Addresses issue Data redaction before sending to server #2979 by providing a way to redact sensitive data from tracked URLs

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +66 to +68
if (urlOverwrite && typeof window[urlOverwrite] === 'function') {
return window[urlOverwrite](parsedUrl) || parsedUrl;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: potential security risk - executing arbitrary functions from window scope without validation could allow XSS if the attribute value is user-controlled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant