-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Improvements to PH user metrics #1508
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very fine idea, just a bit concerned about all the extra queries.
posthog/tasks/process_event.py
Outdated
for user in Team.objects.get(pk=team_id).users.all(): | ||
posthoganalytics.capture(user.distinct_id, "first event ingested") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will result in multiple identical first event ingested
events per user when we make it possible for users to belong to multiple teams. Maybe a solution would be to add team_id
as event property here.
posthog/tasks/process_event.py
Outdated
@@ -194,6 +195,11 @@ def process_event( | |||
if data.get("$set"): | |||
_update_person_properties(team_id=team_id, distinct_id=distinct_id, properties=data["$set"]) | |||
|
|||
if not Event.objects.filter(team_id=team_id).exists(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it'd be better to add a boolean field on Team for whether an event has been captured yet (e.g. ingested_event
)? False
by default, and just switch to True
when processing any event, if it isn't True
already. Almost zero performance impact, since we're already selecting Team in the _capture
function. Would also avoid having to query team.event_set.exists()
in posthog/api/user.py
.
posthog/api/user.py
Outdated
@@ -57,6 +57,7 @@ def user(request): | |||
"toolbar_mode": request.user.toolbar_mode, | |||
"billing_plan": request.user.billing_plan, | |||
"is_team_unique_user": (team.users.count() == 1), | |||
"team_setup_complete": (team.completed_snippet_onboarding and team.event_set.exists()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would avoid an extra query if possible. Explained above.
Thanks @Twixes, totally agree! See updated implementation |
FYI /~https://github.com/PostHog/posthog-production/pull/20 introduces the same change to the "user signed up" event as in the last commit |
Seems fine to me? |
Changes
first event ingested
per team to PostHog.team_setup_complete
property to users to indicate whether the user's team has ingested events and completed the onboarding process.Checklist