Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix: attribute composed ticket events to the creator (#64820)

Alex V5d5327932189
diff --git a/products/conversations/backend/api/tests/test_events.py b/products/conversations/backend/api/tests/test_events.py
index 650b39bef7c4..4a7e6e2e184a 100644
--- a/products/conversations/backend/api/tests/test_events.py
+++ b/products/conversations/backend/api/tests/test_events.py
@@ -118,6 +118,29 @@ class TestConversationEvents(BaseTest):
assert call_kwargs["properties"]["actor_type"] == "user"
assert call_kwargs["properties"]["actor_id"] == self.user.id
assert call_kwargs["properties"]["actor_email"] == self.user.email
+ assert call_kwargs["properties"]["customer_name"] == "Test Customer"
+ assert call_kwargs["properties"]["customer_email"] == "[email protected]"
+ assert call_kwargs["properties"]["customer_distinct_id"] == self.ticket.distinct_id
+
+ @parameterized.expand(
+ [
+ ("capture_ticket_created", capture_ticket_created, []),
+ ("capture_message_received", capture_message_received, ["msg-id", "content"]),
+ ("capture_message_sent", capture_message_sent, ["msg-id", "content"]),
+ ]
+ )
+ @patch("products.conversations.backend.events.capture_internal_routed")
+ def test_customer_email_falls_back_to_email_from(self, _name, capture_fn, extra_args, mock_capture):
+ self.ticket.anonymous_traits = {}
+ self.ticket.email_from = "[email protected]"
+
+ if capture_fn is capture_message_sent:
+ capture_message_sent(self.ticket, "msg-id", "content", author=self.user)
+ else:
+ capture_fn(self.ticket, *extra_args)
+
+ call_kwargs = mock_capture.call_args.kwargs
+ assert call_kwargs["properties"]["customer_email"] == "[email protected]"
@patch("products.conversations.backend.events.capture_internal_routed")
def test_capture_message_received_uses_team_token(self, mock_capture):
diff --git a/products/conversations/backend/events.py b/products/conversations/backend/events.py
index d662370c20d2..d44339db2e9b 100644
--- a/products/conversations/backend/events.py
+++ b/products/conversations/backend/events.py
@@ -223,11 +223,21 @@ def _get_ticket_base_properties(ticket: Ticket) -> dict:
}
+def _get_customer_properties(ticket: Ticket, *, include_distinct_id: bool = False) -> dict:
+ """Customer identity on the ticket, for workflow filters and analytics."""
+ traits = ticket.anonymous_traits or {}
+ properties = {
+ "customer_name": traits.get("name", ""),
+ "customer_email": traits.get("email") or ticket.email_from or "",
+ }
+ if include_distinct_id:
+ properties["customer_distinct_id"] = ticket.distinct_id or ""
+ return properties
+
+
def capture_ticket_created(ticket: Ticket) -> None:
properties = _get_ticket_base_properties(ticket)
- traits = ticket.anonymous_traits or {}
- properties["customer_name"] = traits.get("name", "")
- properties["customer_email"] = traits.get("email", "")
+ properties.update(_get_customer_properties(ticket))
team = ticket.team
team_id = team.id
@@ -328,6 +338,7 @@ def capture_message_sent(
properties["message_content"] = (message_content or "")[:1000]
properties["author_type"] = "team"
properties.update(_get_actor_properties(author, "user"))
+ properties.update(_get_customer_properties(ticket, include_distinct_id=True))
capture_internal_routed(
token=ticket.team.api_token,
@@ -345,9 +356,7 @@ def capture_message_received(ticket: Ticket, message_id: str, message_content: s
properties["message_id"] = message_id
properties["message_content"] = (message_content or "")[:1000]
properties["author_type"] = "customer"
- traits = ticket.anonymous_traits or {}
- properties["customer_name"] = traits.get("name", "")
- properties["customer_email"] = traits.get("email", "")
+ properties.update(_get_customer_properties(ticket))
team = ticket.team
process_person = False