diff --git a/svc/pkg/team/worker/src/workers/create.rs b/svc/pkg/team/worker/src/workers/create.rs index ae3eb2ced3..ab6f0b33ed 100644 --- a/svc/pkg/team/worker/src/workers/create.rs +++ b/svc/pkg/team/worker/src/workers/create.rs @@ -58,9 +58,9 @@ async fn worker(ctx: &OperationContext) -> GlobalRes analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "team.create".into(), - user_id: ctx.owner_user_id, properties_json: Some(serde_json::to_string(&json!({ "team_id": team_id, + "user_id": owner_user_id, }))?), ..Default::default() }, diff --git a/svc/pkg/team/worker/src/workers/join_request_create.rs b/svc/pkg/team/worker/src/workers/join_request_create.rs index db5eaf8edb..d0bca4457b 100644 --- a/svc/pkg/team/worker/src/workers/join_request_create.rs +++ b/svc/pkg/team/worker/src/workers/join_request_create.rs @@ -20,10 +20,10 @@ async fn fail( analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "team.join_request.create_fail".into(), - user_id: Some(user_id.into()), properties_json: Some(serde_json::to_string(&json!({ "team_id": team_id, "error": error_code as i32, + "user_id": user_id, }))?), ..Default::default() } @@ -87,9 +87,9 @@ async fn worker( analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "team.join_request.create".into(), - user_id: ctx.user_id, properties_json: Some(serde_json::to_string(&json!({ "team_id": team_id, + "user_id": user_id, }))?), ..Default::default() } diff --git a/svc/pkg/team/worker/src/workers/join_request_resolve.rs b/svc/pkg/team/worker/src/workers/join_request_resolve.rs index 64458b3aef..a401604d05 100644 --- a/svc/pkg/team/worker/src/workers/join_request_resolve.rs +++ b/svc/pkg/team/worker/src/workers/join_request_resolve.rs @@ -39,9 +39,9 @@ async fn worker( analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "team.join_request.resolve".into(), - user_id: Some(user_id.into()), properties_json: Some(serde_json::to_string(&json!({ "team_id": team_id, + "user_id": user_id, }))?), ..Default::default() } diff --git a/svc/pkg/team/worker/src/workers/member_create.rs b/svc/pkg/team/worker/src/workers/member_create.rs index 84fbd11a59..6579be7e35 100644 --- a/svc/pkg/team/worker/src/workers/member_create.rs +++ b/svc/pkg/team/worker/src/workers/member_create.rs @@ -68,9 +68,9 @@ async fn worker(ctx: &OperationContext) -> Gl analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "team.member.create".into(), - user_id: Some(user_id.into()), properties_json: Some(serde_json::to_string(&json!({ "team_id": team_id, + "user_id": user_id, }))?), ..Default::default() } @@ -127,11 +127,11 @@ async fn fail( analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "team.invite.consume_fail".into(), - user_id: Some(user_id.into()), properties_json: Some(serde_json::to_string(&json!({ "team_id": team_id, "code": invitation.code, "error": invite_error_code as i32, + "user_id": user_id, }))?), ..Default::default() } diff --git a/svc/pkg/team/worker/src/workers/member_kick.rs b/svc/pkg/team/worker/src/workers/member_kick.rs index 30c7712d3a..c6d9652526 100644 --- a/svc/pkg/team/worker/src/workers/member_kick.rs +++ b/svc/pkg/team/worker/src/workers/member_kick.rs @@ -26,16 +26,23 @@ async fn worker(ctx: &OperationContext) -> Glob msg!([ctx] team::msg::member_kick_complete(team_id, user_id) { }).await?; + let mut properties = json!({ + "team_id": team_id, + "kick_user_id": user_id, + }); + + if let Some(kicker_user_id) = ctx.kicker_user_id { + properties["user_id"] = json!(kicker_user_id.to_string()); + } + + let properties_json = Some(serde_json::to_string(&properties)?); + msg!([ctx] analytics::msg::event_create() { events: vec![ analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "team.member.kick".into(), - user_id: ctx.kicker_user_id, - properties_json: Some(serde_json::to_string(&json!({ - "team_id": team_id, - "kick_user_id": user_id, - }))?), + properties_json, ..Default::default() } ], diff --git a/svc/pkg/team/worker/src/workers/member_remove.rs b/svc/pkg/team/worker/src/workers/member_remove.rs index 9803925f8b..13d9e13cdb 100644 --- a/svc/pkg/team/worker/src/workers/member_remove.rs +++ b/svc/pkg/team/worker/src/workers/member_remove.rs @@ -46,9 +46,9 @@ async fn worker(ctx: &OperationContext) -> Gl analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "team.member.remove".into(), - user_id: Some(user_id.into()), properties_json: Some(serde_json::to_string(&json!({ "team_id": team_id, + "user_id": user_id, }))?), ..Default::default() } diff --git a/svc/pkg/team/worker/src/workers/user_ban.rs b/svc/pkg/team/worker/src/workers/user_ban.rs index 868b12aac9..c35c11766e 100644 --- a/svc/pkg/team/worker/src/workers/user_ban.rs +++ b/svc/pkg/team/worker/src/workers/user_ban.rs @@ -45,16 +45,23 @@ async fn worker(ctx: &OperationContext) -> GlobalR }) .await?; + let mut properties = json!({ + "team_id": team_id, + "ban_user_id": user_id, + }); + + if let Some(banner_user_id) = ctx.banner_user_id { + properties["user_id"] = json!(banner_user_id.to_string()); + } + + let properties_json = Some(serde_json::to_string(&properties)?); + msg!([ctx] analytics::msg::event_create() { events: vec![ analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "team.user.ban".into(), - user_id: ctx.banner_user_id, - properties_json: Some(serde_json::to_string(&json!({ - "team_id": team_id, - "banned_user_id": user_id, - }))?), + properties_json, ..Default::default() } ], diff --git a/svc/pkg/team/worker/src/workers/user_unban.rs b/svc/pkg/team/worker/src/workers/user_unban.rs index 5785c3c578..69ebe28679 100644 --- a/svc/pkg/team/worker/src/workers/user_unban.rs +++ b/svc/pkg/team/worker/src/workers/user_unban.rs @@ -35,16 +35,23 @@ async fn worker(ctx: &OperationContext) -> Globa }) .await?; + let mut properties = json!({ + "team_id": team_id, + "unban_user_id": user_id, + }); + + if let Some(unbanner_user_id) = ctx.unbanner_user_id { + properties["user_id"] = json!(unbanner_user_id.to_string()); + } + + let properties_json = Some(serde_json::to_string(&properties)?); + msg!([ctx] analytics::msg::event_create() { events: vec![ analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "team.user.unban".into(), - user_id: ctx.unbanner_user_id, - properties_json: Some(serde_json::to_string(&json!({ - "team_id": team_id, - "unban_user_id": user_id, - }))?), + properties_json, ..Default::default() } ], diff --git a/svc/pkg/user-follow/ops/toggle/src/lib.rs b/svc/pkg/user-follow/ops/toggle/src/lib.rs index a924fb1a11..841202f280 100644 --- a/svc/pkg/user-follow/ops/toggle/src/lib.rs +++ b/svc/pkg/user-follow/ops/toggle/src/lib.rs @@ -90,11 +90,11 @@ async fn handle( events: vec![ analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "user_follow.create".into(), - user_id: Some(follower_user_id.into()), properties_json: Some(serde_json::to_string(&json!({ "follower": follower_user_id, "following": following_user_id, "became_mutual": mutual, + "user_id": follower_user_id, }))?), ..Default::default() } ], @@ -125,11 +125,11 @@ async fn handle( events: vec![analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "user_follow.delete".into(), - user_id: Some(follower_user_id.into()), properties_json: Some(serde_json::to_string(&json!({ "follower": follower_user_id, "following": following_user_id, "was_mutual": mutual, + "user_id": follower_user_id, }))?), ..Default::default() }], diff --git a/svc/pkg/user-identity/ops/create/src/lib.rs b/svc/pkg/user-identity/ops/create/src/lib.rs index 36679891ba..ee680c43ed 100644 --- a/svc/pkg/user-identity/ops/create/src/lib.rs +++ b/svc/pkg/user-identity/ops/create/src/lib.rs @@ -32,10 +32,9 @@ async fn handle( analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "user_identity.create".into(), - user_id: Some(user_id.into()), - namespace_id: None, properties_json: Some(serde_json::to_string(&json!({ "identity_email": email.email, + "user_id": user_id, }))?), ..Default::default() } @@ -61,10 +60,9 @@ async fn handle( analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "user_identity.create".into(), - user_id: Some(user_id.into()), - namespace_id: None, properties_json: Some(serde_json::to_string(&json!({ "identity_access_token": access_token.name, + "user_id": user_id, }))?), ..Default::default() } diff --git a/svc/pkg/user/ops/avatar-upload-complete/src/lib.rs b/svc/pkg/user/ops/avatar-upload-complete/src/lib.rs index b6d7277a3c..e2ad1c13fc 100644 --- a/svc/pkg/user/ops/avatar-upload-complete/src/lib.rs +++ b/svc/pkg/user/ops/avatar-upload-complete/src/lib.rs @@ -1,5 +1,6 @@ use proto::backend::pkg::*; use rivet_operation::prelude::*; +use serde_json::json; #[operation(name = "user-avatar-upload-complete")] async fn handle( @@ -38,7 +39,9 @@ async fn handle( analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "user.avatar_set".into(), - user_id: Some(user_id.into()), + properties_json: Some(serde_json::to_string(&json!({ + "user_id": user_id, + }))?), ..Default::default() } ], diff --git a/svc/pkg/user/worker/src/workers/create.rs b/svc/pkg/user/worker/src/workers/create.rs index 9b81c70e63..3f6b2100a2 100644 --- a/svc/pkg/user/worker/src/workers/create.rs +++ b/svc/pkg/user/worker/src/workers/create.rs @@ -81,22 +81,28 @@ async fn worker(ctx: &OperationContext) -> GlobalRes }) .await?; + let mut properties = json!({ + "user_id": user_id, + }); + + if let Some(display_name) = display_name { + properties["display_name"] = json!(display_name); + } + + let properties_json = Some(serde_json::to_string(&properties)?); + msg!([ctx] analytics::msg::event_create() { events: vec![ analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "user.create".into(), - user_id: Some(user_id.into()), - namespace_id: ctx.namespace_id, - properties_json: Some(serde_json::to_string(&json!({ - }))?), + properties_json: properties_json.clone(), ..Default::default() }, analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "user.profile_set".into(), - user_id: Some(user_id.into()), - namespace_id: ctx.namespace_id, + properties_json, ..Default::default() }, ], diff --git a/svc/pkg/user/worker/src/workers/delete.rs b/svc/pkg/user/worker/src/workers/delete.rs index bc9ac2d88c..3227872bc2 100644 --- a/svc/pkg/user/worker/src/workers/delete.rs +++ b/svc/pkg/user/worker/src/workers/delete.rs @@ -135,8 +135,6 @@ async fn worker(ctx: &OperationContext) -> GlobalRes analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "user.delete".into(), - user_id: None, - namespace_id: None, properties_json: Some(serde_json::to_string(&json!({ "deleted_user_id": user_id }))?), diff --git a/svc/pkg/user/worker/src/workers/profile_set.rs b/svc/pkg/user/worker/src/workers/profile_set.rs index 2c598f64f9..d2d64b0ced 100644 --- a/svc/pkg/user/worker/src/workers/profile_set.rs +++ b/svc/pkg/user/worker/src/workers/profile_set.rs @@ -1,5 +1,6 @@ use chirp_worker::prelude::*; use proto::backend::pkg::*; +use serde_json::json; #[worker(name = "user-profile-set")] async fn worker(ctx: &OperationContext) -> GlobalResult<()> { @@ -92,7 +93,9 @@ async fn worker(ctx: &OperationContext) -> Glob analytics::msg::event_create::Event { event_id: Some(Uuid::new_v4().into()), name: "user.profile_set".into(), - user_id: Some(*user_id), + properties_json: Some(serde_json::to_string(&json!({ + "user_id": user_id.to_string() + }))?), ..Default::default() }, ],