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

Improvements to PH user metrics #1508

Merged
merged 5 commits into from
Sep 1, 2020
Merged

Conversation

paolodamico
Copy link
Contributor

Changes

  • Send first event ingested per team to PostHog.
  • Add team_setup_complete property to users to indicate whether the user's team has ingested events and completed the onboarding process.

Checklist

  • All querysets/queries filter by Team (if this PR affects any querysets/queries)
  • Backend tests (if this PR affects the backend)
  • N/A. Cypress E2E tests (if this PR affects the front and/or backend)

@timgl timgl temporarily deployed to posthog-feat-self-hoste-elgg3z August 25, 2020 21:07 Inactive
@timgl timgl temporarily deployed to posthog-feat-self-hoste-elgg3z August 25, 2020 21:16 Inactive
@paolodamico paolodamico requested a review from Twixes August 25, 2020 21:19
Copy link
Member

@Twixes Twixes left a 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.

Comment on lines 200 to 201
for user in Team.objects.get(pk=team_id).users.all():
posthoganalytics.capture(user.distinct_id, "first event ingested")
Copy link
Member

@Twixes Twixes Aug 25, 2020

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.

@@ -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():
Copy link
Member

@Twixes Twixes Aug 25, 2020

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.

@@ -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()),
Copy link
Member

@Twixes Twixes Aug 25, 2020

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.

@timgl timgl temporarily deployed to posthog-feat-self-hoste-elgg3z August 26, 2020 14:33 Inactive
@timgl timgl temporarily deployed to posthog-feat-self-hoste-elgg3z August 26, 2020 15:53 Inactive
@paolodamico
Copy link
Contributor Author

Thanks @Twixes, totally agree! See updated implementation

@timgl timgl temporarily deployed to posthog-feat-self-hoste-elgg3z August 26, 2020 19:28 Inactive
@paolodamico
Copy link
Contributor Author

FYI /~https://github.com/PostHog/posthog-production/pull/20 introduces the same change to the "user signed up" event as in the last commit

@timgl
Copy link
Collaborator

timgl commented Sep 1, 2020

Seems fine to me?

@timgl timgl merged commit 1da7f43 into master Sep 1, 2020
@timgl timgl deleted the feat/self-hosted-metrics-improvements branch September 1, 2020 13:37
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