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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

perso182
Copy link

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

@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
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?

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.

3 participants