Skip to content

Commit

Permalink
[fix] posthog: use user_id as distinct id (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Apr 10, 2024
1 parent bad1a42 commit ece61a9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions fixbackend/analytics/analytics_event_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,27 @@ async def flush(self) -> None:
self.client.identify( # type: ignore
distinct_id=str(event.user_id),
properties={"email": event.email},
timestamp=utc(),
uuid=uuid_str(),
)
# when a workspace is created, identify it as a group
if isinstance(event, AEWorkspaceCreated):
self.client.group_identify( # type: ignore
"workspace_id", str(event.workspace_id), properties={"name": event.name, "slug": event.slug}
group_type="workspace_id",
group_key=str(event.workspace_id),
properties={"name": event.name, "slug": event.slug},
timestamp=utc(),
uuid=uuid_str(),
)
# if the event has a workspace_id, use it to define the group
groups = {"workspace_id": str(ws)} if (ws := getattr(event, "workspace_id", None)) else None
self.client.capture( # type: ignore
distinct_id=uuid_str(),
distinct_id=str(event.user_id),
event=event.kind,
properties=event.to_json(),
timestamp=utc(),
groups=groups,
uuid=uuid_str(),
)
self.queue.clear()

Expand Down

0 comments on commit ece61a9

Please sign in to comment.