Skip to content

Use the props passed to identify to determine sessions #3334

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

Merged
merged 5 commits into from
Apr 25, 2025

Conversation

perso182
Copy link
Contributor

Hey!

I added the custom props sent to umami.identify to also be used for defining the session. This way if the same PC visits a website that uses Umami, but different props has been passed to umami.identify, it will result in different sessions rather than one session with the properties of the last visit.
Fixes #3181

Not sure if saving the identity in localstorage is the way to go so let me know if this is not a reasonable solution.

Copy link

vercel bot commented Mar 28, 2025

@perso182 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
Contributor

@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

Overall, these changes integrate custom identity properties into session definitions, leveraging localStorage to differentiate sessions on shared PCs.

  • In /src/tracker/index.js, the track function now reads the identity from localStorage and includes it in event payloads, while identify writes new props and clears cached sessions.
  • In /src/app/api/send/route.ts, the identity is stringified and factored into session ID generation, ensuring different identities yield distinct sessions.
  • Be cautious: JSON.parse on localStorage may throw errors; consider error handling for robustness.
  • Review security implications of storing identity in localStorage.

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

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

@trondkla
Copy link

We too would love to have something like this. We have multiple users using the same IP and browser, on a thin client, and the possibility of sending in a hashed username or some other identifier would be great!

@@ -18,6 +18,7 @@ const schema = z.object({
payload: z.object({
website: z.string().uuid(),
data: anyObjectParam.optional(),
identity: anyObjectParam.optional(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a string, not an object. Should be renamed to just id.

@@ -233,21 +233,34 @@
};

const track = (obj, data) => {
let identity;
try {
const parsedIdentity = JSON.parse(localStorage.getItem('umami.identity'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can't use localStorage for privacy reasons. We might have to rely on umami.identify and change the signature to umami.identify(id, data).

@perso182
Copy link
Contributor Author

perso182 commented Apr 1, 2025

@mikecao I did a new commit changing the signature of umami.identify and removed the usage of localstorage, I am not 100% sure if this is what you had in mind regarding your previous comments. What are you thoughts on doing it this way?

@bendiksolheim
Copy link

What is the outlook for this pull request? I hate being a nuisance, but we’re in a situation where all users in our production environment are being counted as the same unique person in Umami, which significantly limits our usage.

@mikecao mikecao merged commit 0fd2d09 into umami-software:dev Apr 25, 2025
0 of 5 checks passed
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.

4 participants