feat: add posthog events (#231)

* feat: add posthog events

* fix: workflow_duplicated event

* chore: add events to enum
This commit is contained in:
Sabiha Khan 2026-04-10 17:52:21 +05:30 committed by GitHub
parent bb5f56bfb7
commit 3f19a16e7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 450 additions and 93 deletions

View file

@ -9,7 +9,9 @@ from pydantic import BaseModel
from api.constants import BACKEND_API_ENDPOINT, ENVIRONMENT, UI_APP_URL
from api.db import db_client
from api.db.models import EmbedTokenModel, UserModel
from api.enums import PostHogEvent
from api.services.auth.depends import get_user
from api.services.posthog_client import capture_event
router = APIRouter(prefix="/workflow")
@ -103,6 +105,17 @@ async def create_or_update_embed_token(
expires_at=expires_at,
)
capture_event(
distinct_id=str(user.provider_id),
event=PostHogEvent.AGENT_EMBEDDED,
properties={
"workflow_id": workflow_id,
"is_new_token": len(existing_tokens) == 0,
"has_domain_restriction": bool(embed_request.allowed_domains),
"organization_id": user.selected_organization_id,
},
)
# Generate embed script
embed_script = generate_embed_script(token)