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

feat(flags): Autoselect identified distinct ID in Person flags tab when possible #26857

Merged
merged 4 commits into from
Dec 12, 2024

Conversation

havenbarnes
Copy link
Contributor

Problem

Context: https://posthog.slack.com/archives/C07Q2U4BH4L/p1733826806892899

On the backend we currently do not track which distinct ID was created through identify or alias calls. When some users rack up many distinct IDs, it can be annoying to go look for the "identified" distinct ID in the list.

Changes

Screenshot 2024-12-11 at 5 57 51 PM Screenshot 2024-12-11 at 5 58 04 PM

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

Verified desired behavior when loading person profiles with:

  • One anonymous UUID
  • One anonymous UUID and one identified ID
  • Multiple anonymous UUIDs and multiple identified IDs

(s) => [s.person],
(person): string | null => {
// We do not track which distinct ID was created through identify, but we can try to guess
const nonUuidDistinctIds = person?.distinct_ids.filter((id) => id?.split('-').length !== 5)
Copy link
Contributor Author

@havenbarnes havenbarnes Dec 12, 2024

Choose a reason for hiding this comment

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

I went for the - segment count instead of a UUID regex because the actual user request for this included some UUID-adjacent identifiers which were longer than 36 characters: https://posthog.slack.com/archives/C07Q2U4BH4L/p1733826806892899

Figured I'd keep this flexible 🤷

Copy link
Contributor

@dmarticus dmarticus Dec 12, 2024

Choose a reason for hiding this comment

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

yeah, this is a pretty good way of doing this IMO – I haven't seen any cases where the non-uuid distinct_id isn't the user-created distinct_id, and defaulting to the first one in any other cases seems sane enough.

Furthermore, it looks like we do this on the backend, too, so you should feel extra validated by the choice you made ;)

Yes, it would be nice if we could be even more confident in this value (even if this is just a quality-of-life thing for users) but it's not worth blocking on.

Copy link
Contributor

github-actions bot commented Dec 12, 2024

Size Change: 0 B

Total Size: 1.11 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.11 MB

compressed-size-action

Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

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

nice work, I think this is good enough to ship.

(s) => [s.person],
(person): string | null => {
// We do not track which distinct ID was created through identify, but we can try to guess
const nonUuidDistinctIds = person?.distinct_ids.filter((id) => id?.split('-').length !== 5)
Copy link
Contributor

@dmarticus dmarticus Dec 12, 2024

Choose a reason for hiding this comment

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

yeah, this is a pretty good way of doing this IMO – I haven't seen any cases where the non-uuid distinct_id isn't the user-created distinct_id, and defaulting to the first one in any other cases seems sane enough.

Furthermore, it looks like we do this on the backend, too, so you should feel extra validated by the choice you made ;)

Yes, it would be nice if we could be even more confident in this value (even if this is just a quality-of-life thing for users) but it's not worth blocking on.

@havenbarnes
Copy link
Contributor Author

Yes, it would be nice if we could be even more confident in this value (even if this is just a quality-of-life thing for users) but it's not worth blocking on.

Yep only thing I can think of that would be better than this is a CH lookup for the last identify that occurred, but this seems a bit silly to block the UI for

@havenbarnes havenbarnes merged commit dfa9fa8 into master Dec 12, 2024
96 checks passed
@havenbarnes havenbarnes deleted the guess-primary-distinct-id branch December 12, 2024 19:53
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.

2 participants