: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(skills): emit vote and install-failure analytics for community skills (#91778)
posthog[bot]c5b5b5946b6c
diff --git a/products/skills/backend/api/community_skills.py b/products/skills/backend/api/community_skills.pyindex c6e905012741..387ea2d36716 100644--- a/products/skills/backend/api/community_skills.py+++ b/products/skills/backend/api/community_skills.py@@ -172,6 +172,17 @@ class CommunitySkillViewSet(serializer = self.get_serializer(queryset, many=True)return Response({"count": len(serializer.data), "results": serializer.data})+ def _report_install_failed(self, request: Request, slug: str, reason: str) -> None:+ # One event per failed install path so the dashboard can track the install failure rate and+ # its causes. reason is a short stable code, not the user-facing message.+ report_user_action(+ cast(User, request.user),+ "community skill install failed",+ {"community_skill_slug": slug, "reason": reason},+ team=self.team,+ request=request,+ )+@extend_schema(request=CommunitySkillInstallSerializer, responses={201: LLMSkillSerializer})@action(methods=["POST"], detail=True)def install(self, request: Request, slug: str = "", **kwargs) -> Response:@@ -196,6 +207,7 @@ class CommunitySkillViewSet(variables=payload.validated_data.get("variables"),)except CommunitySkillNotFoundError:+ self._report_install_failed(request, slug, "not_found")return Response({"detail": f"Community skill '{slug}' not found."},status=status.HTTP_404_NOT_FOUND,@@ -208,6 +220,7 @@ class CommunitySkillViewSet() as err:# All four are fixable by the caller (supply the value / shorter values / fix the key),# so they're 400s against the field that carried them.+ self._report_install_failed(request, slug, "missing_variable")raise ValidationError({"variables": str(err)}) from errexcept UnknownTemplatePlaceholderError as err:# The template body references a variable it never declared — a content-repo bug the@@ -219,6 +232,7 @@ class CommunitySkillViewSet(slug=slug,placeholder=err.placeholder,)+ self._report_install_failed(request, slug, "undeclared_placeholder")return Response({"detail": str(err)},status=status.HTTP_500_INTERNAL_SERVER_ERROR,@@ -226,6 +240,7 @@ class CommunitySkillViewSet(except LLMSkillDuplicateNameConflictError:# Only blame the new_name field when the caller actually supplied it — otherwise the# conflicting name is the skill's own slug, so a generic message is accurate.+ self._report_install_failed(request, slug, "name_conflict")if payload.validated_data.get("new_name"):return Response({"attr": "new_name", "detail": "A skill with this name already exists in your project."},@@ -239,9 +254,11 @@ class CommunitySkillViewSet(status=status.HTTP_400_BAD_REQUEST,)except CommunitySkillInvalidPayloadError as err:+ self._report_install_failed(request, slug, "invalid_payload")return Response({"detail": err.detail}, status=status.HTTP_400_BAD_REQUEST)except (LLMSkillFileLimitError, LLMSkillFilePathConflictError):# The synced community payload violates the skill limits (too many files / bad paths).+ self._report_install_failed(request, slug, "invalid_files")return Response({"detail": "This community skill can't be installed because its bundled files are invalid."},status=status.HTTP_400_BAD_REQUEST,@@ -279,4 +296,12 @@ class CommunitySkillViewSet({"detail": f"Community skill '{slug}' not found."},status=status.HTTP_404_NOT_FOUND,)++ report_user_action(+ cast(User, request.user),+ "community skill voted",+ {"community_skill_slug": slug, "voted": has_voted, "vote_count": vote_count},+ team=self.team,+ request=request,+ )return Response({"vote_count": vote_count, "has_voted": has_voted})diff --git a/products/skills/backend/api/test/test_community_skills.py b/products/skills/backend/api/test/test_community_skills.pyindex cbecb695fdbe..b071fd9257fe 100644--- a/products/skills/backend/api/test/test_community_skills.py+++ b/products/skills/backend/api/test/test_community_skills.py@@ -51,6 +51,10 @@ def _create_community_skill()+def _captured_events(mock_capture, event: str) -> list[dict]:+ return [call.kwargs["properties"] for call in mock_capture.call_args_list if call.kwargs.get("event") == event]++def _create_template_skill(*, slug: str = "feed-scout") -> CommunitySkill:return CommunitySkill.objects.create(slug=slug,@@ -323,6 +327,49 @@ class TestCommunitySkillAPI(APIBaseTest):self.assertEqual(second.json(), {"vote_count": 0, "has_voted": False})self.assertFalse(CommunitySkillVote.objects.exists())+ @patch("posthog.event_usage.posthoganalytics.capture")+ def test_vote_reports_event_with_state_and_count(self, mock_capture, _mock_flag) -> None:+ _create_community_skill(slug="web-analytics-triage")++ self.client.post(self._url("web-analytics-triage/vote/"))+ self.client.post(self._url("web-analytics-triage/vote/"))++ vote_events = _captured_events(mock_capture, "community skill voted")+ self.assertEqual(+ [(p["community_skill_slug"], p["voted"], p["vote_count"]) for p in vote_events],+ [("web-analytics-triage", True, 1), ("web-analytics-triage", False, 0)],+ )++ @parameterized.expand(+ [+ ("not_found",),+ ("missing_variable",),+ ("name_conflict",),+ ("undeclared_placeholder",),+ ]+ )+ @patch("posthog.event_usage.posthoganalytics.capture")+ def test_install_failure_reports_event(self, reason, mock_capture, _mock_flag) -> None:+ # Each branch shape (return, raised ValidationError, hand-built 500) must still emit the+ # failure event, so cover one representative path per shape plus the not-found path.+ if reason == "not_found":+ self.client.post(self._url("missing/install/"), {})+ elif reason == "missing_variable":+ _create_template_skill(slug="feed-scout")+ self.client.post(self._url("feed-scout/install/"), {}, format="json")+ elif reason == "name_conflict":+ _create_community_skill(slug="web-analytics-triage")+ self.client.post(self._url("web-analytics-triage/install/"), {})+ self.client.post(self._url("web-analytics-triage/install/"), {})+ elif reason == "undeclared_placeholder":+ skill = _create_template_skill(slug="feed-scout")+ skill.body = "Watch {{ feed_table }} and {{ undeclared }}."+ skill.save(update_fields=["body"])+ self.client.post(self._url("feed-scout/install/"), {"variables": {"feed_table": "x"}}, format="json")++ failures = _captured_events(mock_capture, "community skill install failed")+ self.assertEqual([p["reason"] for p in failures], [reason])+@pytest.mark.ee@patch(