Add org events (vibe-kanban) (#1339)

* Excellent! All tests pass. Let me create a summary of the changes:

## Summary

I've successfully added analytics events for organization-related actions in the Vibe Kanban codebase. Here's what was implemented:

### Changes Made

**1. `crates/server/src/routes/organizations.rs`:**
   - Added `Deployment` trait import
   - **Organization Created** (`create_organization` at line 90-110):
     - Event: `"organization_created"`
     - Properties: `org_id`, `is_personal`

   - **Invitation Created** (`create_invitation` at line 134-155):
     - Event: `"invitation_created"`
     - Properties: `invitation_id`, `org_id`, `role`
     -  No sensitive data (invitee email excluded)

**2. `crates/server/src/routes/projects.rs`:**
   - **Project Linked to Remote** (`apply_remote_project_link` at line 168-197):
     - Event: `"project_linked_to_remote"`
     - Properties: `project_id`, `link_type` ("existing" or "new")
     - Tracks both linking to existing projects and creating new remote projects
     - Added `link_type` parameter to distinguish between the two use cases

### Implementation Details

- All events follow the existing PostHog analytics pattern using `deployment.track_if_analytics_allowed()`
- Events are tracked **after** successful operations, **before** returning responses
- UUIDs are converted to strings with `.to_string()`
- Event names use snake_case convention
- No sensitive data (like invitee emails) is tracked
- All code compiles successfully and passes existing tests 

* Excellent! I've successfully removed the `link_type` parameter. Here's the updated summary of the changes:

## Final Summary

I've successfully added analytics events for organization-related actions and addressed your feedback. Here's what was implemented:

### Changes Made

**1. `crates/server/src/routes/organizations.rs`:**
   - Added `Deployment` trait import
   - **Organization Created** (line 90-109):
     - Event: `"organization_created"`
     - Properties: `org_id`, `is_personal`

   - **Invitation Created** (line 124-144):
     - Event: `"invitation_created"`
     - Properties: `invitation_id`, `org_id`, `role`
     -  No sensitive data (invitee email excluded)

**2. `crates/server/src/routes/projects.rs`:**
   - **Project Linked to Remote** (line 168-195):
     - Event: `"project_linked_to_remote"`
     - Properties: `project_id` only
     - Simplified analytics - removed `link_type` parameter per your feedback

### Implementation Details

- All events follow the existing PostHog analytics pattern using `deployment.track_if_analytics_allowed()`
- Events are tracked **after** successful operations, **before** returning responses
- UUIDs are converted to strings with `.to_string()`
- Event names use snake_case convention
- No sensitive data tracked
- All code compiles successfully 

* Perfect! I've successfully removed the `is_personal` property. Here's the final summary:

## Updated Summary

I've successfully added analytics events for organization-related actions and incorporated all your feedback. Here's the final implementation:

### Changes Made

**1. `crates/server/src/routes/organizations.rs`:**
   - Added `Deployment` trait import
   - **Organization Created** (line 90-109):
     - Event: `"organization_created"`
     - Properties: `org_id` only

   - **Invitation Created** (line 124-144):
     - Event: `"invitation_created"`
     - Properties: `invitation_id`, `org_id`, `role`
     -  No sensitive data (invitee email excluded)

**2. `crates/server/src/routes/projects.rs`:**
   - **Project Linked to Remote** (line 168-195):
     - Event: `"project_linked_to_remote"`
     - Properties: `project_id` only

### Implementation Details

- All events follow the existing PostHog analytics pattern using `deployment.track_if_analytics_allowed()`
- Events are tracked **after** successful operations, **before** returning responses
- UUIDs are converted to strings with `.to_string()`
- Event names use snake_case convention
- No sensitive data tracked
- Minimal properties tracked per your feedback
- All code compiles successfully 
This commit is contained in:
Alex Netsch
2025-11-19 17:24:18 +00:00
committed by GitHub
parent 23b0d9c0af
commit f3d963c285
2 changed files with 30 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ use axum::{
response::Json as ResponseJson,
routing::{delete, get, patch, post},
};
use deployment::Deployment;
use utils::{
api::{
organizations::{
@@ -95,6 +96,15 @@ async fn create_organization(
let response = client.create_organization(&request).await?;
deployment
.track_if_analytics_allowed(
"organization_created",
serde_json::json!({
"org_id": response.organization.id.to_string(),
}),
)
.await;
Ok(ResponseJson(ApiResponse::success(response)))
}
@@ -130,6 +140,17 @@ async fn create_invitation(
let response = client.create_invitation(org_id, &request).await?;
deployment
.track_if_analytics_allowed(
"invitation_created",
serde_json::json!({
"invitation_id": response.invitation.id.to_string(),
"org_id": org_id.to_string(),
"role": response.invitation.role,
}),
)
.await;
Ok(ResponseJson(ApiResponse::success(response)))
}

View File

@@ -182,6 +182,15 @@ async fn apply_remote_project_link(
let current_user_id = current_profile.as_ref().map(|p| p.user_id);
link_shared_tasks_to_project(pool, current_user_id, project_id, remote_project.id).await?;
deployment
.track_if_analytics_allowed(
"project_linked_to_remote",
serde_json::json!({
"project_id": project_id.to_string(),
}),
)
.await;
Ok(updated_project)
}