From d4a3a125fab0e6ae7bd317ba0aa0b3b2086abe75 Mon Sep 17 00:00:00 2001 From: Surbhi Date: Fri, 6 Dec 2024 16:51:52 -0500 Subject: [PATCH] adding capture for when event verification is toggled --- ee/api/ee_event_definition.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ee/api/ee_event_definition.py b/ee/api/ee_event_definition.py index 325a845aaa804..2c36958e505c7 100644 --- a/ee/api/ee_event_definition.py +++ b/ee/api/ee_event_definition.py @@ -11,6 +11,10 @@ ) from loginas.utils import is_impersonated_session +from typing import cast +import posthoganalytics +from posthog.event_usage import groups +from posthog.models import User class EnterpriseEventDefinitionSerializer(TaggedItemSerializerMixin, serializers.ModelSerializer): @@ -104,6 +108,23 @@ def update(self, event_definition: EnterpriseEventDefinition, validated_data): detail=Detail(name=str(event_definition.name), changes=changes), ) + verified_old = event_definition.verified + verified_new = validated_data.get("verified", verified_old) + + # If verified status has changed, track it + if "verified" in validated_data and verified_old != verified_new: + user = cast(User, self.context["request"].user) + posthoganalytics.capture( + str(user.distinct_id), + "event verification toggled", + properties={ + "verified": verified_new, + "event_name": event_definition.name, + "is_custom_event": not event_definition.name.startswith("$"), + }, + groups=groups(user.organization), + ) + return super().update(event_definition, validated_data) def to_representation(self, instance):